I bought some cheap HD44780-compatible LCD-displays on ebay to have something to play with (never used them before). The seller supplied some tutorials that I'm working with. I get the display to work on my breadboard when using 8-bit mode (controlled by a PIC 16F628A), but I cannot make it work using 4-bit mode. When I use 4-bit, D7-D4 is connected to RB3-RB0. When 8-bit, D7-D0 is connected to RB7-RB0. I've switched both the PIC and LCD to eliminate these sources of errors, so I'm probably doing something wrong in my code. Nothing else than the LCD-display and my Wisp-programmer is connected to the PIC. Here's the code: #include __CONFIG(INTIO & WDTDIS & PWRTDIS & MCLREN & UNPROTECT & BORDIS & LVPDIS); #define RS RA2 #define RW RA3 #define E RA4 #define D4 RB0 #define D5 RB1 #define D6 RB2 #define D7 RB3 void lcd_wait(void) { unsigned char i; unsigned int j; for (i = 0; i < 5; i++) {} for (j = 0; j < 6000; j++) {} } void init_delay(void) { unsigned int i; for (i = 0; i < 23456; i++) {} } void init_MCU(void) { TRISA = TRISB = 0; // All outputs PORTA = PORTB = 0; // Clear garbage OSCF = 1; // 4MHz INTOSC CMCON = 0b00000111; // Disable comparators VRCON = 0; // Disable voltage reference-module T1CON = 0; // Disable Timer1 CCP1CON = 0; // Disable CCP } void lcd_cmd(unsigned char cmd) { // According to the tutorial, only D7-D4 is used when 4-bit mode // is selected. RB3-RB0 goes to D7-D4 so we'll mask and shift // the commands. PORTB = (cmd & 0xF0) >> 4; E = 1; lcd_wait(); E = 0; PORTB = cmd & 0x0F; E = 1; lcd_wait(); E = 0; } void lcd_cmd_8bit(unsigned char cmd) { PORTB = cmd; E = 1; lcd_wait(); E = 0; } void lcd_putc(char letter) { RW = 0; RS = 1; lcd_cmd(letter); } void lcd_print(char *str) { char *p = str; while (*p) lcd_putc(*p++); } void main(void) { char snase[] = "ABC"; init_MCU(); init_delay(); // RA1 is a LED (for debugging) RA1 = 1; // This works fine in 8-bit, but not in 4-bit lcd_cmd(0b00111000); // Set 4-bit transfer, 2 lines lcd_cmd(0b00001111); // Display on, cursor on, blink, underline // lcd_cmd_8bit(0b00111000); // Set 4-bit transfer, 2 lines // lcd_cmd_8bit(0b00001111); // Display on, cursor on, blink, underline lcd_print(snase); RA1 = 0; while(1) { NOP(); } } What happens in the 4-bit mode is that the display responds to my commands, but instead of printing three letters (ABC) I get like "OOOOOO\\\\\\NNNNNN". That is, each letter is repeated and deformed. But - even weirder - is that this result is not 100% reproducible. Sometimes the display turns on and cursor blinks *before* the command is sent, and when this happens no garbled text is printed. This is the reason I tried to change displays, but the behaviour is similiar on everyone. 8-bit mode works fine for everyone. Can anyone shed some light on this? Is my lcd_cmd() erronious? -- - Rikard - http://bos.hack.org/cv/ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist