hi, The soft is composed with • One interrupt timer • One serial interrupt If we use at the same time the serial interrupt and the timer interrupt, the string transfert is not regular, she was composed by random wrong value like ';' '&' or another character. If we remove the timer, the transfert is correct. #define MAIN #include "external.h" /*******************************************************/ void timer (void) { TMOD &= 0xF0; TMOD |= 0x01; TL0 = 0x00; TH0 = 0x00; ET0 = 1; TR0 = 1; } /*******************************************************/ void serial_interrup(void) interrupt 4 { idata unsigned char caractere; ES0 = 0; if (RI) { caractere = SBUF0; RI = 0; } ES0 = 1; } /*******************************************************/ void Timer_0(void) interrupt 3 { ET0 = 0; TL0 = 0xED; TH0 = 0xCB; ET0 = 1; } /*******************************************************/ void config_Rs232(void)///////// 19200 bauds /////////// { ES0=0; SCON0 = 0x50; RCAP2H = 0xFF; // Baud H BAUDTAB_H[] RCAP2L = 0xE5; // Baud L BAUDTAB_L[] TI = 0; ES0 = 1; } /*******************************************************/ void main(void) { unsigned char k; Poids=0; IE = 0x00; timer(); config_Rs232(); EA=1; while(1) { ++Poids; sprintf( PdsAff, "%ld",Poids); Chaine[0]='0';//CONFIG; Chaine[1]=' ';//ReadConfig; Chaine[2]=PdsAff[0]; Chaine[3]=PdsAff[1]; Chaine[4]=PdsAff[2]; Chaine[5]=PdsAff[3]; Chaine[6]=PdsAff[4]; Chaine[7]=PdsAff[5]; Chaine[8]=PdsAff[6]; Chaine[9]=PdsAff[7]; Chaine[10]=PdsAff[8]; Chaine[11]=PdsAff[9]; Chaine[12]=PdsAff[10]; Chaine[13]=PdsAff[11]; Chaine[14]=0x0A; for(k=0;k<15;k++) { ES0=0; SBUF0=Chaine[k]; while(TI!=1); TI=0; ES0=1; } } }
Hi Jeromi, I beleived u should solve this problem if not let me know
Jerome, I'm using serial ISR (Mode 2) and timer0 (Mode 2) ISR, too, and if I go below -40 (215) for TL0 reload of TH0, my Serial ISR stops working. Under that it's fine. I can't figure it out, can you? I've tried many things, and here are my ISR codes: serial () interrupt 4 using 2 { if (RI) { Targets_Status = SBUF; RI=0; else RCV1=1; } } void timer0 (void) interrupt 1 using 1 { int i=0; Frequency_Out = 0; Frequency_Out = 1; }
Hi Alberic, I have just realised (hopefully) what you problem is, it is like you say the timer interrupt but it is because you have specified the WRONG interrupt number for Timer_0(void), interrupt 3 is for timer 1, so if you change it to be as follows:- Timer_0(void) interrupt 1 then i think everything should now be ok. Mark.
Chiane is declared in UCHAR and Poids in long
Or 'poids' for that matter - is it declared as a long? Stefan
I don't see the declarations of 'chaine' and 'pdsaff' - can you post the complete source? Stefan
i try but i have the same problem thanks
If you are using Timer 2 as the baud rate generator, dont you need to set the correct bits in T2CON? Include in void config_Rs232(void) T2CON = 0x34; // RCLK, TCLK enabled, TR2 start timer Mark
i think it's that but i don't know how can i change... sorry i am a new user thanks
I suggest you take a look at the interrupt driven serial i/o examples in the download area on this site. The way you are handling serial rx/tx is a bit weird - maybe the timer being enabled/disabled is just changing the timing a bit and messing up the transmission? Stefan