SlideShare a Scribd company logo
/*website : http://picnelectronic.blogspot.com/
compiler : HI-TECH C compiler version 9.82
Programmer : HF
*/
#include <htc.h> //to include content before compiling
#define _XTAL_FREQ 20000000 //DEFINE CRYSTAL VALUE
__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & BOREN_OFF & MCLRE_ON &
LVP_OFF);
/*High speed crystal oscillator
Disable Watchdog Timer
Enable Power Up Timer
Disable Brown Out Reset
MCLR function is enabled
Disable Low Voltage Programming*/
/****************LCD FUNCTION START*************************/
/*
* LCD interface example
* This code will interface to a standard LCD controller
* like the Hitachi HD44780. It uses it in 4 bit mode, with
* the hardware connected as follows (the standard 14 pin
* LCD connector is used):
*
*
* To use these routines, set up the port I/O (TRISD) then
* call lcd_init(), then other routines as required.
* printf function (stdio.h) to write data to LCD
*/
#include <stdio.h>
#define LCD_RS RD0 //LCD configuration
#define LCD_EN RD1
#define LCD_D4 RD2
#define LCD_D5 RD3
#define LCD_D6 RD4
#define LCD_D7 RD5
#define LCD_PULSE() ((LCD_EN = 1),(LCD_EN=0))
/* write a byte to the LCD in 4 bit mode */
void lcd_write(unsigned char c)
{
__delay_us(40);
LCD_D4=(c>>4)&1; //LCD High nibble
LCD_D5=(c>>5)&1;
LCD_D6=(c>>6)&1;
LCD_D7=(c>>7)&1;
LCD_PULSE();
LCD_D4=(c>>0)&1; //LCD low Nibble
LCD_D5=(c>>1)&1;
LCD_D6=(c>>2)&1;
LCD_D7=(c>>3)&1;
LCD_PULSE();
}
void lcd_clear(void) //Clear and home the LCD
{
LCD_RS = 0;
lcd_write(0x1);
__delay_ms(2);
}
void lcd_string(const char * s) /* write a string of chars to
the LCD */
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}
/* write one character to the LCD */
void lcd_char(char c)
{
LCD_RS = 1; // write characters
lcd_write( c );
}
void putch(char c)
{
LCD_RS = 1; // write characters
lcd_write( c );
}
/*
* Go to the specified position
*/
void lcd_goto(unsigned char row, unsigned char pos)
{
LCD_RS = 0;
switch(row){
case 0:{lcd_write(0x80+pos);break;}
case 1:{lcd_write(0xC0+pos);break;}
case 2:{lcd_write(0x94+pos);break;}
case 3:{lcd_write(0xD4+pos);break;}
}
}
/* initialise the LCD - put into 4 bit mode */
void lcd_init()
{
LCD_RS = 0;
LCD_EN = 0;
__delay_ms(15); // wait 15mSec after power applied,
LCD_D4=1;
LCD_D5=1;
LCD_D6=1;
LCD_D7=0;
LCD_PULSE();
__delay_ms(5);
LCD_PULSE();
__delay_us(200);
LCD_PULSE();
__delay_us(200);
// Four bit mode
LCD_D4=0;
LCD_D5=1;
LCD_D6=0;
LCD_D7=0;
LCD_PULSE();
lcd_write(0x28); // Set interface length
lcd_write(0x0C); // Display On, Cursor On, Cursor Blink
lcd_clear(); // Clear screen
lcd_write(0x6); // Set entry Mode
}
/*******************LCD FUNCTION END************************/
void main(void) // the main function
{
TRISD = 0b00000000; //Set PORTD as output
lcd_init(); //initialize LCD display
lcd_goto(0,0); //row 1 pos 1
printf("Tutorial LCD"); //display on LCD
lcd_goto(1,0); //row 2 pos 1
printf("Hitachi HD44780");
while(1){
}
}

More Related Content

What's hot

REPORT
REPORTREPORT
coding and wiring dht11 and ultrasonic hcsr04 arduino
coding and wiring dht11 and ultrasonic hcsr04 arduino coding and wiring dht11 and ultrasonic hcsr04 arduino
coding and wiring dht11 and ultrasonic hcsr04 arduino
Nanda Fauzi P
 
Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23
DefconRussia
 
Arduino lcd display
Arduino lcd displayArduino lcd display
Arduino lcd display
Makers of India
 
Uart
UartUart
Uart
cs1090211
 
Switch level modeling
Switch level modelingSwitch level modeling
Switch level modeling
Devi Pradeep Podugu
 
VGA VHDL RTL design tutorial
VGA  VHDL   RTL design tutorialVGA  VHDL   RTL design tutorial
VGA VHDL RTL design tutorial
Nabil Chouba
 

What's hot (7)

REPORT
REPORTREPORT
REPORT
 
coding and wiring dht11 and ultrasonic hcsr04 arduino
coding and wiring dht11 and ultrasonic hcsr04 arduino coding and wiring dht11 and ultrasonic hcsr04 arduino
coding and wiring dht11 and ultrasonic hcsr04 arduino
 
Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23
 
Arduino lcd display
Arduino lcd displayArduino lcd display
Arduino lcd display
 
Uart
UartUart
Uart
 
Switch level modeling
Switch level modelingSwitch level modeling
Switch level modeling
 
VGA VHDL RTL design tutorial
VGA  VHDL   RTL design tutorialVGA  VHDL   RTL design tutorial
VGA VHDL RTL design tutorial
 

Similar to Lcd n PIC16F

Dam gate open close lpc prog
Dam gate open close lpc progDam gate open close lpc prog
Dam gate open close lpc prog
nikhil dixit
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
hairilfaiz86
 
LCD_Example.pptx
LCD_Example.pptxLCD_Example.pptx
LCD_Example.pptx
julioalexanderaguila
 
131080111003 mci
131080111003 mci131080111003 mci
131080111003 mci
jokersclown57
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd Year
Andrew Kozik
 
Experiment 16 x2 parallel lcd
Experiment   16 x2 parallel lcdExperiment   16 x2 parallel lcd
Experiment 16 x2 parallel lcd
Prashanta Chowdhury
 
2022-BEKM 3453 - LCD and keypad.pdf
2022-BEKM 3453 - LCD and keypad.pdf2022-BEKM 3453 - LCD and keypad.pdf
2022-BEKM 3453 - LCD and keypad.pdf
VNEX
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015
Rodrigo Almeida
 
Lab #5_Revised  (Due 121315)This is a revision on the previous.docx
Lab #5_Revised  (Due 121315)This is a revision on the previous.docxLab #5_Revised  (Due 121315)This is a revision on the previous.docx
Lab #5_Revised  (Due 121315)This is a revision on the previous.docx
VinaOconner450
 
_LCD display-mbed.pdf
_LCD display-mbed.pdf_LCD display-mbed.pdf
_LCD display-mbed.pdf
vidhyalakshmi153619
 
Functions for Nano 5 Card
Functions for Nano 5 CardFunctions for Nano 5 Card
Functions for Nano 5 Card
Omar Sanchez
 
Embedded systems development Defcon 19
Embedded systems development Defcon 19Embedded systems development Defcon 19
Embedded systems development Defcon 19
Rodrigo Almeida
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
Syed Ghufran Hassan
 
Lcd & keypad
Lcd & keypadLcd & keypad
Lcd & keypad
Izwanizam Yahaya
 
LCD Keypad Shield
LCD Keypad ShieldLCD Keypad Shield
LCD Keypad Shield
Raghav Shetty
 
Arduino: Arduino lcd
Arduino: Arduino lcdArduino: Arduino lcd
Arduino: Arduino lcd
SANTIAGO PABLO ALBERTO
 
Basic standard calculator
Basic standard calculatorBasic standard calculator
Basic standard calculator
UVSofts Technologies
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
SANTIAGO PABLO ALBERTO
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
Jens Siebert
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
forwardcom41
 

Similar to Lcd n PIC16F (20)

Dam gate open close lpc prog
Dam gate open close lpc progDam gate open close lpc prog
Dam gate open close lpc prog
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
 
LCD_Example.pptx
LCD_Example.pptxLCD_Example.pptx
LCD_Example.pptx
 
131080111003 mci
131080111003 mci131080111003 mci
131080111003 mci
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd Year
 
Experiment 16 x2 parallel lcd
Experiment   16 x2 parallel lcdExperiment   16 x2 parallel lcd
Experiment 16 x2 parallel lcd
 
2022-BEKM 3453 - LCD and keypad.pdf
2022-BEKM 3453 - LCD and keypad.pdf2022-BEKM 3453 - LCD and keypad.pdf
2022-BEKM 3453 - LCD and keypad.pdf
 
Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015Embedded systems design @ defcon 2015
Embedded systems design @ defcon 2015
 
Lab #5_Revised  (Due 121315)This is a revision on the previous.docx
Lab #5_Revised  (Due 121315)This is a revision on the previous.docxLab #5_Revised  (Due 121315)This is a revision on the previous.docx
Lab #5_Revised  (Due 121315)This is a revision on the previous.docx
 
_LCD display-mbed.pdf
_LCD display-mbed.pdf_LCD display-mbed.pdf
_LCD display-mbed.pdf
 
Functions for Nano 5 Card
Functions for Nano 5 CardFunctions for Nano 5 Card
Functions for Nano 5 Card
 
Embedded systems development Defcon 19
Embedded systems development Defcon 19Embedded systems development Defcon 19
Embedded systems development Defcon 19
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
 
Lcd & keypad
Lcd & keypadLcd & keypad
Lcd & keypad
 
LCD Keypad Shield
LCD Keypad ShieldLCD Keypad Shield
LCD Keypad Shield
 
Arduino: Arduino lcd
Arduino: Arduino lcdArduino: Arduino lcd
Arduino: Arduino lcd
 
Basic standard calculator
Basic standard calculatorBasic standard calculator
Basic standard calculator
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
 

More from hairilfaiz86

