dinesh401
Advanced Member level 4
i want to send serial values to the 8051 mc by serial communication. but i want to send the values when i press the enter key. i wrote a sample code for serial interrupt program of 8051.
whenever i press the enter key. the loop must break and continue to next instructions. can anyone tell me the logic for this.
thankyou
Code:
#include<reg51.h>
void isr(void) interrupt 4
{
unsigned char dat[10];
int i;
for(i=0;i<2;i++)
{
while(RI==0);
RI=0;
dat[i]=SBUF;
SBUF=dat[i];
while(TI==0);
TI=0;
if(/* here i want to keep a ascii check for enter key*/)
break;
}
if(dat[0]=='3' & dat[1]=='c')
{
P0=0x01;
}
if(dat[0]=='3' & dat[1]=='e')
{
P0=0x02;
}
if(dat[0]=='3' & dat[1]=='f')
{
P0=0x03;
}
if(dat[0]=='3' & dat[1]=='i')
{
P0=0x04;
}
if(dat[0]=='3' & dat[1]=='j')
{
P0=0x05;
}
if(dat[0]=='3' & dat[1]=='l')
{
P0=0x06;
}
if(dat[0]=='3' & dat[1]=='o')
{
P0=0x07;
}
if(dat[0]=='3' & dat[1]=='q')
{
P0=0x08;
}
if(dat[0]=='3' & dat[1]=='r')
P0=0x09;
if(dat[0]=='3' & dat[1]=='t')
{
P0=0x0A;
}
if(dat[0]=='3' & dat[1]=='w')
{
P0=0x0B;
}
/*if(dat[0]=='3' & dat[1]=='x')
{
P0=0x0C;
led2=0;
} */
if(dat[0]=='5' & dat[1]=='c')
{
P0=0x0D;
}
if(dat[0]=='5' & dat[1]=='e')
{
P0=0x0E;
}
if(dat[0]=='5' & dat[1]=='f')
{
P0=0x0F;
}
if(dat[0]=='5' & dat[1]=='i')
{
P0=0x10;
}
if(dat[0]=='5' & dat[1]=='j')
{
P0=0x11;
}
if(dat[0]=='5' & dat[1]=='l')
P0=0x12;
}
void main(void)
{
TMOD = 0X20;
TH1=0xFD;
SCON=0X50;
TR1=1;
RI=0;
ES=1;
EA=1;
P0=0x00;
while(1)
{
}
}
whenever i press the enter key. the loop must break and continue to next instructions. can anyone tell me the logic for this.
thankyou