;----------------------------------------------------------------- ; EX69.ASM WIDGET COUNTER C.P. Diduch 2001 ; ; Counts the number of widgets, in binary, transported along a ; conveyor belt and displays the count at the 8-LSB's of output ; port 0x0003. A proximity sensor generates '0' (at bit-0 of input ; port 0x0001) when a widget is in view of the sensor and a '1' ; after the widget moves past the sensor and out of its field of ; view. ; ; Author(s): ; Signature(s): Date: ;----------------------------------------------------------------- .EQU IPORT 1 ; #define IPORT 0 .EQU OPORT 3 ; #define OPORT 2 ; .ORG 0x0000 ; "variable assignments in RAM" COUNT: .DS 1 ; unsigned COUNT ; ; .ORG 0x8000 ; "assign the following to ROM" ; ; void main(void) { ; XOR R0, R0, R0 ; COUNT = 0 ; STOREM COUNT, R0 ; ; W0: LOADM R0, COUNT ; do { STOREP OPORT, R0 ; outport(OPORT, COUNT) ; ; W1: LOADP R0, IPORT ; do {Read sensor ; } ANDL NULL, R0, 1 ; while (Widget NOT detected) JMPNZ W1 ; ; W2: LOADP R0, IPORT ; do {Read sensor ; } ANDL NULL, R0, 1 ; while (Widget IS detected) {} JMPZ W2 ; ; LOADM R0, COUNT ; ADDL R0, R0, 1 ; COUNT = COUNT + 1 ; STOREM COUNT, R0 ; JMP W0 ; } ; }