*********************************************************************************
*     Flashlight Program For CSM-12C32 module
*	    PT7 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  $0800  ; 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,%10000000	 ;bit set will set bit 7 to make PT7 an output TO drive LED
AGAIN:     	    
  LDAA PTT					;load port T value into accumulator A. Pin PT2 is the pushbutton switch
  RORA 							;rotate accmulator A with carry one bit to right so that Bit 1 of accumulator A holds state of switch.
  RORA							;Now Bit 0 of accumulator A holds state of switch
  RORA							;Now Carry Bit holds it
  RORA							;Now Bit 7 of accumulator A holds state of switch
  STAA PTT					;Store accumulator A contents out to Port T so that the switch state is shown on LED in PT7
  BRA  AGAIN				;Loop back to get new state of switch. 
  	
  ORG $FFFE				;Assemble next byte into loccation $FFFE, which is Reset Vector location
				
	DCW	Flashlight_Entry  ; DCW directive allocates two bytes and store value Flashlight_Entry 
											      ; at Reset Vector point location as starting address when reset