serial Reception using 8051 tamil | Serial reception programming | seria...


code:-

  #include<regx52.h>
  #include"lcd.h" 
  #include"UART.h"
  #include<string.h>
char msg[50];
int newmsg=0,i=0;
void read_msg();

void incoming_msg() interrupt 4
{
if(RI==1)
{
RI=0;
newmsg=1;
}
}
void main()
{
EA=0;
ES=0;
lcd_init();
  UART_init();
display_lcd("WELCOME");
send_to_modem ("testing communication");
delay(1000);
lcdcmd(0x01);
EA=1;
ES=1;
while(1)
{
if(newmsg==1)
{
lcdcmd(0x01);
ES=0;
read_msg();
display_lcd(msg);
delay(100);
ES=1;
newmsg=0;
}
i=0;
while (msg[i] !='\0')
{
msg[i]='\0';
i++;
}
}
void read_msg()
{
while(SBUF !='#') // welcome#
{
msg[i]=SBUF; 
  i++;
RI=0;
while(RI==0);
}
}

//////////////////88888888888888888888888//////////////////////////////////
sbit rs = P3^5;
//sbit rw = P3^6;
sbit en = P3^4;


void delay(unsigned int dela)
   {
   unsigned int l,mm;
   for(mm=0;mm<100;mm++)
   for(l=0;l<dela;l++);
   } 

void lcdcmd(unsigned char cmd)
{
P1 = cmd;
rs = 0;
// rw = 0;
en = 1;
delay(15);
en = 0;
// delay(150);
}

void datawrt_lcd(unsigned char datas)
{
P1 = datas;
rs = 1;
// rw = 0;
en = 1;
delay(15);
en = 0;
// delay(150);
}

void display_lcd(unsigned char *lcdstr)
{
    while (*lcdstr !='\0')
{
datawrt_lcd(*lcdstr);
lcdstr++;
}
}

void lcd_init()
{
lcdcmd(0x38);
lcdcmd(0x0C);
lcdcmd(0x01);  
lcdcmd(0x80);
}

////////////////////////////////////8888888888888888888888888////////////////////////////////////

 void UART_init(void);
void send_to_modem (unsigned char s[]);
void UART_init(void)
 {
  TMOD=0x20;    
  TH1=0xFD;
  SCON=0x50;
  TR1=1;
 }

void send_to_modem (unsigned char s[])
 {
  unsigned char r;

for(r=0;s[r]!='\0';r++) // to send the command to GSM modem to avoid echo signal 
  { //  the command is "ate0", 
    SBUF=s[r];
    while(TI==0);
    TI=0;
    delay(50);
  }
 // enter(); 
 }
 

Comments