//Toggling PE2 to activate the Relay for Dragon12 Plus Trainer Board //PE2 of PORTE is connected to Relay on Dragon12+ board //This program toggles PE2 to turn on and off the Relay(you hear click sound closing and opening the relay) //For Relay See Chapter 15 of HCS12 book by Mazidi & Causey //If you use this relay to control an external device such as horn and lamp use external power as shown in chapter 15. #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void MSDelay(unsigned int); void main(void) { /* put your own code here */ DDRE = DDRE | 0b00000100; // PE2 as output for (;;) { PORTE = PORTE | 0b00000100; //make PE2=1 to turn on relay MSDelay(500); //change the delay size to see what happens PORTE = PORTE & 0b11111011; //Make PE2=0 to turn off relay MSDelay(500); //change delay size.... } } void MSDelay(unsigned int itime) //msec delay { unsigned int i; unsigned int j; for(i=0;i