;Toggling PE2 to turn on and off the relay for Dragon12 Plus Trainer Board ;PE2 of PORTE is connected to Relay on Dragon12+ board ;This program toggles PE2 to click on and off the relay (you hear the click sound opening and clsoing the relay) ;For relay discussion see Chapter 15 of Mazidi & Causey HCS12 book ;If you use this relay to control an external device such as horn and lamp use external power as shown in chapter 15. ABSENTRY Entry ; for absolute assembly: mark this as application entry point ; Include derivative-specific definitions INCLUDE 'mc9s12dp256.inc' ;CPU used by Dragon12+ board ;----------------------USE $1000-$2FFF for Scratch Pad R1 EQU $1001 R2 EQU $1002 R3 EQU $1003 ;code section ORG $4000 ;Flash ROM address for Dragon12+ Entry: LDS #$4000 ;Stack BSET DDRE,%00000100 ;PE2 as Output pin for Relay ;-------Turn on and off the Relay at PE2 BACK BSET PORTE,%00000100 ;PE2=1 to turn on relay JSR DELAY BCLR PORTE,%00000100 ;PE2=0 to turn off relay JSR DELAY BRA BACK ;Keep toggling Relay ;----------DELAY DELAY PSHA ;Save Reg A on Stack LDAA #100 ;Change this value to hear STAA R3 ;different relay clicking sound ;--1 msec delay. The Serial Monitor works at speed of 48MHz with XTAL=8MHz on Dragon12+ board ;Freq. for Instruction Clock Cycle is 24MHz (1/2 of 48Mhz). ;(1/24MHz) x 10 Clk x240x10=1 msec. Overheads are excluded in this calculation. L3 LDAA #10 STAA R2 L2 LDAA #240 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 $4000