Friday, May 17, 2013

16*2 LCD module driver program

Here is the program to drive a 16*2 LCD module. First install PIC C compiler downloaded from internet or one that you have purchased. Install the compiler and create a new project in New project wizard,then initial setting ie. device selection, oscillator frequency, are done in the first page.
 In the next opening page we have to write the program in C.

PIC C compiler have bult-in functions and can be directly be used. Compile the program and if any errors correct it, then recompile. For simulation of the hex code we can use PIC simulator IDE.





CODE:

#include <16F877A.h>
#device adc=8
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES WRT_50%                  //Lower half of Program Memory is Write Protected
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
///////////////////////////////////////////////////LCD///////////////////////////////////////////////////////

void command()                               //     command control function
{
output_low(pin_c0);     //Rgister Select (RS)= 0  
output_high(pin_c2);
delay_ms(10);
output_low(pin_c2);      //E = 0
}

void data()                                     //    Data flow control function
{
output_high(pin_c0);    //RS = 1
output_high(pin_c2);
delay_ms(10);
output_low(pin_c2);      //E = 0
}
void lcd_init()                                //     LCD initialization
  
 {
   output_b(0x38);
   command();
   output_b(0x0E);
   command();
   output_b(0x01);
   command();
   output_b(0x80);
   command();
 }
 char c;      
 void main()
    {
   char d[] = "YES ITS WORKING...";
   int i=0;
   lcd_init();
   while(d[i]!='\0')                //                         
      {
      output_b(d[i]);              //  sending charactrs (byte) to the PORTB
      data();
      delay_ms(10);
      i++;
      }
   while(1)
   {
   output_b(0x18);              // Scrolling the display after entire data entered to the display
   command();
   }
}

No comments:

Post a Comment