0

Hi I am fairly new to programming 68hc11 assembly and was wondering how to go about proceeding with this problem.

A conveyor belt sensor is connected to bit zero at memory location $8000, write a program to count the number of objects that pass (this is < 10 000)

From what I understand the sensor will increase the counter every time it is on (bit zero == 1). But I only want the counter to be increased once for each object not the total time the sensor is on

Here is what I have programmed thus far

START LDY 8000

      LDX #0 count is initially 0;

w1    BRSET 0,Y,$01 w1

w2    BRCLR 0,Y $01 w2

      INCX

      BNE w1

done  BRA done
  • Unless you're using P&E assembler which has default hex radix, LDY 8000 should be LDY $8000. Also, counting is usually done with general purpose accumulator (A,B, or D) and not index registers. Although INCX may work for some assemblers, the official instruction is INX. The order of w1 and w2 lines should be swapped. How do you terminate? Only on 16-bit overflow? Also, BRCLR/BRSET assume no noise on your belt switch, which would require debouncing. – tonypdmtr Mar 03 '16 at 13:01

1 Answers1

0

Increment the counter when the bit is 1, loop until it goes to 0 again, and then start back at the beginning (waiting for it to change to 1).

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
  • so would the program go like this (updated in question) – DragonDude Mar 02 '16 at 19:12
  • Assuming `BRSET` means "branch when set", I would move the `BRSET` loop *after* `INCX` (so the logic is "loop while clear, increment (because it is no longer clear), loop while set". I'm not sure what the reasoning behind you last 2 lines is: if `BNE w1` is an unconditional jump, say so, and `done BRA done` is never reached and even if it were is pointless. – Scott Hunter Mar 02 '16 at 19:50