??? 11/06/04 21:49 Read: times |
#80556 - RE: Int running on rising edge? Responding to: ???'s previous message |
Actually already planned on that, just hadn't implemented it yet :) Do you think it could cause the listed problem, though? Either way, I'll try that as soon as I get to the bench.
How's this look? /* Test program by Richard Slaughter. SDCC compiler. Teaching myself to apply C code in Microprocessor applications Should simply blink the LED each time the button is pressed. Processor: Atmel AT89S8252 Speed: 12mhz Instruction rate: 1mhz */ #include<at89s8252.h> #define button P3_2 #define LEDc P3_4 void debounce(void); void initInts(void); void main(void); /* above would all be in a header file */ void _sdcc__external__startup() //Init all IO bits high { P1=255; P2=255; P3=255; } void initInts() { TL1=0; // Timer 1 -- gotta do the math to make this 1millisecond TH1=0; // Timer 1 -- gotta do the math to make this 1millisecond TMOD=17; // Tmr0/TMR1 both 16 bit no prescaler. 0001 0001 TCON=67; // timer 1 active, timer 0 not, int0 on & falling edge 0100 0011 IP=0; // all priorities default 0000 0000 IE=138; // both timers, enabled - int0 not enabled just yet 1000 1010 } void button() interrupt 0 //button { IE=(IE & 0xFE); //disable int0 DBTmr=10; // or something... if(LEDc==1) LEDc=0; else // Swap status of LED LEDc=1; } void timer() interrupt 3 //empty timer { if(DBTmr!=0) DBTmr--; else IE=(IE | 0x01); //then re-enable int0 after button stabilizes TL1=0; // Timer 1 -- gotta do the math to make this 1millisecond TH1=0; // Timer 1 -- gotta do the math to make this 1millisecond } void main() { unsigned int DBTmr=0; // initialize stability counter initInts(); // Just initialize once, then while(!button); // Wait til the button stabilizes high IE=(IE | 0x01); //Enable int1.. was EX0=1, this didn't work... while(1); // Loop eternally } |
Topic | Author | Date |
Int running on rising edge? | 01/01/70 00:00 | |
RE: Int running on rising edge? | 01/01/70 00:00 | |
RE: Int running on rising edge? | 01/01/70 00:00 | |
RE: Int running on rising edge? | 01/01/70 00:00 | |
RE: Int running on rising edge? | 01/01/70 00:00 | |
RE: Int running on rising edge? | 01/01/70 00:00 | |
RE: Int running on rising edge?![]() | 01/01/70 00:00 | |
RE: Int running on rising edge? | 01/01/70 00:00 | |
RE: Int running on rising edge? | 01/01/70 00:00 |