// blink.c compiled with CodeVisionAVR 1.0006 // Wichit Sirichote 26-02-43 #include <90s8535.h> #include #define xtal 8000000 unsigned char counter1,flag1; bit enable_tone,off_hook; void tick_wait(){ while((TIFR&0x01) == 0); //cputick <10); TCNT0 = 256-75; //78; // reload timer 0 for 100Hz tick generation TIFR |= 0x01; // clear Timer 0 overflow flag by writing '1' } void task1(){ counter1++; if (counter1 >100) {PORTC ^= 0x80; counter1 = 0; flag1 ^= 0x01; // toggle flag1.0 enable_tone ^= 1; // toggle enable_tone bit } } void on_tone(){ TCCR2 = 0x1e; // enable OC2 toggle for tone generation } void off_tone(){ TCCR2 = 0x2e; // turn OC2 low } void test_tone(){ if (enable_tone == 1) //((flag1&0x01) != 0) on_tone(); else off_tone(); } void main() { // initialize corresponding port DDRA=0x00; /* all port A is input */ DDRB=0xff; /* all port B is output */ DDRC=0xff; /* all port C is output */ DDRD=0x80; /* port D is input except PD7 for OC2 output */ PORTB=0x00; PORTC=0x00; flag1 = 0; // timer0 is used for system 10ms tick TIMSK = 0x01; // Timer 0 overflow enable TCCR0 = 0x05; // Start Timer0 with clk/1024 // timer2 is used for 550Hz tone generation, the real output measured via Fluke83 is 558Hz OCR2 = 28; // toggle oc2 every 1/1116Hz or 558Hz output frequency TCCR2 = 0x1e; // start timer2 with PCLK/256, reset timer2 when matched while (1) { tick_wait(); // 10ms tick test_tone(); //on_tone(); task1(); } }