We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am doing a project and want to use both the serial port at 2400bps and timer 0 for timing ticking. for the serial: my setting is that: TMOD=0x20; TH1=-13; TL1=1; SCON=0x50; for the timer: TMOD=0x01; TH0=(65536-5000)/256; TL0=(65536-5000)%256; IE=0x82; TR0=1; the problem is i find the TMOD need to set in both code. How can i make two timer work seperately and work without collide? I find my system not work and the timer0 suddenly reset. pls help
moreover, i have recheck the program, i found the when i put the data into the serial buuffer SBUF=data; the timer was stopped pls help
Welcome to the C language. If you would like to set the upper nybble of TMOD without affecting the lower nybble of TMOD try:
TMOD &= 0x0F; TMOD |= 0x20;
TMOD = TMOD & 0x0F | 0x20;
#define WRITE_TMOD_T1(nybble) do { TMOD = TMOD & 0x0F | (nybble) << 4 } while (0)
#define WRITE_TMOD_T0(nybble) do { TMOD = TMOD & 0xF0 | (nybble) } while (0)
WRITE_TMOD_T1(2); WRITE_TMOD_T0(1);