SlideShare a Scribd company logo
1 of 4
/********PIC16F887*******
   HI-Tech C compiler
   Programmer : http://vto22012.blogspot.com/
***********************************
*/


#include <htc.h>
#define _XTAL_FREQ 20000000 //crystal speed 20Mhz
__CONFIG(0X3F32); //set configuration bits. Refer to PIC datasheet.
#include <stdio.h> // standard I/O c language


/********LCD Driver start ************************************************/

/*   LCD controller
//   (max characters is 40)
//   Initialization: lcd_init();
//   To print a string: printf("Hello World");
//   A few more formatting subroutines are available.
//   See towards the end of this page.

// macros to isolate interface dependencies
// LCD is connected to PORTD */


#define   LCDPort         PORTD
#define   LCDTris         TRISD
#define   Epin            6
#define   RWpin           5
#define   RSpin           4
#define   BUSYpin         3
#define   DATA0pin        0
#define   DATA1pin        1
#define   DATA2pin        2
#define   DATA3pin        3

#define EHIGH          bitset(LCDPort, Epin)
#define ELOW           bitclr(LCDPort, Epin)
#define E_OUTPUT       bitclr(LCDTris, Epin)
#define RSHIGH         bitset(LCDPort, RSpin)
#define RSLOW          bitclr(LCDPort, RSpin)
#define RS_OUTPUT      bitclr(LCDTris, RSpin)
#define RWHIGH         bitset(LCDPort, RWpin)
#define RWLOW          bitclr(LCDPort, RWpin)
#define RW_OUTPUT      bitclr(LCDTris, RWpin)
#define BUSY_FLAG      bittst(LCDPort, BUSYpin)
#define DATA_DIR_RD
{bitset(LCDTris,DATA3pin);bitset(LCDTris,DATA2pin);bitset(LCDTris,DATA1pin);bits
et(LCDTris,DATA0pin);}
#define DATA_DIR_WR
{bitclr(LCDTris,DATA3pin);bitclr(LCDTris,DATA2pin);bitclr(LCDTris,DATA1pin);bitc
lr(LCDTris,DATA0pin);}
#define OUTPUT_DATA(x) {int aval=LCDPort&0xF0; x = x & 0x0F; LCDPort=aval+x;}

// some common defines

#define bitset(var,bitno) ((var) |= (1 << (bitno)))
#define bitclr(var,bitno) ((var) &= ~(1 << (bitno)))
#define bittst(var,bitno) (var & (1 << (bitno)))


void epulse(void){
        __delay_us(1);
EHIGH;
       __delay_us(1);
       ELOW;
       __delay_us(1);
}

void lcd_write(
     unsigned char cmd, unsigned char data_flag, unsigned char chk_busy,
unsigned char dflag){
        char bflag,c;
        if (chk_busy) {
                 RSLOW;        //RS = 0 to check busy
                 // check busy
                 DATA_DIR_RD; //set data pins all inputs
                 RWHIGH;        // R/W = 1, for read
                 do {
                         EHIGH;
                         __delay_us(1); // upper 4 bits
                         bflag = BUSY_FLAG;
                         ELOW;
                         __delay_us(1);
                         epulse();
                 } while(bflag);
        } else {
                 __delay_ms(10); // don't use busy, just delay
        }
        DATA_DIR_WR;
        if (data_flag) RSHIGH;      // RS=1, data byte
        else     RSLOW;    // RS=0, command byte
        // device is not busy
        RWLOW;        // R/W = 0, for write
        c = cmd >> 4; // send upper 4 bits
        OUTPUT_DATA(c);
        epulse();
        if (dflag) {
                 c = cmd & 0x0F; //send lower 4 bits
                 OUTPUT_DATA(c);
                 epulse();
        }
}


void lcd_init(void) {
        // configure, see control pins as outputs
        // initialize as low
        E_OUTPUT; RS_OUTPUT; RW_OUTPUT;
        ELOW; RSLOW; RWLOW;

       __delay_ms(25); //wait for device to settle
       __delay_ms(25);
       lcd_write(0x20,0,0,0); // 4 bit interface
       lcd_write(0x28,0,0,1); // 2 line display, 5x7 font
       lcd_write(0x28,0,0,1); // repeat
       lcd_write(0x06,0,0,1); // enable display
       lcd_write(0x0C,0,0,1); // turn display on; cursor, blink is off
       lcd_write(0x01,0,0,1); // clear display, move cursor to home
       __delay_ms(3);   // wait for busy flag to be ready
}

// send 8 bit char to LCD

 void putch (char c) {
    lcd_write(c,1,1,1);
}
void lcd_clear(void){
        lcd_write(0x01,0,0,1);   // clear display, move cursor to home
}

/* go to the specified position */
void lcd_goto(unsigned char row, unsigned char pos)
{
switch(row){
case 1:{lcd_write(0x80+pos,0,1,1);break;}
case 2:{lcd_write(0xC0+pos,0,1,1);break;}
case 3:{lcd_write(0x94+pos,0,1,1);break;}
case 4:{lcd_write(0xD4+pos,0,1,1);break;}
     }
}

void lcd_shiftleft(void){
        lcd_write(0x18,0,1,1);   // shift left
}

void lcd_shiftright(void){
        lcd_write(0x1C,0,1,1);   // shift right
}

void lcd_blinkcursor(void){
        lcd_write(0x0F,0,1,1);   // displays and blink a cursor
}

void lcd_printbar(int bar){
        for(int i=0; i<bar; i++){
                lcd_write(0xFF,1,1,1);           // print bars on the LCD
        }
}

void lcd_string(const char *s)                           //send a string to display
in the lcd
{
        unsigned char i=0;
           while (s && *s)lcd_write(*s++,1,1,1);

}

/********************LCD Driver
End****************************************************/


/*******************start main program *************************************/
void main(void)
{
      TRISD = 0b00000000;                      // configure all RD pin as output
      PORTD = 0b00000000;                      // reset all RD pin to 0 or off
condition
      ANSEL = 0;                         // Configure AN pins as digital
      ANSELH = 0;
      C1ON = 0;                      // Disable comparators
      C2ON = 0;

      lcd_init();   // initialise LCD

while(1){                                           // loop forever
    lcd_goto(1,0); //Display start at line 1 and position 0
      printf("Tutorial PIC"); //display
      lcd_goto(2,0); //Display start at line 2 position 0
      printf("visit:vto22012");
//can use normal printf function like printf("Convert number %d",temp);
}
}
/***********************main program
end****************************************/

More Related Content

What's hot

Microcontroller lec 2
Microcontroller  lec 2Microcontroller  lec 2
Microcontroller lec 2Ibrahim Reda
 
PIC Microcontroller
PIC MicrocontrollerPIC Microcontroller
PIC MicrocontrollerDivya Bansal
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.parthi_arjun
 
Programming pic microcontrollers
Programming pic microcontrollersProgramming pic microcontrollers
Programming pic microcontrollersMAIYO JOSPHAT
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller Raghav Shetty
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerCorrado Santoro
 
Embedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingEmbedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingIkhwan_Fakrudin
 
Analog I/O in PIC16F877A
Analog I/O in PIC16F877AAnalog I/O in PIC16F877A
Analog I/O in PIC16F877AMohamed Bedair
 
Introduction to pic microcontroller
Introduction to pic microcontrollerIntroduction to pic microcontroller
Introduction to pic microcontrollerSiva Kumar
 
Atmel and pic microcontroller
Atmel and pic microcontrollerAtmel and pic microcontroller
Atmel and pic microcontrollerTearsome Llantada
 
PIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikarPIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikarGauravRaikar3
 
Pic 18 microcontroller
Pic 18 microcontrollerPic 18 microcontroller
Pic 18 microcontrollerAshish Ranjan
 
Pic16cxx instruction set
Pic16cxx instruction setPic16cxx instruction set
Pic16cxx instruction setv Kalairajan
 

What's hot (19)

Microcontroller lec 2
Microcontroller  lec 2Microcontroller  lec 2
Microcontroller lec 2
 
PIC Microcontroller
PIC MicrocontrollerPIC Microcontroller
PIC Microcontroller
 
PIC 16F877A by PARTHIBAN. S.
PIC 16F877A   by PARTHIBAN. S.PIC 16F877A   by PARTHIBAN. S.
PIC 16F877A by PARTHIBAN. S.
 
Programming pic microcontrollers
Programming pic microcontrollersProgramming pic microcontrollers
Programming pic microcontrollers
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontroller
 
Pic microcontroller step by step your complete guide
Pic microcontroller step by step your complete guidePic microcontroller step by step your complete guide
Pic microcontroller step by step your complete guide
 
Embedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingEmbedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programming
 
Getting started with pic microcontrollers
Getting started with pic microcontrollersGetting started with pic microcontrollers
Getting started with pic microcontrollers
 
Analog I/O in PIC16F877A
Analog I/O in PIC16F877AAnalog I/O in PIC16F877A
Analog I/O in PIC16F877A
 
Introduction to pic microcontroller
Introduction to pic microcontrollerIntroduction to pic microcontroller
Introduction to pic microcontroller
 
Class7
Class7Class7
Class7
 
Atmel and pic microcontroller
Atmel and pic microcontrollerAtmel and pic microcontroller
Atmel and pic microcontroller
 
PIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikarPIC 16F877 micro controller by Gaurav raikar
PIC 16F877 micro controller by Gaurav raikar
 
Pic 18 microcontroller
Pic 18 microcontrollerPic 18 microcontroller
Pic 18 microcontroller
 
Digital i o
Digital i oDigital i o
Digital i o
 
PIC CONTROLLERS
PIC CONTROLLERSPIC CONTROLLERS
PIC CONTROLLERS
 
Pic16cxx instruction set
Pic16cxx instruction setPic16cxx instruction set
Pic16cxx instruction set
 
Lec13
Lec13Lec13
Lec13
 

Similar to PIC and LCD

Dam gate open close lpc prog
Dam gate open close lpc progDam gate open close lpc prog
Dam gate open close lpc prognikhil dixit
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxSANTIAGO PABLO ALBERTO
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controllerSyed Ghufran Hassan
 
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.pdfforwardcom41
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuenteBlackD10
 
Atmega lcd programing_with_header_file
Atmega lcd programing_with_header_fileAtmega lcd programing_with_header_file
Atmega lcd programing_with_header_fileABHISHEK MAURYA
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Svet Ivantchev
 
Functions for Nano 5 Card
Functions for Nano 5 CardFunctions for Nano 5 Card
Functions for Nano 5 CardOmar Sanchez
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdffootstatus
 
(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-program(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-programDimz I
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver艾鍗科技
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScriptJens Siebert
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfSIGMATAX1
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd YearAndrew Kozik
 
#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docx#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docxajoy21
 

Similar to PIC and LCD (20)

Dam gate open close lpc prog
Dam gate open close lpc progDam gate open close lpc prog
Dam gate open close lpc prog
 
Lcd n PIC16F
Lcd n PIC16FLcd n PIC16F
Lcd n PIC16F
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
LCD_Example.pptx
LCD_Example.pptxLCD_Example.pptx
LCD_Example.pptx
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
 
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
 
131080111003 mci
131080111003 mci131080111003 mci
131080111003 mci
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuente
 
Atmega lcd programing_with_header_file
Atmega lcd programing_with_header_fileAtmega lcd programing_with_header_file
Atmega lcd programing_with_header_file
 
Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016Gaztea Tech Robotica 2016
Gaztea Tech Robotica 2016
 
Arduino: Arduino lcd
Arduino: Arduino lcdArduino: Arduino lcd
Arduino: Arduino lcd
 
Functions for Nano 5 Card
Functions for Nano 5 CardFunctions for Nano 5 Card
Functions for Nano 5 Card
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
 
(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-program(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-program
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
Embedded Systems Project 3rd Year
Embedded Systems Project 3rd YearEmbedded Systems Project 3rd Year
Embedded Systems Project 3rd Year
 
Basic standard calculator
Basic standard calculatorBasic standard calculator
Basic standard calculator
 
#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docx#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docx
 

More from 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

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 

Recently uploaded (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 

PIC and LCD

  • 1. /********PIC16F887******* HI-Tech C compiler Programmer : http://vto22012.blogspot.com/ *********************************** */ #include <htc.h> #define _XTAL_FREQ 20000000 //crystal speed 20Mhz __CONFIG(0X3F32); //set configuration bits. Refer to PIC datasheet. #include <stdio.h> // standard I/O c language /********LCD Driver start ************************************************/ /* LCD controller // (max characters is 40) // Initialization: lcd_init(); // To print a string: printf("Hello World"); // A few more formatting subroutines are available. // See towards the end of this page. // macros to isolate interface dependencies // LCD is connected to PORTD */ #define LCDPort PORTD #define LCDTris TRISD #define Epin 6 #define RWpin 5 #define RSpin 4 #define BUSYpin 3 #define DATA0pin 0 #define DATA1pin 1 #define DATA2pin 2 #define DATA3pin 3 #define EHIGH bitset(LCDPort, Epin) #define ELOW bitclr(LCDPort, Epin) #define E_OUTPUT bitclr(LCDTris, Epin) #define RSHIGH bitset(LCDPort, RSpin) #define RSLOW bitclr(LCDPort, RSpin) #define RS_OUTPUT bitclr(LCDTris, RSpin) #define RWHIGH bitset(LCDPort, RWpin) #define RWLOW bitclr(LCDPort, RWpin) #define RW_OUTPUT bitclr(LCDTris, RWpin) #define BUSY_FLAG bittst(LCDPort, BUSYpin) #define DATA_DIR_RD {bitset(LCDTris,DATA3pin);bitset(LCDTris,DATA2pin);bitset(LCDTris,DATA1pin);bits et(LCDTris,DATA0pin);} #define DATA_DIR_WR {bitclr(LCDTris,DATA3pin);bitclr(LCDTris,DATA2pin);bitclr(LCDTris,DATA1pin);bitc lr(LCDTris,DATA0pin);} #define OUTPUT_DATA(x) {int aval=LCDPort&0xF0; x = x & 0x0F; LCDPort=aval+x;} // some common defines #define bitset(var,bitno) ((var) |= (1 << (bitno))) #define bitclr(var,bitno) ((var) &= ~(1 << (bitno))) #define bittst(var,bitno) (var & (1 << (bitno))) void epulse(void){ __delay_us(1);
  • 2. EHIGH; __delay_us(1); ELOW; __delay_us(1); } void lcd_write( unsigned char cmd, unsigned char data_flag, unsigned char chk_busy, unsigned char dflag){ char bflag,c; if (chk_busy) { RSLOW; //RS = 0 to check busy // check busy DATA_DIR_RD; //set data pins all inputs RWHIGH; // R/W = 1, for read do { EHIGH; __delay_us(1); // upper 4 bits bflag = BUSY_FLAG; ELOW; __delay_us(1); epulse(); } while(bflag); } else { __delay_ms(10); // don't use busy, just delay } DATA_DIR_WR; if (data_flag) RSHIGH; // RS=1, data byte else RSLOW; // RS=0, command byte // device is not busy RWLOW; // R/W = 0, for write c = cmd >> 4; // send upper 4 bits OUTPUT_DATA(c); epulse(); if (dflag) { c = cmd & 0x0F; //send lower 4 bits OUTPUT_DATA(c); epulse(); } } void lcd_init(void) { // configure, see control pins as outputs // initialize as low E_OUTPUT; RS_OUTPUT; RW_OUTPUT; ELOW; RSLOW; RWLOW; __delay_ms(25); //wait for device to settle __delay_ms(25); lcd_write(0x20,0,0,0); // 4 bit interface lcd_write(0x28,0,0,1); // 2 line display, 5x7 font lcd_write(0x28,0,0,1); // repeat lcd_write(0x06,0,0,1); // enable display lcd_write(0x0C,0,0,1); // turn display on; cursor, blink is off lcd_write(0x01,0,0,1); // clear display, move cursor to home __delay_ms(3); // wait for busy flag to be ready } // send 8 bit char to LCD void putch (char c) { lcd_write(c,1,1,1); }
  • 3. void lcd_clear(void){ lcd_write(0x01,0,0,1); // clear display, move cursor to home } /* go to the specified position */ void lcd_goto(unsigned char row, unsigned char pos) { switch(row){ case 1:{lcd_write(0x80+pos,0,1,1);break;} case 2:{lcd_write(0xC0+pos,0,1,1);break;} case 3:{lcd_write(0x94+pos,0,1,1);break;} case 4:{lcd_write(0xD4+pos,0,1,1);break;} } } void lcd_shiftleft(void){ lcd_write(0x18,0,1,1); // shift left } void lcd_shiftright(void){ lcd_write(0x1C,0,1,1); // shift right } void lcd_blinkcursor(void){ lcd_write(0x0F,0,1,1); // displays and blink a cursor } void lcd_printbar(int bar){ for(int i=0; i<bar; i++){ lcd_write(0xFF,1,1,1); // print bars on the LCD } } void lcd_string(const char *s) //send a string to display in the lcd { unsigned char i=0; while (s && *s)lcd_write(*s++,1,1,1); } /********************LCD Driver End****************************************************/ /*******************start main program *************************************/ void main(void) { TRISD = 0b00000000; // configure all RD pin as output PORTD = 0b00000000; // reset all RD pin to 0 or off condition ANSEL = 0; // Configure AN pins as digital ANSELH = 0; C1ON = 0; // Disable comparators C2ON = 0; lcd_init(); // initialise LCD while(1){ // loop forever lcd_goto(1,0); //Display start at line 1 and position 0 printf("Tutorial PIC"); //display lcd_goto(2,0); //Display start at line 2 position 0 printf("visit:vto22012");
  • 4. //can use normal printf function like printf("Convert number %d",temp); } } /***********************main program end****************************************/