PDA

View Full Version : Problem with Newhaven LCD on 18LF66K80



KrisDouglas
- 30th May 2014, 10:11
Hello,

I am having great difficulty getting a newhaven 20x4 LCD working on my 18LF66K80 in 4 bit mode. When using PORTA.0-3, once one bit of data is set, it gets unset before the next is set. I have temporary solved that by embedding assembler which achieves the same thing, however I am getting a persistent problem where the display just shows 2 rows of vertical lines.

http://s30.postimg.org/q7iqtpn25/20140530_094701.jpg (http://postimg.org/image/q7iqtpn25/)

I also get similar results from using LCDOUT, where basically when I set all the bits suitably it "just doesn't work" with similar effects to above.

I am confident with the wiring as we have another PIC with the same code written in C (albeit 8bit) working perfectly.


D4-7 are on RA0-3 respectively
RW is on RF3
RS is on RF2
E0 is on RA5

The following are the defines I tried for LCDOUT.


DEFINE LCD_DREG PORTADEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTF
DEFINE LCD_RSBIT 2
DEFINE LCD_REREG PORTF
DEFINE LCD_RWBIT 3
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2100
DEFINE LCD_DATAUS 500

An example of the code I am using to display some text is below:



Main:
LCDOut $fe,1:FLAGS=0:Pause 250
LCDOUT "Hello World"
pause 2000
goto Main

Any help getting to the bottom of this would be hugely appreciated!

Dave
- 30th May 2014, 11:45
Kris, I would move the commands "FLAGS=0" and "PAUSE 250" to just above the MAIN loop. There is no reason to be resetting the display every loop. Also I would set the cursor command to be part of the LCDOUT statement as such: LCDOUT $fe.1,"Hello World". And 2100 us. seems a bit long for the command. I have never used anything more than 250 us. in the past and I have used all different kinds of lcd displays from different mfr's.

KrisDouglas
- 30th May 2014, 11:47
Hello,

Thanks for your reply, though we have messed with the command delays a lot just to see if we could get it working, I'll adjust it and try again now. When I connect it to the oscilloscope it seems that the enable line isn't going high for long enough when using LCDOUT which was interesting.

I will try now and post the results.

Dave
- 30th May 2014, 11:54
One last thought Kris, I would like to see the direction registers for your ports as well as the the ANCON register values for the portA port F.

KrisDouglas
- 30th May 2014, 12:07
Hello, my code for the LCD is as follows:



' ------------------------------------------------------
' MiniCon Motherboard LCD Test
' Kris Douglas 23/05/14

' ------------------------------------------------------
' We will run at 64MHz once the PLL is started up
Define OSC 64

'LCD Definitions
DEFINE LCD_DREG PORTA
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTF
DEFINE LCD_RSBIT 2
DEFINE LCD_REREG PORTF
DEFINE LCD_RWBIT 3
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2100
DEFINE LCD_DATAUS 500

' ------------------------------------------------------
' PIC18LF66K80 Configuration Bit Settings

' Basic source line config statements

#CONFIG
CONFIG RETEN = OFF
CONFIG INTOSCSEL = HIGH
CONFIG SOSCSEL = DIG
CONFIG XINST = OFF
CONFIG FOSC = INTIO2
CONFIG PLLCFG = ON
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRTEN = ON
CONFIG BOREN = SBORDIS
CONFIG BORV = 1
CONFIG BORPWR = ZPBORMV
CONFIG WDTEN = ON
CONFIG WDTPS = 1048576
CONFIG CANMX = PORTB
CONFIG T0CKMX = PORTB
CONFIG T3CKMX = PORTG
CONFIG MSSPMSK = MSK7
CONFIG MCLRE = ON
CONFIG STVREN = ON
CONFIG BBSIZ = BB2K
CONFIG CP0 = OFF
CONFIG CP1 = OFF
CONFIG CP2 = OFF
CONFIG CP3 = OFF
CONFIG CPB = OFF
CONFIG CPD = OFF
CONFIG WRT0 = OFF
CONFIG WRT1 = OFF
CONFIG WRT2 = OFF
CONFIG WRT3 = OFF
CONFIG WRTC = OFF
CONFIG WRTB = OFF
CONFIG WRTD = OFF
CONFIG EBTR0 = OFF
CONFIG EBTR1 = OFF
CONFIG EBTR2 = OFF
CONFIG EBTR3 = OFF
CONFIG EBTRB = OFF
#ENDCONFIG

' ------------------------------------------------------
' Alias definitions

'Alias the LED on the board
localLed var PORTA.7

'Alias the LCD control pins
LCD_Backlight var PORTB.5
LCD_E2 var PORTF.1

'Alias the buzzer on the board
buzzer var PORTC.1

'Alias the watchdog
mbWatchDog var PORTF.7

' ------------------------------------------------------
' Variables

'LCD Variables
lcdData var byte
bla var byte

' ------------------------------------------------------
' Set Phase-Locked Loop to Enabled

'OSCCON = OSCCON | %01110000
'OSCTUNE = OSCTUNE | %01000000

' ------------------------------------------------------
' Port configuration

'Port D needs setting to digital
ADCON1 = %01101111

' ------------------------------------------------------
' Program code to flash LED and display text on LCD
LCDOut $fe,1:FLAGS=0:Pause 250
Main:
LCDOUT $fe,1, "Hello World"
pause 1000
goto Main

Amoque
- 31st May 2014, 13:21
I am NOT familiar with the chip you are using, but just yesterday I was near to pulling out my few remaining hairs before realizing that I had not set my TRIS registers to output. Is this necessary on the 18LF66K80?

Demon
- 31st May 2014, 14:33
Try adding this:
http://www.picbasic.co.uk/forum/showthread.php?t=18529

Then check the warnings during compile. It will tell you how to make all pins digital.

You set port D to digital but I see nothing for port A.

Robert

longpole001
- 2nd June 2014, 19:12
i agree with robert , check port A config as a start point , as port a 0-5 are analog optional , also when connecting port at 64mhz i had some very bad results when not using the "LATA.x" commands for outputs , here Port A for the 18F67K22 , should be much the same




' ------- Setup port A Variables & directions ----------
ANCON0.0 = 1 ' Set PortA:0 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL0
ANCON0.1 = 1 ' Set PortA:1 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL1
ANCON0.2 = 1 ' Set PortA:2 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL2
ANCON0.3 = 1 ' Set PortA:3 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL3
ANCON0.4 = 1 ' Set PortA:5 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL4 Set RA5 (AN4/ ANSEL4) to be analog input for V-Mon

TRISA = %00101111 ' setup Port A input=1,output=0 for I/O pins , set input for RA0-RA3, RA5
PORTA = %00101111 ' Clear Outputs