Addresses of Cursor Position For 16x2 HD44780 LCD
Addresses of Cursor Position For 16x2 HD44780 LCD
Addresses of Cursor Position For 16x2 HD44780 LCD
PIC16F877A is 8-bit microcontroller based on reduced instruction set computer (RISC) architecture. It has 8kx14-bits flash program memory, 368 bytes of RAM. Here PIC16F877A microcontroller is connected to HD44780 LCD in 4-bit interface data, only four bus lines (DB4 to DB7) are used for data transfer. Bus lines DB0 to DB3 are having no connection with microcontroller. The data transfer between the HD44780U and the PIC16F877A is completed after the 4-bit data has been transferred twice.As for the order of data transfer, the four high order bits (for 8-bit operation, DB4 to DB7) are transferred before the four low order bits (for 8-bit operation, DB0 to DB3).Any character on HD44780 LCD is displayed by sending its respective ASCII code. Hence to display 1 on LCD microcontroller has to send 31h as data. When RS pin =0 instruction register is selected and information on data bus is taken as commands. The IR stores instruction codes, such as display clear and cursor shift, and address information for display data RAM (DDRAM) and character generator RAM (CGRAM). The IR can only be written from the PIC16F877A. When RS pin=1 data register is selected and information on data bus is taken as ASCII value of respective character to be displayed on HD44780 LCD. The DR temporarily stores data to be written into DDRAM or CGRAM and temporarily stores data to be read from DDRAM or CGRAM. When address information is written into the IR, data is written and then stored into the DR from DDRAM or CGRAM by an internal operation RW pin is used to either read from LCD (RW=1) or write to LCD (RW=0). When a High to Low pulse is applied on the Enable pin the information present on the data bus is latched into the LCD register.
Send lower nibble of data byte High to low pulse at Enable pin void lcd_character(char c) write one character to the LCD using wait for 40 usecond Set RS =1 to send ASCII code of character to LCD Call lcd_write function
PIC16f877_LCD.c
#include<pic.h> #include "delay.h" #include "lcd.h" void main() { TRISD=0X00; PORTD=0; lcd_init(); //LCD initialized lcd_line1(0); //LCD address specified AT LINE 1 lcd_string("INTERFACING LCD"); //Displays message "LCD INTERFACING" lcd_line2(0); //LCD address specified AT LINE 2 lcd_string(" PIC 16F877A");//Displays message " PIC 16F877A" while(1); } study projects files given below for more details on Interfacing LCD to PIC16F877A microcontroller
below is c language code for the heart rate monitor using PIC microcontroller 16f84, the c code is written Hi-Tech C. //# define # include < pic . h> #define rs RA2 #define e RA1 #define lcd_data PORTB #define _XTAL_FREQ 4000000 void delayms(unsigned int itime);
void pulse(void); void send_char(unsigned char data); void lcd_goto(unsigned char data); void lcd_clr(void); void send_string(const char *s); void init_lcd(void); void dis_num(unsigned int data,unsigned char digit); void prog1(void); unsigned long no=0; void main (void) { TRISA=0; TRISB=0; TRISA3=1; init_lcd(); delayms(10); lcd_clr(); delayms(10); send_string("Heart rate meter"); delayms(1000); lcd_clr(); delayms(10); while(1) { prog1(); } } void prog1(void) { unsigned int temp1=0,temp2=0; unsigned char i; unsigned int hb=1; while(RA3); while(!RA3){ hb++; delayms(1); } hb=30000/hb; lcd_goto(2); send_string("H.B.R: bpm"); lcd_goto(8); dis_num(hb,3); } void delayms(unsigned int itime) { unsigned int i;
for(;itime>0;itime--) { __delay_ms(1); } } void send_config(unsigned char data) //send lcd configuration { rs=0; //set lcd to configuration mode lcd_data=data&0xf0; //lcd data port = data pulse(); lcd_data=(data<<4)&0xf0; pulse(); } void pulse(void) { e=1; //pulse e to confirm the data delayms(1); e=0; delayms(1); } void lcd_goto(unsigned char data) //set the location of the lcd cursor { //if the given value is (0-15) the send_config(0x80+data); //cursor will be at the lower line } void lcd_clr(void) //clear the lcd { send_config(0x01); delayms(2); } void send_string(const char *s) //send a string to display in the lcd { rs = 1; while (*s)send_char (*s++); } void send_char(unsigned char data) //send lcd character { rs =1; delayms(1); //set lcd to display mode lcd_data=data&0xf0; //lcd data port = data pulse(); lcd_data=(data<<4)&0xf0; pulse(); } void init_lcd(void) { rs=0;e=0; //command mode
delayms(10); //delay 10ms lcd_data=0x30; //load initial nibble pulse(); //Latch initial code delayms(5); //delay 5ms pulse(); //Latch initial code delayms(1); //delay 1ms pulse(); //Latch initial code lcd_data=0x20; pulse(); //Latch initial code //configure lcd send_config(0x28); //Set 4-bit mode, 2 lines send_config(0xF); //Switch off display send_config(0x06); //Enable cursor auto increase } void dis_num(unsigned int data,unsigned char digit) { if(digit>3) send_char('0'+(data/1000)%10); if(digit>2) send_char('0'+(data/100)%10); if(digit>1) send_char('0'+(data/10)%10); if(digit>0) send_char('0'+(data/1)%10); }