am using PIC16F877A and this is my code:
Code: Select all
void interrupt()
{
INTCON.GIE = 0;
if (PIR1.RCIF) // test the interrupt for uart rx
{
dat[i] = UART1_Read();
i++;
if (i == 11)
{flag = 1;}
PIR1.RCIF = 0; // clear RCIF
}
}
Code: Select all
void main()
{
TrisB.f0 = 0;
TrisB.f1 = 0;
TrisB.f2 = 0;
PortB = 0;
PIE1.RCIE = 1; //enable USART receiver interrupt bit
INTCON.PEIE = 1; //enable peripheral interrupt bit
INTCON.GIE = 1; //enable global interrupt bit
PortD = 0x00;
TrisD = 0x00;
adcon1 = 0x06; // Configure AN pins as digital
adcon0 = 0x00;
cmcon = 0x07;
UART1_Init(9600);
Delay_ms(100);
while (1)
{
if(flag ==1){
label1: while (1)
{
for (j=0; j < GRE; j++)
{
if(PIR1.RCIF)
{GRE=0, RED=0, RED21=0, RED22=0, RED31=0, RED32=0, YLL, TOT=0;goto reset;}
else{
//process
}
}
for (j=0; j < 1; j++)
{
if(PIR1.RCIF)
{GRE=0, RED=0, RED21=0, RED22=0, RED31=0, RED32=0, YLL, TOT=0;goto reset;}
else{
//process
}
}
for (j=0; j < RED; j++)
{
if(PIR1.RCIF)
{GRE=0, RED=0, RED21=0, RED22=0, RED31=0, RED32=0, YLL, TOT=0;goto reset;}
else{
//process
}
}
for (j=0; j < 1; j++)
{
if(PIR1.RCIF)
{GRE=0, RED=0, RED21=0, RED22=0, RED31=0, RED32=0, YLL, TOT=0;goto reset;}
else{
//process
}
}
}
flag = 0; i=0;
}}