While trying to understand some device connection protocol I'v faced a problem: at first simply I need to continosle monitor what happens on CLK pin of device. In sample: ET0 = 1; EA = 1; TMOD = (TMOD & 0xF0) | 0x09; while (1) { T0_ISR_count = 0; TH0 = 0; TL0 = 0; TR0 = 1; while (!INT0); while (INT0); printf ("The width pulse is: %ld uSec\n", (unsigned long)((TH0 << 8) | TL0 | ((unsigned long)T0_ISR_count << 16))); } } after this I got huge various numbers, that doesn't seems to be true, 'couse my scope shows nice strobes with period about 0.5 miliseconds (500 micros from up to down). Maybe printf function takes a lot of time to output calculated data (while timer already counted another value) ? Any ideas about short pulse width measurement? In feature I'll need during the CLK pulse from device to read DATA pin to collect information... Is my 2051 (11.059) fast enough to make this? Any help would be nice...
Thanks Jon! It helped a little bit, but... those huge numbers I'v got... After all I made some modifications: 1. Entered a keypress wait before start of calculation 2. Changed to printf (TH0,TL0,T0_ISR_count) After all of this I got TH0 = 253 (not always stable, but it it seems to be true), TL0, T0_ISR_count = 0... Any ideas why TH0 counts first ? If i try to remove a keypress wait, i lost any stability and TH0 values begins to jump in vary wide range. Why I lost stability if I do the same thing, but continiously without waiting for kaypress or something? Thanks