Discussion in "Embedded GSM Development" started by    chiragpatel    Apr 4, 2013.
Thu Apr 04 2013, 12:47 am
#1
#include<reg51.h>
#define port P1
#define dataport P2 // Data port for LCD
sbit rs = port^0;
sbit rw = port^1;
sbit en = port^2;
int count,i;
unsigned char check,str[15];
bit check_space ;

void init_serial() // Initialize serial port
{
TMOD=0x20; // Mode=2
TH1=0xfd; // 9600 baud
SCON=0x50; // Serial mode=1, 8-Bit data, 1 Stop bit, 1 Start bit, Receiving on
TR1=1; // Start timer
}
void delay(unsigned int msec ) // Function for delay
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0; j<1275; j++);
}

void lcd_cmd(unsigned char item) // Function to send command on LCD
{
dataport = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data(unsigned char item) // Function to display character on LCD
{
dataport = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data_string(unsigned char *str) // Function to display string on LCD
{
int i=0;
while(str[i]!='\0')
{
lcd_data(str[i]);
i++;
delay(10);
}
return;
}
void lcd()
{
lcd_cmd(0x38); // For using 8-bit 2 row LCD
delay(5);
lcd_cmd(0x0F); // For display on, cursor blinking
delay(5);
lcd_cmd(0x80); // Set the cursor on first position of lcd
delay(5);
}



void receive_data() interrupt 4 // Function to recieve data serialy from RS232 into microcontroller
{
str[++count]=SBUF; //Read SBUF
RI=0;
}

unsigned char byte_check() //Function to check carraige return and new line character
{
switch(str[0])
{
case 0x0a:
{ // Return 0x00 for new line
return 0x00;
break ;
}
case 0x0d:
{ // Return 0x01 for carriage return
return 0x1;
break ;
}
default:return 0x02 ; // Return 0x02 for characters except new line and carriage return
}
}

void main()
{
lcd(); // Initialize LCD
init_serial(); // Initialize serial port
count=(-1);
lcd_data_string("Ready");
delay(10);
lcd_cmd(0x01);
IE=0x94;
while(1)
{
if(count>=0)
{
check=byte_check(); //Check the character
if(check!=0x00)
{
if(check==0x01)
{
if(check_space==1) //Check previous character
{
lcd_data(0x20);
check_space=0;
}
}
else
{
lcd_data(str[0]);
check_space=1;
}
}
count--;
for(i=0;i<count;i++) // Shift the whole array to one left
{

str[i]=str[i];
}
}
}
}
Thu Apr 04 2013, 10:31 am
#2
Will you provide some description for this post? or else its of no use.

[Topic moved to Embedded GSM Development forum]
 sonuverma like this.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Robertrip
Fri Apr 26 2024, 11:20 am
ArnoldDiant
Fri Apr 26 2024, 03:53 am
RodneyKnorb
Thu Apr 25 2024, 07:08 pm
Williamjef
Thu Apr 25 2024, 02:08 pm
SamuelSmise
Thu Apr 25 2024, 09:56 am
DustinErele
Thu Apr 25 2024, 08:44 am
ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm