??? 01/21/09 11:08 Read: times |
#161676 - Catch that magic marker Responding to: ???'s previous message |
Change your interrupt handler to:
intrptcnt = 0; char turnaround; void Timer0_ISR (void) interrupt 1 { ET0 = 0; TF0 = 0; //clear flag intrptcnt++; if (intrptcnt >= 1000) { intrptcnt = 0; turnaround = 1; } TL0 = 0xCC; TH0 = 0xD4; ET0 = 1; } and change your main code as: if (turnaround) { turnaround = 0; LED0 = ~LED0; flash++; if ((flash & 3) == 0) { LcdWriteString("Hello World"); } else { LcdClear();//clear } } Now you don't get a deadlock if you miss the magic value 1000. What happens if you fill your car with fuel, and have decided to stop filling at exactly 10.00, but you happens to blink exactly at that value and next time you look, you will see the value 10.17? Your program as written would continue, and continue, and continue... Always write your program with a bit of resilience - a real human being who notices that he has passed the "magic marker" would react anyway. I didn't react to any "external". What I reacted to was that you didn't show the size of the intrptcnt variable, making it impossible for me to estimate exactly how long it would take until it would reach the value 1000 one more time. No need to restart "flash" when it reaches 100. A single byte stores 256 states, i.e. evenly divisible by four, so just let it loop, unless you need the values 0 .. 99 somewhere else in the program. |
Topic | Author | Date |
Program Conflict | 01/01/70 00:00 | |
More info | 01/01/70 00:00 | |
Reply to Per Westermark | 01/01/70 00:00 | |
no code | 01/01/70 00:00 | |
Reply to no code | 01/01/70 00:00 | |
Too slow sampling | 01/01/70 00:00 | |
Reply to Too Slow sampling | 01/01/70 00:00 | |
Catch that magic marker | 01/01/70 00:00 | |
Replay to Catch that magic marker | 01/01/70 00:00 | |
Edison | 01/01/70 00:00 | |
Try this...![]() | 01/01/70 00:00 |