;Getting data from push-button SW1-SW4 and sending it to LED1-LED4 for HCS12G128 Tower Module using CodeWarrior ;On TWR-S12G128 Tower board, 4 LEDs (LED4-LED1)are connected to PT7-PT4 pins. PT7=LED4,.., PT4=LED1 ;LED1-LED4 are active LOW. See TWR-HCS12G128 schematic ;The 4-pins of PAD7-PAD4 are also connected to the push-button (debounce) switches (SW4-SW1) ;SW4-SW1 are active LOW (normally HIGH) See TWR-HCS12G128 schematic ;There are 8 jumpers allowing the connection of the SW1-Sw4 and LED1-LED4 to the CPU pins. ;If you use LEDs and SWs make sure the jumpers for them are set. ;Notice the PAD7-PAD4 pins are normally used for Analog-to-Digital converter (ADC). ;To use them for digital input via SW4-SW1, we must write 1 to ATDDIEN register bits. See Chap 12 of the HCS12G Ref. Manual. ;Chapter 2 of HCS12G Ref. Manual describes all the ports of HCS12G128 ;Sections 2.4.3.49 through 2.4.3.64 give the details of registers associated with PAD ;As you press the push-button Sw, an LED is turned on (LEDs shows the status of SW). ;Modified and tested by Mazidi from Examples in chapter 4 of Mazidi & Causey HCS12 textbook ;In HCS12G128 Tower the RAM address starts at $2000 ;We use RAM addresses starting at $2000 for scratch pad (variables) and $3FFF for Stack ;In CodeWarrior,make sure you are in Open Source BDM when downloading and running. ;Press F7 (to Make), then F5(Debug) to download,and F5 once more to start the program execution ABSENTRY Entry ; for absolute assembly: mark this as application entry point ; Include derivative-specific definitions INCLUDE 'mc9s12g128.inc' ;CPU used by HCS12G128 Tower board ;----------------------USE $2000-$2FFF for Scratch Pad R1 EQU $2001 R2 EQU $2002 R3 EQU $2003 ;code section ORG $8000 ;Flash ROM address for HCS12G128 Tower Entry: LDS #$4000 ;Stack BSET DDRT,%11110000 ;PT7-PT4 as Output pin LDD #$00F0 STD ATDDIEN ;Make PAD7-PAD4 as digital Input for SW4-Sw1. (The default is analog for ADC) LDAA #$F0 STAA PER1AD ;Enable internal pull-ups for the PAD7-PAD4 pins ;-------Get data from SWs and send it to LEDs BACK LDAA PT1AD ;get data from SW4-Sw1 JSR DELAY ;call delay (optional) STAA PTT ;send it to LED4-LED1 BRA BACK ;Keep doing it ;----------DELAY DELAY PSHA ;Save Reg A on Stack LDAA #1 ;Change this value to see STAA R3 ;how fast LEDs Toggle ;--10 msec delay. ;Freq. for Instruction Clock Cycle is 6.25MHz (1/2 of 12.5MHz) ;(1/6.25MHz) x 10 Clk x62x100=10 msec. Overheads are excluded in this calculation. L3 LDAA #100 STAA R2 L2 LDAA #62 STAA R1 L1 NOP ;1 Intruction Clk Cycle NOP ;1 NOP ;1 DEC R1 ;4 BNE L1 ;3 DEC R2 ;Total Instr.Clk=10 BNE L2 DEC R3 BNE L3 ;-------------- PULA ;Restore Reg A RTS ;------------------- ;************************************************************** ;* Interrupt Vectors * ;************************************************************** ORG $FFFE DC.W Entry ;Reset Vector. CPU wakes here and it is sent to start of the code at $8000