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.
Program: void main(void) { unsigned char t_f = 0; TMOD = 0X21; TH0 = 0XB8; //0XB800 ---> 20ms TL0 = 0X00; // TH1 = 0XFD; //0XFD ---> 9600,T1, // TL1 = TH1; RCAP2L = 0Xdc; //dc-- 11.0592 9600 b8-- //- 11.0592 4800 RCAP2H = 0Xff; T2CON = 0X34; SCON = 0X50; IE = 0X90; IP = 0X10; TR0 = 1; P0=0xff; while(1) { if (TF0) /***detect TF0*****/ { TR0 = 0; TH0 = 0XB8; TL0 = 0X00; TR0 = 1; t_f ++; } /********/ if (t_f == 50) { //for RTC } } } void Serial(void) interrupt 4 using 1 { ES = 0; if (TI) TI = 0; if (RI) { //FOR ReceivING the data RI = 0; } ES = 1; } ...... In the Main_Loop,detecting T0 's overflow flag TF0.In the other side ,enable the UART 's Interrupt.When running ,UART 's Enable ES will be reset at the moment of T0 overflow,UART can only receive a byte.But the RTC is right.So,i delete detecting TF0 in the main_loop,and enable T0 's Interrupt in stead ,code in following: void Timer0(void) interrupt 1 using 1 { ET0 = 0; TR0 = 0; TH0 = 0XB8; TL0 = 0X00; TR0 = 1; t_f ++; ET0 = 1; } At this time, UART work well but RTC is wrong. How can i do for both TIMER and UART working well?
1) do nor disable the activatying interrupt in the ISR 2) if your T0 ISR really is as short as you show, you can set it at a higher priority 3) for RTC DO NOT stop the timer in the ISR, use auto-reload Erik