//Interrupt Programming with CodeWarrior on Dragon12+ Using SCI0 Interrupt. //Souding Buzzer of PTT5 continuously while waiting for Interrupt to come in from SCI0 //Pressing any key on x86 PC HyperTerminal/Tera Terminal will interrupt the Dragon12 //and Dragon12 gets the character and displays it on LEDs of PORTB //Modified by Mazidi from Example 11-12C of Chapter 11 of HCS12 textbook by Mazidi & Causey //Serial SCI0 is the USB port next to the LCD. //Serial SCI0 is connected to USB and used by the Serial Monitor to communicate (downLOAD and RUN) with the Trainer board //This program must be downloaded into Dragon12 via USB/COM0 using HCS12 Serial Monitor //Use the usual steps in CodeWarrior. a) Make (F7) b) Set SW7 =00 (LOAD) position, c)use Debug (F5) to download. //After it is downloaded, d)close the Debugger Windows of CodeWarrior from step C, and e) set SW7=10 (RUN) position //(f) bring up HyperTerminal (or Tera Term in Windows Vista and Windows 7), //and g) MAKE SURE TO press RESET on the Dragon12 board and it will run this program. //(h) to download another program, close the HyperTerminal and set SW7=00 for LOAD. //Serial Monitor uses USB(SCI0) to download (LOAD,SW7=00) and works at 48 MHz //The RUN mode (SW7=10) of Dragon12+ works at 8 MHz Use this for 9600 baud rate caculation.. //We use USB(SCI0) to download using Serial Monitor //and then switch to RUN to send data to HyperTerminal/Tara Terminal using the same SCI0 //Make sure to choose "minimal startup code" and "Small" for memory model(no banked) when creating porject for Interrupts //Close and open HyperTerminal/TeraTerminal everytime you run this program //To Run this program Make sure to press RESET on Dragon12 board after the download and making SW7=10 for RUN. #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void MSDelay(unsigned int); void main(void) { DDRB = 0xFF; //PTB as output for LEDs DDRJ = 0xFF; //PTJ as output DDRT = 0xFF; //PORTT as output for PT5 buzzer PTJ = 0x0; //Let PTB show data. Needed by Dragon12+ board SCI0BDH=0x00; //Serial Monitor used for LOAD works at 48MHz SCI0BDL=26; //8MHz/2=4MHz, 4MHz/16=250,000 and 250,000/9600=26 for run when SW=10 SCI0CR1=0x00; SCI0CR2=0x2C; //enable receive interrupt too __asm CLI; //Enable interrupts globally for(;;) { //do something PTT = PTT ^ 0x20; //sound the buzzer by toggling PT5 MSDelay(10); } //stay here until interrupt comes. } //SCI0 Interrupt, Pressing any key on HyperTerminal/TeraTerminal will send a charater to Dragon12 via SCI0 port //and Dragon12 gets the character and displays it on LEDs of PORTB interrupt (((0x10000-Vsci0)/2)-1) void SCI0_ISR(void) { if(SCI0SR1 & SCI0SR1_RDRF_MASK) PORTB=SCI0DRL; } void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for(i=0;i