librerie laurtec per diplay hd44780

  • Raban
  • Autore della discussione
  • Nuovo Utente
  • Nuovo Utente
Di più
13 Anni 1 Mese fa #6 da Raban
Risposta da Raban al topic Re: librerie laurtec per diplay hd44780
ecco le correzzioni che ho apportato :

cambiati gli header
tolta la libreria delay e utilizzato la libreria delay della microchip
utilizzato la funzione itoa delle libreria microchip
Code:
/********************************************************************************************** Author : Mauro Laurenti Version : 1.0 Date : 4/9/2006 CopyRight 2006 all rights are reserved ******************************************************** SOFTWARE LICENSE AGREEMENT ******************************************************** The usage of the supplied software imply the acceptance of the following license. The software supplied herewith by Mauro Laurenti (the Author) is intended for use solely and exclusively on Microchip PIC Microcontroller (registered mark). The software is owned by the Author, and is protected under applicable copyright laws. All rights are reserved. Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws (Italian or International ones), as well as to civil liability for the breach of the terms and conditions of this license. Commercial use is forbidden without a written acknowledgment with the Author. Personal or educational use is allowed if the application containing the following software doesn't aim to commercial use or monetary earning of any kind. THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. **********************************************************************************************/ #include <LCD_44780.h> #include <libpic30.h> //************************************************************ // Epulse Implementation //************************************************************ void Epulse (void) { LCD_E = 1; __delay32 (100000); LCD_E = 0; __delay32 (30000); } //************************************************************ // SendCommand Implementation //************************************************************ void SendCommand (unsigned char D3, unsigned char D2, unsigned char D1, unsigned char D0) { LCD_D0 = D0; LCD_D1 = D1; LCD_D2 = D2; LCD_D3 = D3; Epulse (); } //************************************************************ // Line2LCD Implementation //************************************************************ void Line2LCD(void) { SendCommand (1,1,0,0); SendCommand (0,0,0,0); } //************************************************************ // HomeLCD Implementation //************************************************************ void HomeLCD(void) { SendCommand (0,0,0,0); SendCommand (0,0,1,0); } //************************************************************ // ShiftLCD Implementation //************************************************************ void ShiftLCD(char shift, char number_of_shift) { char i; for (i=0; i < number_of_shift; i++) { SendCommand (0,0,0,1); SendCommand (1,shift,0,0); } } //************************************************************ // ShiftCursorLCD Implementation //************************************************************ void ShiftCursorLCD(char shift, char number_of_shift){ char i; for (i=0; i < number_of_shift; i++) { SendCommand (0,0,0,1); SendCommand (0,shift,0,0); } } //************************************************************ // GotoLineLCD Implementation //************************************************************ void GotoLineLCD (char line) { switch(line) { case 1: SendCommand(1,0,0,0); SendCommand(0,0,0,0); break; case 2: SendCommand(1,1,0,0); SendCommand(0,0,0,0); break; case 3: SendCommand(1,0,0,1); SendCommand(0,1,0,0); break; case 4: SendCommand(1,1,0,1); SendCommand(0,1,0,0); } } //************************************************************ // WriteCharLCD Implementation //************************************************************ void WriteCharLCD (unsigned char value) { unsigned char D3,D2,D1,D0; LCD_RS = 1; // Splitting of the first nibble D3 = (value & 0b10000000) >> 7; D2 = (value & 0b01000000) >> 6; D1 = (value & 0b00100000) >> 5; D0 = (value & 0b00010000) >> 4; SendCommand (D3,D2,D1,D0); // Splitting of the second nibble D3 = (value & 0b00001000) >> 3; D2 = (value & 0b00000100) >> 2; D1 = (value & 0b00000010) >> 1; D0 = (value & 0b00000001); SendCommand (D3,D2,D1,D0); LCD_RS = 0; } //************************************************************ // WriteStringLCD Implementation //************************************************************ void WriteStringLCD(char *buffer) { // Write data to LCD up to null while(*buffer) { // Write character to LCD WriteCharLCD(*buffer); // Increment buffer buffer++; } } //************************************************************ // WriteVarLCD Implementation //************************************************************ void WriteVarLCD(unsigned char *buffer) { // Write data to LCD up to null while(*buffer){ // Write character to LCD WriteCharLCD(*buffer); // Increment buffer buffer++; } } //************************************************************ // WriteIntLCD Implementation //************************************************************ void WriteIntLCD(int value, char number_of_digits){ // The array size is 5 plus end of string \0 unsigned char convertedInt [6]; // Index used to shift to the right the digit char index; // Integer is converted to string //itoa (value, (char*) convertedInt); itoa(convertedInt, value, 10); if (number_of_digits >0 ) { convertedInt[number_of_digits] = '\0'; // Shift the digit to the right removing the empty one while (!isdigit(convertedInt[number_of_digits-1])) { for (index = number_of_digits-1; index > 0; index--){ convertedInt[index] = convertedInt[index-1]; convertedInt[index-1] = ' '; } } } WriteVarLCD (convertedInt); } //************************************************************ // ClearLCD Implementation //************************************************************ void ClearLCD (void){ SendCommand (0,0,0,0); SendCommand (0,0,0,1); } //************************************************************ // CursorLCD Implementation //************************************************************ void CursorLCD(char active,char blinking) { SendCommand (0,0,0,0); SendCommand (1,1,active,blinking); } //************************************************************ // CursorLCD Implementation //************************************************************ void BacklightLCD(char active) { LCD_LED = active; } //************************************************************ // OpenLCD Implementation //************************************************************ void OpenLCD(void) { LCD_RS = 0x00; LCD_E = 0x00; LCD_RW = 0x00; __delay32 (3000000); SendCommand (0,0,1,1); __delay32 (150000); SendCommand (0,0,1,1); __delay32 (150000); SendCommand (0,0,1,1); __delay32 (150000); SendCommand (0,0,1,0); SendCommand (0,0,1,0); SendCommand (1,0,0,0); SendCommand (0,0,0,0); SendCommand (1,1,1,0); CursorLCD (0,0); ClearLCD (); }

