Bonjour,
je suis en train de programmer un écran LCD alphanumérique 8*2 Everbouquet pour lequel la datasheet est très pauvre. Ils ne disent pas quel controleur est utilisé, mais en fouillant un peu sur le net il est supposé que c'est un clone du Hitachi standard. (http://www.farnell.com/datasheets/316294.pdf
J'utilise un PIC18F1320 et je programme en C avec MPLAB C18. Après de nombreux essais, je ne parviens toujours pas à afficher un seul caractère. Les cases sont toutes sombres, je ne parviens donc même pas à l'initialiser, ni à faire clignoter de curseur ... Je l'utilise en mode 4 bits et sans utiliser le R/W car je n'ai pas assez de pins disponibles. Je dois donc utiliser une fonction Delay. J'utilise l'horloge interne à 8Mhz.
Pourriez-vous svp jeter un coup d'oeil à mon code, je désespère...
Merci d'avance.
.Code:/* Prog LCD display pic18LF1320 LCD 8*2 Alphanumeric 4bits mode */ #include <p18f1320.h> #pragma config WDT = OFF #pragma config OSC = INTIO2 #pragma config FSCM = OFF #pragma config IESO = OFF #pragma config PWRT = OFF #pragma config BOR = OFF #pragma config MCLRE = OFF #pragma config STVR = ON #pragma config LVP = OFF #pragma config DEBUG = OFF #pragma config CP0 = OFF #pragma config CP1 = OFF #pragma config CPB = OFF #pragma config CPD = OFF #pragma config WRT0 = OFF #pragma config WRT1 = OFF #pragma config WRTB = OFF #pragma config WRTC = OFF #pragma config WRTD = OFF #pragma config EBTR0 = OFF #pragma config EBTR1 = OFF #pragma config EBTRB = OFF //#pragma config STVR = OFF //#pragma config BORV = 20 //#pragma config WDTPS = 32768 // Sorties LCD #define LCD_RS PORTAbits.RA1 #define LCD_EN PORTBbits.RB1 #define LCD_D4 PORTAbits.RA2 #define LCD_D5 PORTAbits.RA3 #define LCD_D6 PORTBbits.RB4 #define LCD_D7 PORTBbits.RB5 #define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0)); // impulsion positive // LCD Display functions extern void lcd_init(void); extern void lcd_write(unsigned char c_display); extern void lcd_clear(void); extern void lcd_puts(const rom far char * s); extern void lcd_goto(unsigned char pos); extern void lcd_goto2(unsigned char pos2); extern void lcd_home(void); extern void lcd_home2(void); extern void lcd_write1(unsigned char c_display); // Delay functions, 8Mhz clock void Delay(unsigned int cnt); void main(void){ //configuration des ports du MCU TRISA =0x20; TRISB =0x04; PORTA =0x00; PORTB =0x00; OSCCON = 0x72; // 8MHz, Run Mode, internal osc, ADCON0 = 0x00; // disable ADCON1 = 0x7F; // Tout le portA digital lcd_init(); Delay(2000000); lcd_home(); Delay(2000000); lcd_puts(Hello); } /* Fonctions Delay*/ void Delay(unsigned int cnt) // { unsigned long time; time = 0; while (time < cnt) { time = time+1; } } /* fonctions LCD * Ecrit 4 bits sur LCD */ void lcd_write1(unsigned char c_display) { Delay(4000); if((c_display&(0b00010000))!=0) LCD_D4=1; else LCD_D4=0; if((c_display&(0b00100000))!=0) LCD_D5=1; else LCD_D5=0; if((c_display&(0b01000000))!=0) LCD_D6=1; else LCD_D6=0; if((c_display&(0b10000000))!=0) LCD_D7=1; else LCD_D7=0; LCD_STROBE(); } void lcd_write(unsigned char c_display) { Delay(40000); // time to be checked if((c_display&(0b00010000))!=0) LCD_D4=1; else LCD_D4=0; if((c_display&(0b00100000))!=0) LCD_D5=1; else LCD_D5=0; if((c_display&(0b01000000))!=0) LCD_D6=1; else LCD_D6=0; if((c_display&(0b10000000))!=0) LCD_D7=1; else LCD_D7=0; LCD_STROBE(); Delay(100); if((c_display&(0b00000001))!=0) LCD_D4=1; else LCD_D4=0; if((c_display&(0b00000010))!=0) LCD_D5=1; else LCD_D5=0; if((c_display&(0b00000100))!=0) LCD_D6=1; else LCD_D6=0; if((c_display&(0b00001000))!=0) LCD_D7=1; else LCD_D7=0; LCD_STROBE(); Delay(100); } /* Clear and home the LCD */ void lcd_clear(void) { LCD_RS = 0; lcd_write(0x01); // d'abord les 4 bits de poids forts Delay(4000); } /* write a string of chars to the LCD */ void lcd_puts(const rom far char * s) { LCD_RS = 1; // write characters while(*s) lcd_write(*s++); } /* Go to the specified position */ void lcd_goto(unsigned char pos) { LCD_RS = 0; lcd_write(0x80+pos); } /* Go to the specified position on the second line */ void lcd_goto2(unsigned char pos2) { LCD_RS = 0; lcd_write(0xC0+pos2); } /* Go back to the initial position of the first line */ void lcd_home(void) { LCD_RS = 0; lcd_write(0x02); // 0x80?? } /* Go back to the initial position of the second line */ void lcd_home2(void) { LCD_RS = 0; lcd_write(0xC0); } /* initialise the LCD - put into 4 bit mode */ void lcd_init(void) { char init_value; init_value = 0x30; LCD_RS = 0; // write control bytes LCD_EN = 0; // 2000 = 1ms Delay(30000); // power on delay lcd_write1(init_value); // force le LCD en mode 8 bits LCD_STROBE(); Delay(10000); LCD_STROBE(); Delay(400000); LCD_STROBE(); Delay(10000); lcd_write1(0x20);// mode 4 bits "2h" Delay(100); LCD_STROBE(); lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font lcd_write(0x08); // display off lcd_write(0x0E); // display on, blink curson on lcd_write(0x05); // entry mode lcd_clear(); lcd_goto(0x00); }
-----