PDA

View Full Version : LCD Troubles on 16F685



SOTASOTA
- 19th November 2011, 22:05
I configured the code for a 16F628a and it worked fine.
Now, I am trying to setup the same LCD for a 16F685.

#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
#ENDCONFIG

high PortC.0 'LED on Port to check to see if PIC boots

DEFINE OSC 4

define LCD_DREG PORTA ' Data on PORTA
define LCD_DBIT 0 ' Data starts on PORTA.0
DEFINE LCD_RSREG PORTA ' RS on PORTA
DEFINE LCD_RSBIT 4 ' RS on A4
DEFINE LCD_EREG PORTA ' E on PORTA
DEFINE LCD_EBIT 5 ' E on A5
DEFINE LCD_BITS 4 ' LCD 4 bit mode
DEFINE LCD_LINES 2 ' 2 line LCD display
Define LCD_COMMANDUS 2000 ' Command Delay (uS)
Define LCD_DATAUS 50 ' Data Delay (uS)

Pause 500 ' Wait for LCD to startup
mainloop:
LCDOut $fe, 1 ' Clear LCD screen
LCDOut "Hello"
toggle portc.0
pause 1000
GoTo mainloop
End

mackrackit
- 19th November 2011, 22:15
I think that chip has ADC on PORTA. Turn ADC off.

SOTASOTA
- 19th November 2011, 22:20
OK, how best to do that?

mackrackit
- 19th November 2011, 22:29
http://www.picbasic.co.uk/forum/showthread.php?t=561

SOTASOTA
- 19th November 2011, 22:54
Tried every bit of code to turn off ADC and CMC. Still the LCD just sits there and stares at me (!).

mackrackit
- 19th November 2011, 23:40
I just looked at the datasheet and RA3 is the MCLR pin. You need to move things around so RA3 is not used as an output.

SOTASOTA
- 19th November 2011, 23:46
Funny, I just looked at that! Thought maybe I could set a fuse to make this pin an output, but no avail.
However, the LCD is now working!!!!
Yay!
Thanks very much. Now, my next task is to set an ADC and see if I can get that to work...
Cheers.

SOTASOTA
- 20th November 2011, 01:54
OK, next step is to initialize the ADC. Tried it but cannot go further. Would be nice to see a run-down of all the settings like ADSEL, for novice programmers like me to see exactly what these settings do. So here is the code that does not read ADC port AN0. Now, I use PortA.4 and PortA.5 so I use this:
TrisA = 001111



#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
#ENDCONFIG
high portc.0
DEFINE OSC 4
DEFINE ADC_BITS 10 ' 10 bit A/D Conversion
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50 ' 50 uS A/D sample time
VRCON = 000000 ' Disable Comparator Voltage Reference
ANSEL = 000001 ' Set pin (AN0) to analog input, the rest to digital
ADCON0 = 001001 ' Set up A/D converter - Right Just., VDD REF., CH 0, ON
ADCON1 = 110000 ' Set up A/D Converter clock source to internal RC

TrisA = 001111

define LCD_DREG PORTB ' Data on PORTB
define LCD_DBIT 4 ' Data starts on PORTB.4
DEFINE LCD_RSREG PORTA ' RS on PORTA
DEFINE LCD_RSBIT 4 ' RS on A4
DEFINE LCD_EREG PORTA ' E on PORTA
DEFINE LCD_EBIT 5 ' E on A5
DEFINE LCD_BITS 4 ' LCD 4 bit mode
DEFINE LCD_LINES 2 ' 2 line LCD display
Define LCD_COMMANDUS 2000 ' Command Delay (uS)
Define LCD_DATAUS 50 ' Data Delay (uS)
adval var byte


Pause 500 ' Wait for LCD to startup
mainloop:
ADCIN 0, adval
LCDOut $fe, 1 ' Clear LCD screen
LCDOut "Magnetic Pulser"
'Charac 1234567890123456
LCDOut $fe, $c0 'Jump to second line
lcdout "Voltage:", DEC adval
toggle portc.0
pause 100
GoTo mainloop
End

mackrackit
- 20th November 2011, 10:27
This thread goes over some of it.
http://www.picbasic.co.uk/forum/showthread.php?t=11947

SOTASOTA
- 20th November 2011, 16:53
YAY!!! Sweet success!!!
Thanks VERY much for walking me through this!!
So good to see it working.
Cheers!