I've been trying to get a HD44780 LCD module working with my pic16f886 for a few nights now. I've resorted to trying a ready made solution but I can't even get that to work. I've put an oscilloscope on D4-7 and used EN as an external trigger and have found that D4-7 only remain high until the next pin is set eg. if RB3 is set high, then it will fall low when RB4 is set (regardless of H or L). I have also seen this when stepping through the code in MPLAB X IDE v3.2. I've tried slowing down the clock/speed by using the int osc and manipulating _XTAL_FREQ but nothing seems to help.
Any helpful suggestions greatly appreciated, Robin
Here's the online solution: https://electrosome.com/lcd-pic-mplab-xc8/
The asm looks sensible to me too. I thought it may have been MOVF to PORTB and overwriting the prev values but it's using BCF and BSF, snippet below
Any helpful suggestions greatly appreciated, Robin
Here's the online solution: https://electrosome.com/lcd-pic-mplab-xc8/
C:
void Lcd_Port(char a)
{
if(a & 1)
D4 = 1; // D4 does go high
else
D4 = 0;
if(a & 2)
D5 = 1; // but falls low here....
else
D5 = 0; // ... or here
Code:
4: void Lcd_Port(char a)
05D1 00F0 MOVWF __pcstackCOMMON
5: {
6: if(a & 1)
05D2 1C70 BTFSS __pcstackCOMMON, 0x0
05D3 2DD8 GOTO 0x5D8
7: D4 = 1;
05D4 1283 BCF STATUS, 0x5
05D5 1303 BCF STATUS, 0x6
05D6 1586 BSF PORTB, 0x3
05D7 2DDB GOTO 0x5DB
8: else
9: D4 = 0;
05D8 1283 BCF STATUS, 0x5
05D9 1303 BCF STATUS, 0x6
05DA 1186 BCF PORTB, 0x3
10:
11: if(a & 2)
05DB 1CF0 BTFSS __pcstackCOMMON, 0x1
05DC 2DDF GOTO 0x5DF
12: D5 = 1;
05DD 1506 BSF PORTB, 0x2
05DE 2DE0 GOTO 0x5E0
13: else
14: D5 = 0;
05DF 1106 BCF PORTB, 0x2
Last edited:
