I downloaded the demo program from the website to measure the pulsewidth using TIMER0.
ET0 =1; EA =1; TMOD = (TMOD&0xF)| 0x09; //Set GATE0 bit while(1) { T0_ISR_count=0; TH0=0; TL=0; TR0=1; //start TIMER0 tdelay(200); //Test#1 //tdealay(500); //Test#2 while(!INT0); //wait for rising edge while(INT0); //wait for falling edge printf("The width pulse is: %ld uSec\n", (unsigned long) ((TH0<<8) | TL0 | ((unsigned long)T0_ISR_count<<16))); } } //------------------------ void tdelay(unsigned long I) //time delay { int i; for (i=0;I;i++); }
When I tested the code on the real board, changing from Test#1 to Test#2 (for tdelay function ) above made huge different results !!. I would think that the timer will not run until the INT0 goes HI because the SMOD bit4 (GATE0) is set. Could somebody kindly tell me what I did wrong here. NOTE: on the downloaded file, there was a PRINTF statement in replace of the tdelay(200) function. Again, I don't think it is going to make any different because the TIMER has not been fired yet at that line.
We are using Winbond 77LE532 (11.0592MHZ).
Thanks
Jimmy