ARM controller interfacing GSM and LCD



 BLOCK DIAGRAM





CONNECTION DIAGRAM


ORCAD SCHEMATIC DIAGRAM



 














/*
developed by S4silver
license type - open source
created on - 11/12/2014
modified on - 11/14/2014
modification details - refactored
developer - Frank Hust Jincson
contact mail id - silverembeddedsolutions@gmail.com
web link - http://s4silver.blogspot.in/p/programmers-colony.html
*/




 

#include<lpc214x.h>
#define E 0x02000000         /*lcd enable*/
#define RS 0x01000000        /*lcd RS*/
#define T 0x00000010
#define H 0x00000020
#define M 0x00000040
void lcd_data(unsigned char);
void lcd_cmd(unsigned char);
void gsm(int,int);
void lcd_init(void);
unsigned int adjust_portbit(unsigned char);
unsigned char at[46]={'A','T','+','C','M','G','F','=','1','A','T','+','C','N','M','I',
                          '=','2',',','2',',','0',',','0',',','0','A','T','+','C','M','G',
                          'S','=','"','9','8','8','4','4','6','8','7','8','2','"'};
 unsigned int t=24,h=23,m=24;
unsigned char ar[23]="GREEN HOUSE MONITORING";
unsigned int k,l;
void wait(unsigned int);



//_________________________________________________________

unsigned int adjust_portbit(unsigned char c )
{
    unsigned int result;
    result = c;
    result=result<<16;
    return result;
}


//_____________________________________________________

void lcd_data(unsigned char ldata)
{
    unsigned int temp;
    temp=adjust_portbit(ldata);
    IOCLR1=0x00FF0000;
    IOSET1=temp;
    IOSET1=RS;
    IOSET1=E;
    wait(3);
    IOCLR1=E;
}

//_____________________________________________________

void lcd_cmd(unsigned char lcmd)
{
    unsigned int temp;
    temp=adjust_portbit(lcmd);
    IOCLR1=0x00FF0000;
    IOSET1 = temp;
    IOCLR1=RS;
    IOSET1=E;
    wait(3);
    IOCLR1=E;
}

//______________________________________________________

void lcd_init(void)
{

    lcd_cmd(0x38);
    lcd_cmd(0x0E);
    lcd_cmd(0x01);
    lcd_cmd(0x06);
    lcd_cmd(0x80);
   

}

 //___________________________________________________


 void inte_char(unsigned int data)

 {
  unsigned char a,b,c;
  a=(data%10)+48;
  data=data/10;
  b=(data%10)+48;
  data=data/10;
  c=(data%10)+48;
  lcd_data(c);
  lcd_data(b);
  lcd_data(a);
 }

//__________________________________________________


void uart(unsigned int sen)

{

 unsigned char a,b,c;
 a=(sen%10)+48;
 sen=sen/10;
 b=(sen%10)+48;
 sen=sen/10;
 c=(sen%10)+48;
 while(!(U1LSR & 0x20));
 U1THR=c;
 while(!(U1LSR & 0x20));
 U1THR=b;
 while(!(U1LSR & 0x20));
 U1THR=a;

}





//_________________________________________________

main()

{
  
       unsigned int sent=0;
    PINSEL0=0x00050000;
    PINSEL1=0x00000000;
    IO0DIR=0x00000000;
    IO0CLR=0xFFFFFFFF;
    IO1DIR=0x03FF0000;
    U1LCR=0x83;
    U1DLL=97;
    U1LCR =0x03;
    for(l=0;l<=23;l++)

{
     lcd_data(ar[l]);
     if(l==10)
    lcd_cmd(0xc0);
    
}
    lcd_init();
    lcd_data('T');
    lcd_data('=');
    lcd_cmd(0x88);
    lcd_data('H');                                       
    lcd_data('=');
    lcd_cmd(0xc0);
    lcd_data('M');
    lcd_data('=');
   
   
while(1)
{
if((IO0PIN & 0x000000F0)==0x00000080)
{
    m=27;
    lcd_cmd(0xc2);
    inte_char(m);
    gsm(m,1);
}
else if((IO0PIN & 0x000000F0)==0x00000040)
{
    m=30;
    lcd_cmd(0xc2);
    inte_char(m);
    gsm(m,1);
    wait(15);
}

else if((IO0PIN & 0x000000F0)==0x000000C0)
{
    m=34;
    lcd_cmd(0xc2);
    inte_char(m);
    gsm(m,1);
    }

else if((IO0PIN & 0x000000F0)==0x00000020)
{
    m=39;
    lcd_cmd(0xc2);
    inte_char(m);
    gsm(m,1);
   
}

else if((IO0PIN & 0x000000F0)==0x000000A0)
{
    m=42;
    lcd_cmd(0xc2);
    inte_char(m);
    gsm(m,1);
   
}

//_________________________temp___________

else if((IO0PIN & 0x000000F0)==0x00000060)
{
    t=29;
    lcd_cmd(0x82);
    inte_char(t);
    gsm(t,2);
   
}

else if((IO0PIN & 0x000000F0)==0x000000E0)
{
    t=33;
    lcd_cmd(0x82);
    inte_char(t);
    gsm(t,2);
   
}

else if((IO0PIN & 0x000000F0)==0x00000010)
{
    t=38;
    lcd_cmd(0x82);
    inte_char(t);
    gsm(t,2);
   
}

else if((IO0PIN & 0x000000F0)==0x00000090)
{
    t=40;
    lcd_cmd(0x82);
    inte_char(t);
    gsm(t,2);
   
}

else if((IO0PIN & 0x000000F0)==0x00000050)
{
    t=45;
    lcd_cmd(0x82);
    inte_char(t);
    gsm(t,2);
   
}


else if((IO0PIN & 0x000000F0)==0x00000030)
{
    h=32;
    lcd_cmd(0x8A);
    inte_char(h);
    gsm(h,3);
   
}

else if((IO0PIN & 0x000000F0)==0x000000B0)
{
    h=37;
    lcd_cmd(0x8A);
    inte_char(h);
    gsm(h,3);
   
}

else if((IO0PIN & 0x000000F0)==0x00000070)
{
    h=40;
    lcd_cmd(0x8A);
    inte_char(h);
    gsm(h,3);
   
}

else if((IO0PIN & 0x000000F0)==0x000000F0)
{
    h=44;
    lcd_cmd(0x8A);
    inte_char(h);
    gsm(h,3);
   
}
}
 }

//________________________________________________

 void gsm(int p,int i)
 {
   for(k=0;k<=1;k++)

     {

      while(!(U1LSR & 0x20));

      U1THR=at[k];
       wait(3);

     }

     while(!(U1LSR & 0x20));

     U1THR=13;
    wait(3);

     for(k=0;k<=8;k++)

     {

      while(!(U1LSR & 0x20));

      U1THR=at[k];

      wait(3);


     }

     while(!(U1LSR & 0x20));

     U1THR=13;

     wait(3);


     for(k=9;k<=25;k++)

     {

      while(!(U1LSR & 0x20));

      U1THR=at[k];

      wait(3);



     }

     while(!(U1LSR & 0x20));

     U1THR=13;

    wait(3);

     for(k=26;k<=45;k++)

     {

      while(!(U1LSR & 0x20));

      U1THR=at[k];

        wait(3);


     }

     while(!(U1LSR & 0x20));

     U1THR=13;
   
    wait(3);


      for(l=0;l<=23;l++)

{
      while(!(U1LSR & 0x20));
      U1THR=ar[l];
      wait(3);

}
 while(!(U1LSR & 0x20));
 U1THR=13;

     if(i==2)
     {
     while(!(U1LSR & 0x20));
     U1THR='T';
     while(!(U1LSR & 0x20));
     U1THR='=';
     uart(p);
     }
     else if(i==3)
     {
     while(!(U1LSR & 0x20));
     U1THR='H';
     while(!(U1LSR & 0x20));
     U1THR='=';
     uart(p);
     }
     else if(i==1)
     {
     while(!(U1LSR & 0x20));
     U1THR='M';
     while(!(U1LSR & 0x20));
     U1THR='=';
     uart(p);
     }




     while(!(U1LSR & 0x20));

     U1THR=26;

     wait(3);
   
    wait(2);
}   


//_______________________________________________________

void wait(unsigned int x)

{
 unsigned int i,j;
 for(j=0;j<x;j++)
 {
  for(i=0;i<30000;i++);
 }

}