Search

Thursday, August 14, 2014

LCD 4_Bit Interface With PIC18F4520..

               
Print On LCD

    I Aim to teach you programming 16x2 LCD in simples language skills using pic18f4520.

summary on lcd:
         This second LCD-tutorial is based on 'Introduction to LCD Programming', so you should to read that first.
          In the first tutorial we have seen that character LCD's based on the HD44780 chip can be driven in 8bits mode, which requires in total 11 lines from you microcontroller. If we want (or need) to spare some lines for other purposes it is possible to drive the display in 4bits mode, which requires 7 lines. It is possible to use only 6 lines, in which case R/W is tied to GrouND. This configuration is seen many times in projects. Instead of reading the busy flag (which is somewhat trickier than it is in 8 bit modus) we have to use delay loops. These delayloops have to be recalculated when using other oscillator frequencies. In this tutorial we use the somewhat harder solution, making use of the busy flag and being independent of the oscillator frequency. The only drawback using 4 bits is that commands and data have to be sent in two nibbles (4bit parts) to the display, which take slightly more time. In many cases that won't be a problem.
          To keep things simple, I will take the examples from the first tutorial, make the necessary changes and only explain the differences.

Hardware Required

  • Pic microcontroller
  • 8-LEDS
  • 8-220 ohm res

  • Hardware configuration
  •          The only difference with the 8bit version is DB0, DB1, DB2 and DB3 on the displaymodule side. These lines are not connected to the processor. Leave those lines unconnected, DON'T SHORT THEM TO GROUND as seen in projects where R/W is tied to ground.


//****************************************//


Program:

//Author : Palak Patel
//Contact No:9173211683
//Title:lcd_4Bit
//Platform: PIC18f4520
//Software:MPLAB

#include<p18f4520.h>
#pragma config OSC = INTIO67
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config PBADEN = OFF
#pragma config STVREN = OFF
#pragma config LVP = OFF
void Delay_ms(unsigned char);

void cmd(unsigned char);
void dat(unsigned char);
void main()
{
         unsigned char i,name[]="PALAK PATEL";
         TRISC=0x00;
         cmd(0x01);                          //Clear Lcd
         cmd(0x02);                          //4 Bit Specification
         cmd(0x28);                          //4 Bit specification
         cmd(0x0c);
         cmd(0x80);                          //Cursor starting point
         cmd(0X06);
        while(1)
       {
                i=0;
                while(name[i]!='\0')
                {
                        dat(name[i]);
                        i++;
                }
              cmd(0x01);
              cmd(0x80);
       }
}

void cmd(unsigned char k)
{
        PORTC &=0x0F;
        PORTC |=(k & (0xF0));
        PORTC |=(2<<0);
        Delay_ms(2);
        PORTC=PORTC & 0xFC;
        Delay_ms(20);

        PORTC &=0x0F;
        PORTC |=((k<<4) & (0xF0));
        PORTC |=(2<<0);
        Delay_ms(20);
        PORTC=PORTC & 0xFC;
        Delay_ms(20);
}
void dat(unsigned char k)
{
        PORTC &=0x0F;
        PORTC |=(k & 0xF0);
        PORTC |=(3<<0);
        Delay_ms(20);
        PORTC=PORTC & 0xFD;
        Delay_ms(20);

        PORTC &=0x0F;
        PORTC |=((k<<4) & (0xF0));
        PORTC |=(3<<0);
        Delay_ms(20);
        PORTC=PORTC & 0xFD;
        Delay_ms(20);
}

void Delay_ms(unsigned char p)
{
unsigned int i,j;
for(i=0;i<p;i++)
{
for(j=0;j<20;j++);
}
}
//****************************************//

Simulation:










                                             For Basic Electronics Kindally follow this Link:
                           http://basicelectonicspalakpatel.blogspot.in/2014/08/the-mosfet-as-switch.html

1 comment:

  1. I didn't understood following operations
    PORTC &=0x0F;
    PORTC |=(k & (0xF0));
    PORTC |=(2<<0);
    PORTC &=0x0F;
    PORTC |=(k & 0xF0);
    PORTC |=(3<<0);
    Can you please explain?

    ReplyDelete