Share Pastebin
Guest
Public paste!

kimou

By: a guest | Mar 18th, 2010 | Syntax: C | Size: 2.39 KB | Hits: 110 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. /*
  2.  * PIC 16F886 HD44780 LCD Driver
  3.  * Author:    solarwind
  4.  * Date:      2009-01-31
  5.  * Email:     x.solarwind.x@gmail.com
  6.  * Compiler:  Microchip C18 (v3.22)
  7.  *
  8.  * Pin Configuration:
  9.  *              The LCD's data 4 - 7 pins should be connected to bits 4 - 7,
  10.  *              respectively, of any port you wish to use on your PIC.
  11.  *
  12.  *              The E, R/W and RS pins can be connected to any unused port at
  13.  *              any pin.
  14.  *
  15.  *              My configuration is as follows:
  16.  *              LCD        PIC
  17.  *              16 BK-
  18.  *              15 BK+
  19.  *              14 D7   -> RC7
  20.  *              13 D6   -> RC6
  21.  *              12 D5   -> RC5
  22.  *              11 D4   -> RC4
  23.  *              10 D3
  24.  *              9  D2
  25.  *              8  D1
  26.  *              7  D0
  27.  *              6  E    -> RC0
  28.  *              5  R/W  -> RC1
  29.  *              4  RS   -> RC2
  30.  *              3  VO
  31.  *              2  VDD
  32.  *              1  VSS
  33.  *
  34.  * Note:
  35.  *              This driver is designed to work with almost any PIC 18. Be sure to
  36.  *              correctly initialize your PIC, correctly connect your LCD and
  37.  *              define your connections below.
  38.  *
  39.  * Note:
  40.  *              DDRAM Addresses are as follows on 16 x 4 displays:
  41.  *
  42.  *              Line 1:  0x00 -> 0x0F
  43.  *              Line 2:  0x40 -> 0x4F
  44.  *              Line 3:  0x10 -> 0x1F
  45.  *              Line 4:  0x50 -> 0x5F
  46.  *
  47.  */
  48.  
  49. #ifndef LCD_H_
  50. #define LCD_H_
  51.  
  52. #include "main.h"
  53.  
  54. //Define your LCD's data PORT here:
  55. #define LCD_PORT PORTC
  56.  
  57. //Define your LCD's control pins here:
  58. #define LCD_E  PORTCbits.RC0 //Enable
  59. #define LCD_RW PORTCbits.RC1 //Read/write
  60. #define LCD_RS PORTCbits.RC2 //Register select
  61.  
  62. void strobe(void);                      //Strobes the enable pin of the LCD
  63. void send_nibble(byte b);               //Send high nibble of byte b to LCD
  64. void send_byte(byte b);                 //Send entire byte b to LCD via 4 bit interface
  65. void send_cmd(byte b);                  //Send command to LCD
  66. void send_data(byte b);                 //Send data to LCD
  67. void set_cursor(byte row, byte col);    //Set cursor position at (row, col)
  68. void cursor_on(void);                   //Turn on cursor
  69. void cursor_off(void);                  //Turn off cursor
  70. void cls(void);                         //Clear screen
  71. void sc_r(void);                        //Scroll all lines one character right
  72. void sc_l(void);                        //Scroll all lines one character left
  73. void home(void);                        //Send cursor to top-left position
  74. byte b2hc(byte data);                   //Convert lower nibble of byte data to an ascii character
  75. void lcd_init(void);                    //Initialize LCD
  76.  
  77. #endif /*LCD_H_*/