C18 LaurTec Library
2.5
Open Source C Library for PIC18 Microcontrollers
|
00001 /********************************************************************************************** 00002 00003 Author : Mauro Laurenti 00004 Version : 1.0 00005 Date : 09/03/2012 00006 00007 CopyRight 2006-2012 all rights are reserved 00008 00009 ******************************************************** 00010 SOFTWARE LICENSE AGREEMENT 00011 ******************************************************** 00012 00013 The usage of the supplied software imply the acceptance of the following license. 00014 00015 The software supplied herewith by Mauro Laurenti (the Author) 00016 is intended for use solely and exclusively on Microchip PIC Microcontroller (registered mark). 00017 The software is owned by the Author, and is protected under applicable copyright laws. 00018 All rights are reserved. 00019 Any use in violation of the foregoing restrictions may subject the 00020 user to criminal sanctions under applicable laws (Italian or International ones), as well as to 00021 civil liability for the breach of the terms and conditions of this license. 00022 Commercial use is forbidden without a written acknowledgment with the Author. 00023 Personal or educational use is allowed if the application containing the following 00024 software doesn't aim to commercial use or monetary earning of any kind. 00025 00026 THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, 00027 WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED 00028 TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00029 PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHOR SHALL NOT, 00030 IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR 00031 CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 00032 00033 ******************************************************** 00034 PURPOSES 00035 ******************************************************** 00036 00037 00038 This library contains all the functions that are handy for controlling 00039 an LCD with a 44780 Hitachi controller via an I2C interface made with a PCF8574 00040 00041 Before using the functions you have to properly initialize the I2C module to 100KHz. 00042 hardware connetions are (using Eagle CAD nomenclature): 00043 00044 PCF8574 P0 -> LCD D4 00045 PCF8574 P1 -> LCD D5 00046 PCF8574 P2 -> LCD D6 00047 PCF8574 P3 -> LCD D7 00048 PCF8574 P4 -> LCD E 00049 PCF8574 P5 -> LCD R/W 00050 PCF8574 P6 -> LCD RS 00051 PCF8574 P7 -> LCD LED (use a PNP transistor as buffer to drive the backlight LED). 00052 00053 SDA, SCL must be connected to the I2C buffer with pull-up resistors. 00054 A0-A1-A2 adderss pins must be set as required. 00055 Set PCF8574_ADDRESS_L (see below) accordengly to the address pis A0-A1-A2. 00056 00057 More details and pictures can be downloaded from the Brief Note BN0015 (www.LaurTec.com) 00058 00059 **********************************************************************************************/ 00060 00061 #include <p18cxxx.h> 00062 #include <delay.h> 00063 #include <ctype.h> 00064 00065 00066 #ifndef FLAG_LCD_44780_I2C 00067 #define FLAG_LCD_44780_I2C 00068 00069 // Prototipe for itoa from ctype lib 00070 char *itoa (int value, char *s); 00071 00072 //************************************************** 00073 // LCD constants 00074 // Each bit is connected to the PCF8574 00075 //************************************************** 00076 00077 00078 #define LCD_D0 0b00000001 00079 #define LCD_D1 0b00000010 00080 #define LCD_D2 0b00000100 00081 #define LCD_D3 0b00001000 00082 #define LCD_E 0b00010000 00083 #define LCD_RW 0b00100000 00084 #define LCD_RS 0b01000000 00085 #define LCD_LED 0b10000000 00086 00087 //************************************************** 00088 // PCF8574 Address 00089 // PCF8574_ADDRESS_H refers to the enbedded address (PCF8574 model) 00090 // PCF8574_ADDRESS_L refers to the A0, A1, A2 pins 00091 //************************************************** 00092 00093 //PCF8574 00094 //#define PCF8574_ADDRESS_H 0x40 00095 00096 //PCF8574A 00097 #define PCF8574_ADDRESS_H 0x70 00098 00099 #define PCF8574_ADDRESS_L 0x00 00100 00101 //************************************************** 00102 // Constant Definitions 00103 00104 #define LEFT 0b00000000 00105 #define RIGHT 0b00000100 00106 00107 #define TURN_ON_CURSOR 0b00000010 00108 #define TURN_OFF_CURSOR 0b00000000 00109 00110 #define TURN_ON_LED 0b00000000 00111 #define TURN_OFF_LED 0b10000000 00112 00113 #define BLINK_ON 0b00000001 00114 #define BLINK_OFF 0b00000000 00115 00116 //************************************************** 00117 00118 00119 00126 void Epulse (void); 00127 00128 00137 void SendCommand (unsigned char data); 00138 00139 00144 void Line2LCD(void); 00145 00146 00151 void HomeLCD(void); 00152 00153 00164 void ShiftLCD(char shift, char number_of_shift); 00165 00166 00178 void ShiftCursorLCD(char shift, char number_of_shift); 00179 00180 00188 void GotoLineLCD (char line); 00189 00190 00198 void WriteCharLCD (unsigned char value); 00199 00200 00210 void WriteStringLCD(const rom char *buffer); 00211 00212 00213 00222 void WriteVarLCD(unsigned char *buffer); 00223 00224 00238 void WriteIntLCD(int value, char number_of_digits); 00239 00240 00245 void ClearLCD (void); 00246 00247 00259 void CursorLCD(char active,char blinking); 00260 00261 00272 void BacklightLCD(char active); 00273 00274 00284 void OpenLCD(unsigned char quartz_frequency); 00285 00286 00287 #endif