Advertisement
Forceisthop

GPS INTERFACING

Dec 28th, 2022
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.23 KB | None | 0 0
  1. #include  <lpc214x.h>     //Includes LPC2148 register definitions
  2. #include <string.h>
  3. #define DATA_PORT() IO0SET=(1<<16)       //Function to select data port on LCD
  4. #define READ_DATA() IO0SET=(1<<17)       //Function to select read operation on LCD
  5. #define EN_HI() IO0SET=(1<<18)           //Function to Enable LCD
  6.  
  7.  
  8. #define COMMAND_PORT() IO0CLR=(1<<16)     //Function to select command port on LCD
  9. #define WRITE_DATA() IO0CLR=(1<<17)       //Function to select write operation on LCD
  10. #define EN_LOW() IO0CLR=(1<<18)           //Function to disable LCD
  11.  
  12. unsigned char String1[16]={"NORTH"};
  13. unsigned char String2[16]={"EAST"};
  14. unsigned char String3[16]={"WEST"};
  15. unsigned char String4[16]={"SOUTH"};
  16.  
  17.  char direction1[] = "North";
  18.  char direction2[] = "East";
  19.  char direction3[] = "West";
  20.  char direction4[] = "South";
  21.  
  22. void Delay(unsigned char j)
  23. {  
  24.  unsigned int  i;
  25.  for(;j>0;j--)
  26.  {
  27.   for(i=0; i<60000; i++);
  28.  }
  29. }
  30.  
  31. void Delay_Small(unsigned char j)
  32. {
  33.  unsigned int  i;
  34.  for(;j>0;j--)
  35.  {
  36.   for(i=0; i<1000; i++);
  37.  }
  38. }
  39.                                
  40.  
  41. unsigned char Busy_Wait()              //This function checks the busy status of LCD
  42. {
  43.  unsigned int temp=0;
  44.  EN_LOW();
  45.  COMMAND_PORT();
  46.  READ_DATA();
  47.  
  48.  IO0PIN&=0xFF87FFFF;     
  49.  IO0DIR&=0xFF87FFFF;
  50.  IO0PIN|=0x00400000;
  51.  
  52.  do{
  53.  EN_HI();
  54.  EN_LOW();
  55.  EN_HI();
  56.  EN_LOW();
  57.  temp=IO0PIN;
  58.  }
  59.  while((temp & 0x00400000)==0x00400000);
  60.  EN_LOW();
  61.  WRITE_DATA();
  62.  IO0DIR&=0xFF80FFFF;
  63.  IO0DIR|=0x007F0000;
  64.  return (0);
  65. }    
  66.  
  67.  
  68. void LCD_Command(unsigned int data)           //This function is used to send LCD commands
  69. {
  70.  unsigned int temp=0;
  71.  EN_LOW();
  72.  COMMAND_PORT();
  73.  WRITE_DATA();
  74.  
  75.  temp=data;
  76.  //IO0PIN&=0xFF87FFFF;
  77.  IO0PIN&=0x00010000;
  78.  IO0PIN|=(temp & 0xF0) << 15;
  79.  
  80.  EN_HI();
  81.  EN_LOW();
  82.  
  83.  temp=data & 0x0F;
  84.  //IO0PIN&=0xFF87FFFF;
  85.  IO0PIN&=0x00010000;
  86.  IO0PIN|=(temp) << 19;
  87.  
  88.  EN_HI();
  89.  EN_LOW();
  90.  //while(Busy_Wait());
  91.  Delay(10);
  92. }
  93.  
  94.  
  95. void LCD_Data(unsigned int data)           //This function is used to send data to LCD
  96. {
  97.  unsigned int temp=0;
  98.  EN_LOW();
  99.  DATA_PORT();
  100.  WRITE_DATA();
  101.  
  102.  temp=data;
  103.  //IO0PIN&=0xFF87FFFF;
  104.  IO0PIN&=0x00010000;
  105.  IO0PIN|=(temp & 0xF0) << 15;
  106.  
  107.  EN_HI();
  108.  EN_LOW();
  109.  
  110.  temp=data & 0x0F;
  111.  
  112.  //IO0PIN&=0xFF87FFFF;
  113.  IO0PIN&=0x00870000;
  114.  IO0PIN|=(temp) << 19;
  115.  
  116.  EN_HI();
  117.  EN_LOW();
  118.  Delay_Small(1);
  119. }
  120.  
  121. void LCD_Init()
  122. {
  123.  LCD_Command(0x02);    
  124.  LCD_Command(0x28);
  125.  LCD_Command(0x0C);
  126.  LCD_Command(0x06);
  127. }
  128.  
  129.  
  130. void LCD_String(unsigned char *data)
  131. {
  132.  while(*data)
  133.  {
  134.   LCD_Data(*data);
  135.   data++;
  136.  }
  137. }  
  138.  
  139.  
  140. int main(void)
  141. {
  142.  PINSEL0 = 0x00000000;      // Enable GPIO on all pins
  143.  PINSEL1 = 0x00000000;
  144.  PINSEL2 = 0x00000000;
  145.  
  146.  Delay(20);
  147.  IO0DIR = (1<<22) | (1<<21) | (1<<20) | (1<<19) | (1<<18) | (1<<17) | (1<<16); 
  148.  
  149.  
  150.  LCD_Init();
  151.  LCD_Command(0x01);
  152.  Delay(20);
  153.  
  154.    
  155.  while(1){ 
  156.  char dir[]="North";               //change directions
  157.         LCD_Command(0x01);
  158.  if(strcmp(dir,direction1)== 1){
  159.       LCD_Command(0x80);
  160.         LCD_String(&String1[0]);
  161.  }else if(strcmp(dir,direction2)== 1){
  162.       LCD_Command(0x80);
  163.         LCD_String(&String2[0]);
  164.  }else if(strcmp(dir,direction3)== 1){
  165.       LCD_Command(0x80);
  166.         LCD_String(&String3[0]);
  167.  }else if(strcmp(dir,direction4)== 1){
  168.       LCD_Command(0x80);
  169.         LCD_String(&String4[0]);
  170.  }
  171.  }
  172. }
  173.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement