PDA

View Full Version : Help with 16f688



jessey
- 18th October 2006, 07:19
Hello,

This if my first time using the 16f688 micro and I am having trouble getting it set up properly to print to my Lcd in a 4 bit mode. I looked in the archives and couldn't find anything that deals with Lcd's using the 16f688. I tried to use CMCON0 = 7 to shut off the comparators but when I compile I get an error saying syntax error?

The Lcd does turn on but the top line is just all dark black blocks with light gray blocks on the bottom line. The Led flashes properly in the Mainloop. Can anyone here help me understand what I'm doing wrong for the Lcd. Any suggestions would be greatly appreciated.

Thanks
jessey



'************************************************* ******************************
'* Name : Blink Led *
'* Author : Jessey Montgomery *
'* Includes : *
'* Date : November 15/th 2006 *
'* Version : PicBasic Pro Ver 2.45, MPASM Ver 03.60, Using MicroCode Studio *
'* : 2.1.0.7, EPIC Version 2.46 beta programmer, PIC16F688-I/P 04470AY*
'************************************************* ******************************

' --------------
' | 16f688 |
' VDD+ (--->) |1 14| (<---) VSS-
' | |
' RA5/TICKI/OSC1/CLKIN (<-->) |2 13| (<-->) RA0/AN0/C1IN+/ICSPDAT/ULPWU
' | |
'RA4/AN3/TIG/OSC2/CLKOUT (<-->) |3 12| (<-->) RA1/AN1/C1IN-/Vref/ICSPCLK
' | |
' RA3/MCLR/Vpp(--->) |4 11| (<-->) RA2/AN2/TOCKI/INT/C1OUT
' | |
' RC5/RX/DX (<-->) |5 10| (<-->) RC0/AN4/C2IN+
' | |
' RC4/C2OUT/TX/CX (<-->) |6 9| (<-->) RC1/AN5/C2IN-
' | |
' RC3/AN7 (<-->) |7 8| (<-->) RC2/AN6
' | |
' --------------

'------------------------------------------------------------------------------'
'------------- Clear Each Port Before Setting The TRIS Registers --------------'
'------------------------------------------------------------------------------'

Clear ' Set all ram registers to zero
PORTA = 0
PORTC = 0

'--------------------------- VSS VDD MCLR Ect. Pins ---------------------------'

' VDD + '(pin 1)
' VSS - '(pin 14)

'------------------- SET THE TRIS ------------------'

'-------------------- PORTA PINS --------------------'

TRISC.0 = 0 '(pin 10) ...Blue.................Lcd Data bit 4
TRISC.1 = 0 '(pin 9) ....White................Lcd Data bit 5
TRISC.2 = 0 '(pin 8) ....Green................Lcd Data bit 6
TRISC.3 = 0 '(pin 7) ...Orange...............Lcd Data bit 7
TRISC.4 = 0 '(pin 6) ...Orange/Black.........Lcd Register select
TRISC.5 = 0 '(pin 5) ...Blue/White...........Lcd Enable bit

'-------------------- PORTC PINS --------------------'

TRISA.0 = 1 '(pin 13) NOT USED
TRISA.1 = 0 '(pin 12) NOT USED
TRISA.2 = 1 '(pin 11) NOT USED
TRISA.3 = 1 '(pin 4) NOT USED
TRISA.4 = 1 '(pin 3) NOT USED
TRISA.5 = 1 '(pin 2) .......................Led

;==============================================
;
; Configuration Bits
;
;==============================================

' _FCMEN_ON EQU H'3FFF'
' _FCMEN_OFF EQU H'37FF'
' _IESO_ON EQU H'3FFF'
' _IESO_OFF EQU H'3BFF'
' _BOD_ON EQU H'3FFF'
' _BOD_NSLEEP EQU H'3EFF'
' _BOD_SBODEN EQU H'3DFF'
' _BOD_OFF EQU H'3CFF'
' _CPD_ON EQU H'3F7F'
' _CPD_OFF EQU H'3FFF'
' _CP_ON EQU H'3FBF'
' _CP_OFF EQU H'3FFF'
' _MCLRE_ON EQU H'3FFF'
' _MCLRE_OFF EQU H'3FDF'
' _PWRTE_OFF EQU H'3FFF'
' _PWRTE_ON EQU H'3FEF'
' _WDT_ON EQU H'3FFF'
' _WDT_OFF EQU H'3FF7'
' _LP_OSC EQU H'3FF8'
' _XT_OSC EQU H'3FF9'
' _HS_OSC EQU H'3FFA'
' _EC_OSC EQU H'3FFB'
' _INTRC_OSC_NOCLKOUT EQU H'3FFC'
' _INTRC_OSC_CLKOUT EQU H'3FFD'
' _EXTRC_OSC_NOCLKOUT EQU H'3FFE'
' _EXTRC_OSC_CLKOUT EQU H'3FFF'
' _INTOSCIO EQU H'3FFC'
' _INTOSC EQU H'3FFD'
' _EXTRCIO EQU H'3FFE'
' _EXTRC EQU H'3FFF'

