//Interrupt Programming with CodeWarrior for HCS12G128 Tower module Using SCI0 Interrupt. //Toggling PTT7 continuously while waiting for Interrupt to come in from SCI0 //Pressing any key on x86 PC HyperTerminal/Tera Terminal and it will cause interrupt //and HCS12G128 gets the character and displays it on LEDs of PORTT //Modified and tested by Mazidi from Example 11-12C of Chapter 11 of HCS12 textbook by Mazidi & Causey //On TWR-S12G128 Serial COM0 (SCI0) is IDC 2x5 male header located next to brown POT. //The TWR-S12G128 board comes with a DB9-to-IDC-2x5 femal cable for connecting it to the COM port of x86 PC //When connecting female IDC 2x5 to Tower,make sure pin 1 on IDC Tower board is lined up with the red stripe of the IDC-2x5 cable //If the IDC-2x5 cable is connected right, then RED stripe will be on side of USB power cable //If your x86 PC does not have Serial COM port (with DB-9 connector)then you need USB to Serial Converter //The best one we have seen is (TRENDnet USB to RS-232 Serial Converter TU-S9) from Amazon //http://www.amazon.com/TRENDnet-RS-232-Serial-Converter-TU-S9/dp/B0007T27H8/ref=pd_bxgy_e_img_y //Make sure to choose "minimal startup code" and "Small" for memory model(no banked) when creating porject for Interrupts //In Codewarrior, make sure you are in Open Source BDM //In Codewarrior F7(make), F5(Debug) and F5 again to start running //Bring up Hyper Terminal in Windows XP (or Tera Terminal in Windows Vista and Windows 7) //Click on Hyper/Tera Terminal after the message "YES" is displayed //Now,as you press a key, the ASCII char in binary appears on PT6-PT0 //Close and re-open HyperTerminal/TeraTerminal everytime you run this program #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void SerTx0(unsigned char); void MSDelay(unsigned int); void main(void) { DDRT = 0xFF; //PortT as output PER0AD = 0x80; // enable PU on PAD15 to enable COM for the HCS12G128 chip //Notice this is different from HCS12DP256/512 SCI0BDH=0x00; SCI0BDL=41; //12.5 MHz/2=6.25MHz, 6.25MHz/16=390,625 Hz and 390,625/9600=41 SCI0CR1=0x00; SCI0CR2=0x2C; //enable receive interrupt too __asm CLI; //Enable interrupts globally //EnableInterrupts; //another way to Enable interrupts globally //Test serial SCI0 by sending "YES" to Hyper/Tera Terminal to make sure it works. SerTx0('Y'); SerTx0('E'); SerTx0('S'); SerTx0(' '); //Test the PTT by sending 0xAA and 0x55 to make sure they work. PTT = 0x55; MSDelay(1000); PTT = 0xAA; MSDelay(1000); for(;;) { //Now, do something until interrupt comes in PTT = PTT ^ 0x80; //Toggle PT7 (LED4) forever and wait for interrupt MSDelay(100); } //stay here until interrupt comes. } //SCI0 Interrupt, Pressing any key on HyperTerminal/TeraTerminal will send a charater to HCS12G128 Tower Module via SCI0 port //and HCS12G128 gets the character and displays it on PORTT. //Notice the PT6-PT4 (LED3-LED1) LEDs show only the upper 3 bits of the ASCII character coming in from Terminal while LED4 keeps toggling //Make sure you click on Hyper /Tera Terminal and press numbers, small letters, capital letters and see the LED3-1 //To get the lower 4 bits of the ASCII char you need to connect 4 LEDs to PT3-PT0 pins on a breadboard //Make sure this 4 LEDs are active LOW.. interrupt (((0x10000-Vsci0)/2)-1) void SCI0_ISR(void) //interrupt VectorNumber_Vsci0 void SCI0_ISR(void) //another way to declare interrupt { if(SCI0SR1 & SCI0SR1_RDRF_MASK) PTT=~SCI0DRL; //since LEDs connected to PortT are active LOW } void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for(i=0;i