Si prega Accesso o Crea un account a partecipare alla conversazione.

  • Raban
  • Autore della discussione
  • Nuovo Utente
  • Nuovo Utente
Di più
13 Anni 1 Mese fa #7 da Raban
Risposta da Raban al topic Re: librerie laurtec per diplay hd44780
e questo e' l'header file modificato
Code:
/********************************************************************************************** Author : Mauro Laurenti Version : 1.0 Date : 4/9/2006 CopyRight 2006 all rights are reserved ******************************************************** SOFTWARE LICENSE AGREEMENT ******************************************************** The usage of the supplied software imply the acceptance of the following license. The software supplied herewith by Mauro Laurenti (the Author) is intended for use solely and exclusively on Microchip PIC Microcontroller (registered mark). The software is owned by the Author, and is protected under applicable copyright laws. All rights are reserved. Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws (Italian or International ones), as well as to civil liability for the breach of the terms and conditions of this license. Commercial use is forbidden without a written acknowledgment with the Author. Personal or educational use is allowed if the application containing the following software doesn't aim to commercial use or monetary earning of any kind. THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. ******************************************************** PURPOSES ******************************************************** This library contains all the functions that are handy for controlling an LCD with a 44780 Hitachi controller. To use these functions for your pourpose you must set up properly the following LCD constants and the pins of the PORT/s that you will use. You can use any pin you want! **********************************************************************************************/ #include <p30f4011.h> #include <stdlib.h> #ifndef FLAG_LCD_44780 #define FLAG_LCD_44780 // Prototipe for itoa from ctype lib //char *itoa (int value, char *s); //itoa(char * buf, int val, int base); //************************************************** // LCD constants // All the following pin must be set as output //************************************************** #define LCD_D0 LATCbits.LATC15 #define LCD_D1 LATBbits.LATB8 #define LCD_D2 LATBbits.LATB7 #define LCD_D3 LATBbits.LATB6 #define LCD_RS LATDbits.LATD3 #define LCD_E LATCbits.LATC13 #define LCD_RW LATCbits.LATC14 #define LCD_LED LATFbits.LATF6 #endif //************************************************** // Constant Definitions #define LEFT 0 #define RIGHT 1 #define TURN_ON 1 #define TURN_OFF 0 #define BLINK_ON 1 #define BLINK_OFF 0 //************************************************** /*************************************************** * * Description: This function generated the Enable * pulse * * Parameters: * * void * * Return: * * void * ***************************************************/ void Epulse (void); /*************************************************** * * Description: This function send a 4 bit command out * * * Parameters: * * bit_0: bit 0 of the data bus (4 bit modality) * bit_1: bit 1 of the data bus (4 bit modality) * bit_2: bit 2 of the data bus (4 bit modality) * bit_3: bit 3 of the data bus (4 bit modality) * * Return: * * void * ***************************************************/ void SendCommand (unsigned char bit_3, unsigned char bit_2, unsigned char bit_1, unsigned char bit_0); /*************************************************** * * Description: Locate the cursor to the beginning * of Line 2. * * Parameters: * * void * * Return: * * void * ***************************************************/ void Line2LCD(void); /*************************************************** * * Description: Locate the cursor at home location. * First line first character * * Parameters: * * void * * Return: * * void * ***************************************************/ void HomeLCD(void); /*************************************************** * * Description: This function shift the LCD screen on * the left or rigt. * * Parameters: * * shift: 0 shift on the left * 1 shift on the right * * number_of_shift: Specify the number of time the * shift is executed * * Return: * * void * * Note: * You can use the LEFT RIGHT constant * ***************************************************/ void ShiftLCD(char shift, char number_of_shift); /*************************************************** * * Description: This function shift the LCD cursor on * the left or rigt. * * shift: 0 shift on the left * 1 shift on the right * * number_of_shift: Specify the number of time the * shift is executed * Return: * * void * * Note: * You can use the LEFT RIGHT constant * ***************************************************/ void ShiftCursorLCD(char shift, char number_of_shift); /*************************************************** * * Description: This function locate the LCD cursor on * the selected line. * Tested on 20x4 16x2 LCD displays. * * line: number of the line (1,2,3,4) * * * Return: * * void * * Note: * It might not work with all the LCD Diplay * ***************************************************/ void GotoLineLCD (char line); /*************************************************** * * Description: This function writes a char to the * LCD display. * * * Parameters: * * value: character to be sent * * Return: * * void * ***************************************************/ void WriteCharLCD (unsigned char value); /*************************************************** * * Description: This function write a const string * to the LCD display. * * Parameters: * * buffer : Is a const string like that "Hello" * * Return: * * void * ***************************************************/ void WriteStringLCD( char *buffer); /*************************************************** * * Description: This function write an array of char * to the LCD display. * * Parameters: * * buffer : It is an array of char * * Return: * * void * ***************************************************/ void WriteVarLCD(unsigned char *buffer); /*************************************************** * * Description: This function write an array of char * to the LCD display. * * Parameters: * * value : It is integer that must be written to the * LCD diplay. * * numeber_of_digits: It specifies the number of shown * digit [0-5]. * 0: Left Justified * 1-5: Right Justified with n digit * * Return: * * void * * Note: * If you set a number of digit less than required * the digit will be lost starting from the less * significant digit. Minus is like a digit. * ***************************************************/ void WriteIntLCD(int value, char number_of_digits); /*************************************************** * * Description: This Function clean the LCD display * * * Parameters: * * void * * Return: * * void * ***************************************************/ void ClearLCD (void); /*************************************************** * * Description: This function controls the cursor * option (blinking, active) * * Parameters: * * active: activate the cursor, showing it * 1 : cursor is ON * 0 : cursor is OFF * * blinking: let the cursor blink * 1 : Blinking is ON * 0 : Blinking is OFF * * Return: * * void * * Note: * You can use the constant TURN_ON, TURN_OFF * BLINK_ON, BLINK_OFF * ***************************************************/ void CursorLCD(char active,char blinking); /*************************************************** * * Description: This function controls the back ligth * LED * * Parameters: * * active: activate the cursor, showing it * 1 : LED is ON * 0 : LED is OFF * * Return: * * void * * Note: * You can use the constant TURN_ON, TURN_OFF * ***************************************************/ void BacklightLCD(char active); /*************************************************** * * Description: This funnction initializes the LCD * to work in 4 bit modality. * * Parameters: * * quartz_frequency: Quartz freq. expressed in MHz * used to run the PIC. * * Return: * * void * * Note: * You must properly set the microcontroller pins * using the TRISx registers * ***************************************************/ void OpenLCD(void);

