PIC16F877A – Interfacing LCD
PIC16F877A Mini Development Board comes with an LCD module (2×16) operating at 5V. Control lines (RS, R/W, E) are connected to port pins RC0(RS), RC1(E) and data lines (D0-D7) to port pins RD0-RD7 whereas R/W is directly grounded. The board has a potentiometer to adjust LCD contrast. For reliable performance, LCD has to be initialized with certain commands.
Note: By default, LCD works in 8-bit mode (jumpers J11-J14 are shorted, connecting D0-D7 to port pins RD0-RD7). If these jumpers are left open, then LCD can be operated in 4-bit mode with data lines D4-D7.
Schematic
Sample Code (8-bit)
The sample code below gives LCD display output ” RhydoLABZ ” in line 1 and “Cochin” in line 2 .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
/************************************************************************* HEADER FILES **************************************************************************/ #include<pic.h> /************************************************************************* FUNCTION DECLARATIONS **************************************************************************/ void LCD_Command(int com); void LCD_Data(int data); void Send2LCD(const char loc, const char *LCD); void Delay_us(char Delay); void Delay_100us(unsigned long int Delay); /************************************************************************* MAIN FUNCTION **************************************************************************/ void main() { TRISC = 0X00; /* PORTC(control lines) configured as o/p */ TRISD = 0X00; /* PORTD(data lines) configured as o/p */ LCD_Command(0X30); /* LCD specification command */ Delay_us(35); LCD_Command(0X30); /* LCD specification command */ Delay_us(35); LCD_Command(0X30); /* LCD specification command */ Delay_us(35); LCD_Command(0X38); /* Double Line Display Command */ LCD_Command(0X06); /* Auto Increment Location Address Command */ LCD_Command(0X0C); /* Display ON Command */ LCD_Command(0X01); /* Clear Display Command */ Delay_100us(30); Send2LCD(0x84,"RhydoLABZ"); /* Displays string in the first line */ Send2LCD(0xc5,"Cochin"); /* Displays string in the second line */ while(1); } /************************************************************************* * Function : LCD_Command * * * * Description : Function to send a command to LCD * * * * Parameters : com - command to be sent * **************************************************************************/ void LCD_Command(int com) { RC0 = 0; /* RS-0(Command register) */ RC1 = 1; /* E-1(Enable pin high) */ PORTD = com; /* Write the command to data lines */ Delay_us(30); RC1 = 0; /* E-0(Enable pin low) */ } /************************************************************************* * Function : LCD_Data * * * * Description : Function to display single character on LCD * * * * Parameters : data - character to be displayed * **************************************************************************/ void LCD_Data(int data) { RC0 = 1; /* RS-1(Data register) */ RC1 = 1; /* E-1(Enable pin high) */ PORTD = data; /* Write the character to data lines */ Delay_us(30); RC1 = 0; /* E-0(Enable pin low) */ } /************************************************************************* * Function : Send2LCD * * * * Description : Function to display string on LCD * * * * Parameters : loc - location * * String to be displayed * **************************************************************************/ void Send2LCD(const char loc, const char *LCD) { LCD_Command(loc); /* Address of location to display string */ while(*LCD!='\0') /* Check for termination character */ { LCD_Data(*LCD); /* Display the character on LCD */ LCD++; /* Increment the pointer */ } } /************************************************************************* * Function : Delay_us * * * * Description : Function for 1 microsecond delay * * * * Parameter : Delay - delay in microseconds * **************************************************************************/ void Delay_us(char Delay) { while((--Delay)!=0); } /************************************************************************* * Function : Delay_100us * * * * Description : Function for delay * * * * Parameter : Delay - delay * **************************************************************************/ void Delay_100us(unsigned long int Delay) { Delay = Delay*15; while((--Delay)!=0); } /*************************** END OF PROGRAM ****************************/ |
Topics related to PIC16F877A Development Board-Mini
- PIC16F877A Mini Development Board – Overview
- PIC16F877A Mini Development Board – Interfacing LED
- PIC16F877A Mini Development Board – Interfacing LCD
- PIC16F877A Mini Development Board – Serial communication(USART)
- PIC16F877A Mini Development Board – Interfacing Switch
- PIC16F877A Mini Development Board – Interfacing Buzzer
- PIC16F877A Mini Development Board – Interfacing POT(ADC)
- PIC16F877A Mini Development Board – Interfacing Temperature sensor
- PIC 16F877A Mini Development Board – Interfacing Servo Motor
- PIC 16F877A Mini Development Board – Interfacing μRFID Reader
Resources
- Datasheets
How to buy?
- Click here to buy rhydoLABZ PIC 16F877A Mini Development Board
- Click here to buy rhydoLABZ PIC 18F4520 Mini Development Board
- Click here to buy rhydoLABZ PIC 18F4550 Mini Development Board
- Click here to buy rhydoLABZ PIC 18F4580 Mini Development Board
SupportPlease share your ideas with us, visit our forum for discussion
Leave a Reply
You must be logged in to post a comment.