//Using IR Transmitter/Receiver to sound the buzzer for Dragon12 Plus Trainer Board //PT5 of PORTT is connected to buzzer/speaker on Dragon12+ board //This program sounds the buzzer whenever the IR detects an object //Put your hands in front of them and buzzer will sound. Remove your hnad and buzzer will stop //On Dragon12 board the PT4 is used to turn on the Astable multivibrator (Square wave Freq generator) made of 4093 chip //It is an active low so PT4=0 turns it on and it provides 38KHz frequency to IR Transmitter (IRTX) //The IR Receiver (IRRX) is connected to PT3. So we can sample the IR receiver (PT3) as many times per second as we wnat (10 times per second) //Written and tested by M. Mazidi with some input from Travis Chandler. //MAKE SURE YOU MOVE THE JUMPERS ON J27 (IT IS BOTTOM LEFT OF CPU) BEFORE RUNNING THIS PROGRAM //PUT JUMPER BETWEEN 6 AND 5 (SIDEWAY VERTICAL). ALSO PUT JUMPER BETWEEN 4 AND 5 (SIDEWAY VERTICAL) //IF JUMPERS ARE SET PROPERLY BOTH TX AND RX LEDs ARE TURNED ON #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void MSDelay(unsigned int); void main(void) { /* put your own code here */ DDRT = DDRT | 0b00110000; //PT5=out for buzzer, PT4=out for IR Transmitter (IRTX),PT3=in for IR Receiver (IRRX) PTT = PTT & 0b11101111; //turn on Astabale Multivibrator(4093 chip) 38 KHz Freq genrator (it is active Low) while(1) { if(PTT & 0x08) //sample the receiver { PTT = PTT ^ 0b00100000; //if high toggle the buzzer (you can use PWM to sound the buzzer for better sound) MSDelay(10); //change this for different buzzer sounds } MSDelay(10); //sample it 10 times per second } } void MSDelay(unsigned int itime) //msec delay { unsigned int i; unsigned int j; for(i=0;i