LED
LEDLED
Lp teori multimeter
Lp teori multimeterLp teori multimeter
Lp teori multimeter
hairilfaiz86
 
Ws multimeter
Ws multimeterWs multimeter
Ws multimeter
hairilfaiz86
 
Lp amali multimeter
Lp amali multimeterLp amali multimeter
Lp amali multimeter
hairilfaiz86
 
I.s multimeter
I.s multimeterI.s multimeter
I.s multimeter
hairilfaiz86
 
As1 multimeter
As1 multimeterAs1 multimeter
As1 multimeter
hairilfaiz86
 
Lp teori multimeter
Lp teori multimeterLp teori multimeter
Lp teori multimeter
hairilfaiz86
 

More from hairilfaiz86 (7)

LED
LEDLED
LED
 
Lp teori multimeter
Lp teori multimeterLp teori multimeter
Lp teori multimeter
 
Ws multimeter
Ws multimeterWs multimeter
Ws multimeter
 
Lp amali multimeter
Lp amali multimeterLp amali multimeter
Lp amali multimeter
 
I.s multimeter
I.s multimeterI.s multimeter
I.s multimeter
 
As1 multimeter
As1 multimeterAs1 multimeter
As1 multimeter
 
Lp teori multimeter
Lp teori multimeterLp teori multimeter
Lp teori multimeter
 

Recently uploaded

Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 

Recently uploaded (20)

Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 

Lcd n PIC16F

  • 1. /*website : http://picnelectronic.blogspot.com/ compiler : HI-TECH C compiler version 9.82 Programmer : HF */ #include <htc.h> //to include content before compiling #define _XTAL_FREQ 20000000 //DEFINE CRYSTAL VALUE __CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & BOREN_OFF & MCLRE_ON & LVP_OFF); /*High speed crystal oscillator Disable Watchdog Timer Enable Power Up Timer Disable Brown Out Reset MCLR function is enabled Disable Low Voltage Programming*/ /****************LCD FUNCTION START*************************/ /* * LCD interface example * This code will interface to a standard LCD controller * like the Hitachi HD44780. It uses it in 4 bit mode, with * the hardware connected as follows (the standard 14 pin * LCD connector is used): * * * To use these routines, set up the port I/O (TRISD) then * call lcd_init(), then other routines as required. * printf function (stdio.h) to write data to LCD */ #include <stdio.h> #define LCD_RS RD0 //LCD configuration #define LCD_EN RD1 #define LCD_D4 RD2 #define LCD_D5 RD3 #define LCD_D6 RD4 #define LCD_D7 RD5 #define LCD_PULSE() ((LCD_EN = 1),(LCD_EN=0)) /* write a byte to the LCD in 4 bit mode */ void lcd_write(unsigned char c) { __delay_us(40); LCD_D4=(c>>4)&1; //LCD High nibble LCD_D5=(c>>5)&1; LCD_D6=(c>>6)&1; LCD_D7=(c>>7)&1;
  • 2. LCD_PULSE(); LCD_D4=(c>>0)&1; //LCD low Nibble LCD_D5=(c>>1)&1; LCD_D6=(c>>2)&1; LCD_D7=(c>>3)&1; LCD_PULSE(); } void lcd_clear(void) //Clear and home the LCD { LCD_RS = 0; lcd_write(0x1); __delay_ms(2); } void lcd_string(const char * s) /* write a string of chars to the LCD */ { LCD_RS = 1; // write characters while(*s) lcd_write(*s++); } /* write one character to the LCD */ void lcd_char(char c) { LCD_RS = 1; // write characters lcd_write( c ); } void putch(char c) { LCD_RS = 1; // write characters lcd_write( c ); } /* * Go to the specified position */ void lcd_goto(unsigned char row, unsigned char pos) { LCD_RS = 0; switch(row){ case 0:{lcd_write(0x80+pos);break;} case 1:{lcd_write(0xC0+pos);break;} case 2:{lcd_write(0x94+pos);break;} case 3:{lcd_write(0xD4+pos);break;} }
  • 3. } /* initialise the LCD - put into 4 bit mode */ void lcd_init() { LCD_RS = 0; LCD_EN = 0; __delay_ms(15); // wait 15mSec after power applied, LCD_D4=1; LCD_D5=1; LCD_D6=1; LCD_D7=0; LCD_PULSE(); __delay_ms(5); LCD_PULSE(); __delay_us(200); LCD_PULSE(); __delay_us(200); // Four bit mode LCD_D4=0; LCD_D5=1; LCD_D6=0; LCD_D7=0; LCD_PULSE(); lcd_write(0x28); // Set interface length lcd_write(0x0C); // Display On, Cursor On, Cursor Blink lcd_clear(); // Clear screen lcd_write(0x6); // Set entry Mode } /*******************LCD FUNCTION END************************/ void main(void) // the main function { TRISD = 0b00000000; //Set PORTD as output lcd_init(); //initialize LCD display lcd_goto(0,0); //row 1 pos 1 printf("Tutorial LCD"); //display on LCD lcd_goto(1,0); //row 2 pos 1 printf("Hitachi HD44780"); while(1){ } }