Si prega Accesso o Crea un account a partecipare alla conversazione.

  • Mauro Laurenti
  • Moderatore
  • Moderatore
Di più
13 Anni 1 Mese fa #8 da Mauro Laurenti
Risposta da Mauro Laurenti al topic Re: librerie laurtec per diplay hd44780
Ciao,

grazie per aver postato il codice.
Tornerà utile quando convertirò le librerie per dsPIC! :)

Saluti,

Mauro

Si prega Accesso o Crea un account a partecipare alla conversazione.

  • spiderdab
  • Nuovo Utente
  • Nuovo Utente
Di più
12 Anni 6 Mesi fa - 12 Anni 6 Mesi fa #9 da spiderdab
Risposta da spiderdab al topic Re: librerie laurtec per diplay hd44780
Salve, mi sono appena iscritto e presentato.
mi accodo a questa discussione, per chiedere se è stata già fatta la modifica per questa libreria, per poterla usare sui dspic33.
In caso contrario, invece sono molte le modifiche da apportare? Io utilizzo MPLABX su linux con compilatore xc16.

E per quanto riguarda gli stessi display ma col PCF8574 per l'I2C, c'è qualcosa?

Grazie, Davide
Ultima Modifica 12 Anni 6 Mesi fa da spiderdab.

Si prega Accesso o Crea un account a partecipare alla conversazione.

  • Mauro Laurenti
  • Moderatore
  • Moderatore
Di più
12 Anni 6 Mesi fa #10 da Mauro Laurenti
Risposta da Mauro Laurenti al topic Re: librerie laurtec per diplay hd44780
Ciao,

personalmente non ho mai portato la libreria.
per adattarla ai dsPIC devi solo riadattare i registri delle porte e gestire propriamente le costanti in flash (rom)

Per usare la libreria LCD con PCF8574 devi accertarti di avere una libreria equivalente per il controllo del modulo I2C.
Altrimenti, per il resto, le due librerie LCD con o senza PCF8574 sono semplici routine in C.

Questo post mette in luce come portare il tutto in C30 ma per XC16 non ci sono ancora passato! :)

Saluti,

Mauro

Si prega Accesso o Crea un account a partecipare alla conversazione.

Moderatori: Mauro LaurentiMatteo Garia

Registrati al sito

Accedi a tutte le risorse e articoli non visibili pubblicamente, puoi registrarti con pochi passi.

Registrati al sito LaurTec.

Forum - Ultimi messaggi