This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

serial and timer problem

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;
}
}
}