@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF

'------------------------------------------------------------------------------'
'------------------------ Connections For Parallel Lcd ------------------------'
'-------------------------- To 16F688 Microprocessor --------------------------'
'--------------------------------- 4 Bit Mode ---------------------------------'
'------------------------------------------------------------------------------'
' LCD Wire
'Pin No. Color Symbol Function Connections To 16F688
'------ ------ ------ -------- ---------------------
' 1 Black Vss Ground ---------------Connect to -5V
' 2 Red Vdd +5V ------------------Connect to +5V
' 3 White / Black Vo LCD contrast 10K pot -Connect to center pad
' -other 2 pads to + & -
' 4 Orange / Black RS Register select ------Connect to pin (6) RC4
' 5 Red / White R/W Read / write ---------Connect to -5V
' 6 Blue / White E Enable ---------------Connect to pin (5) RC5
' 7 (not used) DB0 Data bit 0
' 8 (not used) DB1 Data bit 1
' 9 (not used) DB2 Data bit 2
' 10 (not used) DB3 Data bit 3
' 11 Blue DB4 Data bit 4 -----------Connect to pin (10) RC0
' 12 White DB5 Data bit 5 -----------Connect to pin (9) RC1
' 13 Green DB6 Data bit 6 -----------Connect to pin (8) RC2
' 14 Orange DB7 Data bit 7 -----------Connect to pin (7) RC3

DEFINE LCD_EREG PORTC 'Set LCD Enable port
DEFINE LCD_EBIT 7 'Set LCD Enable bit

ANSEL = %00000000 ' no analog inputs

Led VAR PORTA.5 ' (pin 2)

'----------------------- Set Initial Time Variables -------------------------

PAUSE 2000 'wait for the Lcd to stabilize, show version screen below
lcdout $fe,1," Blink "
lcdout $fe,$c0," Led "
pause 1000

GOTO Mainloop

Mainloop

HIGH Led
Pause 500
Low Led
Pause 500

goto Mainloop

Dave
- 18th October 2006, 12:16
jessey, Try adjusting the voltage on the Contrast pin of the LCD. It should be close to 0 volts..

Dave Purola,
N8NTA

mister_e
- 18th October 2006, 12:43
There's few missing DEFINE and one bad to fit your actual hardware.


DEFINE LCD_RSREG PORTC 'LCD register select port
DEFINE LCD_RSBIT 4 'LCD register select bit
' 4 Orange / Black RS Register select ------Connect to pin (6) RC4

DEFINE LCD_EREG PORTC 'LCD enable port
DEFINE LCD_EBIT 5 'LCD enable bit
' 6 Blue / White E Enable ---------------Connect to pin (5) RC5


DEFINE LCD_DREG PORTC 'LCD data port
DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4
' 11 Blue DB4 Data bit 4 -----------Connect to pin (10) RC0
' 12 White DB5 Data bit 5 -----------Connect to pin (9) RC1
' 13 Green DB6 Data bit 6 -----------Connect to pin (8) RC2
' 14 Orange DB7 Data bit 7 -----------Connect to pin (7) RC3

jessey
- 20th October 2006, 08:50
Hi Steve,

Thanks for the define codes, my Lcd works like a charm now. I'll remember that the next time I change a Lcd Define to another port.

Thanks again
jessey

mister_e
- 20th October 2006, 13:20
You're welcome.

You live in a great city so far. i went there few years ago.

sayzer
- 20th October 2006, 14:36
Me too live in a great city Steve.
I have not seen you here yet. :)

mister_e
- 20th October 2006, 22:11
A contract and/or a pre-paid airplane ticket always help :D

jessey
- 20th October 2006, 23:12
Hi Steve,

I spent some time in Montreal too, in the late 1960's and early 1970's. Beautiful city that still holds fond memories for me.

It's a small world.

jessey