********************************************************************************* * Flashlight Program For CSMB12C128 module * PT5 configured as output pin to drive an LED, and PT2 configured as a * digital input, connected to a pushbutton switch. * Lines of code that start with an asterisk or a semicolon are comment lines. ********************************************************************************** ; export symbols XDEF Flashlight_Entry ; export 'Flashlight_Entry' symbol ABSENTRY Flashlight_Entry ; for absolute assembly: mark this as pgm entry point ;symbolic definitions RAMStart EQU $0400 ; absolute address to place my variables ROMStart EQU $4000 ; absolute address to place my code/constant data DDRT EQU $242 ; Data Direction Reg for PORT T PTT EQU $240 ; Data Reg for PORT T ; code section ORG ROMStart ;Start assembling program at location $4000 Flashlight_Entry: BCLR DDRT,%00000100 ;bit clear will clear bit 2 to make PT2 a switch input BSET DDRT,%00100000 ;bit set will set bit 5 to make PT5 an output TO drive LED AGAIN: LDAA PTT ;load port T value into accumulator A. Pin PT2 is the pushbutton switch ROLA ;rotate accumulator A with carry one bit to right so that Bit 3 of accumulator A holds state of switch. ROLA ;Now Bit 4 of accumulator A holds state of switch ROLA ;Now Bit 5 of accumulator A holds state of switch ;Store accumulator A contents out to Port T so that the switch state is shown on LED connected to PT5 STAA PTT BRA AGAIN ;Loop back to get new state of switch. ORG $FFFE ;Assemble next byte into location $FFFE, which is Reset Vector location DC.W Flashlight_Entry ; DC.W (or FDB) directive allocates two bytes ;and store value Flashlight_Entry at Reset Vector ;location as starting address when reset