Saturday 17 September 2016

GSM Based System:

GSM Based System:

Code:


#include<lpc214x.h>
#include<string.h>
#define THRE 5
#define TEMT 6
#define RDR 0
#define PLOCK 10
#define DLAB 7

#define lcdport IO0SET
#define lcdportclr IOCLR0
#define rs 16
#define rw 17
#define en 18
void uart0_init()
{
PINSEL0|=5;
U0LCR=0x83;
U0DLL=97;
U0DLM=0x00;
U0LCR=U0LCR&~(1<<DLAB);
}
void delay(int ms)
{
T1CTCR=0x00;
T1TC=0;
T1PC=0;
T1PR=59999;
T1TCR=0x02;
T1TCR=0x01;
while( T1TC != ms);
T1TCR=0;
}

void cmnd()
{
lcdportclr=(1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(4);
lcdportclr=(1<<en);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<15);
cmnd();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void daten()
{
lcdport=(1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(4);
lcdportclr=(1<<en);
}

void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<15);
daten();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
daten();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void lcdstring(char *str)
{
int j;
for(j=0;str[j]!='\0';j++)
{
lcddata(str[j]);
}
}
void lcd_init()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
}
void clk_init()
{
PLL0CON=0x01;
PLL0CFG=0x24;
PLL0FEED=0xAA;
PLL0FEED=0x55;
while(!(PLL0STAT & (1<<PLOCK)));
PLL0CON=0x3;
PLL0FEED=0xAA;
PLL0FEED=0x55;
VPBDIV=0x00;
}
void txdata(char ch)
{
U0THR=ch;
while(!(U0LSR & (1<<TEMT)));
}
void txstring(char *str)
{
while(*str)
{
txdata(*str);
U0FCR=0x07;
str++;
}
}


int main()
{
PINSEL0=0x05;
PINSEL2=0x00;

IODIR0=0xfffffff<<2;
clk_init();
lcd_init();
  uart0_init();
//while(1)
{
 lcdcmd(0x01);
 lcdstring("GSM APPLICATION");
txstring("AT\r\n");
delay(100);
txstring("AT+CMGF=1\r\n");
delay(100);
txstring("AT+CMGS=");
txdata(0x22);
txstring("+918888888888");
 delay(10);
txdata(0x22);
txdata('\r');
delay(100);
txstring("welcome to all");
txdata(0x1a);
while(1);
}
}


Simulation:





0 comments:

Post a Comment

if you have any doubt please let me know