PDA

View Full Version : 16f688 lcd connection



emerson
- 9th December 2010, 01:56
Hey all, I'm trying to write a program so I can use a LCM1602A lcd screen with a pic 16f688. Here are datasheets for both components:

lcd - http://www.vintagecomputercables.com/datasheet/LCM1602A-FL-YBW.pdf

16f688 - http://ww1.microchip.com/downloads/en/DeviceDoc/41203B.pdf

I believe the lcd is a HD44780 equivalent...but I'm not 100% sure. I have everything wired correctly to the best of my knowledge, but all I'm seeing on the screen are 16 black boxes across the top line. I'm using this website as guidance.

http://embedded-lab.com/blog/?p=203

I cannot take credit for this code, but this is the code I am using (how do I post my codes in the nice scrolling box?). Thanks to everyone for your help.



LED var porta.2

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

' PIC Hardware Definitions (ie Pin-Out & Port Assignments)
ANSEL = 0 ' all pins are digital
CMCON0 = 7 ' turn off comparators
ADCON0 = 0
ADCON1 = 0

'pin connection from pic chip to LCD
'1 VDD 5V
'2 OSC1 Crystal (internal 4MHz)
'3 OSC2 Crystal (internal 4MHZ)
'4 MCLR Pulled up
'5 RC5 E LCD
'6 RC4 RS LCD
'7 RC3 DB7
'8 RC2 DB6
'9 RC1 DB5
'10 RC0 DB4
'11 RA2 LED pin
'12 RA1 NC
'13 RA0 NC
'14 VSS Ov

'Define LCD registers and bits
DEFINE OSC 4 'Internal oscillator 4MHz
DEFINE LCD_DREG PORTC 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 0 'LCD Data Starting Bit = Bit 0 or 4
DEFINE LCD_EREG PORTC 'Define PIC port used for E line of LCD
DEFINE LCD_EBIT 5 'Define Port pin used for E connection
DEFINE LCD_RSREG PORTC 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 4 'Define Port pin used for RS connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent.

Pause 500 ' Wait for LCD to startup

loop:

high led
pause 200
low led

Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Hello" ' Display Hello
Pause 500 ' Wait .5 second

Lcdout $fe, 1 ' Clear LCD screen
Lcdout "World" 'Display World
Pause 500 ' Wait .5 second

Goto loop ' Do it forever

Archangel
- 9th December 2010, 02:29
Hello emerson,
put the word code inside brackets and close with / code inside brackets to enclose your code in a box. Check your contrast setting, I almost always just ground that pin, check your wiring for proper hookup AND for good connection. As I have not looked at the chips data sheet, check to be sure you have turned off ALL analog functions on the lcd's pins . . . are you sure ? Is your led flashing ? have you used bypass caps on the power at the PIC and LED ? Black boxes tell you LCD is alive more or less,so if led is flashing then so is PIC if not check your crystal and power connections first. A big ALSO, what config fuses are you using? The default ones? What are they ? Is the MCLR enabled ? do you have it pulled high ?
A good time to add DEFINE OSC xx where xx is your selected value.
Read and understand these threads please:
http://www.picbasic.co.uk/forum/showthread.php?t=543
http://www.picbasic.co.uk/forum/showthread.php?t=561
They will reduce your headache pain considerably, (caused by pulling hair) and with some luck you will keep more than I did . . .
hair that is . . .
Many Many people ask WHY the authors of PIC books suggest the 16f84 chip, and I can answer that, it is because it has almost nothing to set up to get it to work, so beginners do not get frustrated so early on, your chip does have plenty of nice features which make getting started a bit more challenging, BUT you came to the right forum to get some help too.
Hang in there, you are getting it.

emerson
- 9th December 2010, 04:16
Hello emerson,
put the word code inside brackets and close with / code inside brackets to enclose your code in a box. Check your contrast setting, I almost always just ground that pin, check your wiring for proper hookup AND for good connection. As I have not looked at the chips data sheet, check to be sure you have turned off ALL analog functions on the lcd's pins . . . are you sure ? Is your led flashing ? have you used bypass caps on the power at the PIC and LED ? Black boxes tell you LCD is alive more or less,so if led is flashing then so is PIC if not check your crystal and power connections first. A big ALSO, what config fuses are you using? The default ones? What are they ? Is the MCLR enabled ? do you have it pulled high ?
A good time to add DEFINE OSC xx where xx is your selected value.
Read and understand these threads please:
http://www.picbasic.co.uk/forum/showthread.php?t=543
http://www.picbasic.co.uk/forum/showthread.php?t=561
They will reduce your headache pain considerably, (caused by pulling hair) and with some luck you will keep more than I did . . .
hair that is . . .
Many Many people ask WHY the authors of PIC books suggest the 16f84 chip, and I can answer that, it is because it has almost nothing to set up to get it to work, so beginners do not get frustrated so early on, your chip does have plenty of nice features which make getting started a bit more challenging, BUT you came to the right forum to get some help too.
Hang in there, you are getting it.

As of now I have the contrast pin tied to ground, the MCLR pin pulled high via 10K resistor, all of my wiring is good and has good connection, I have the bypass cap (0.1uf) on the power source (5V USB) and the LED is blinking. I'm reading the documents you sent and I'm understanding them little by little. Still trying to figure out how to set config fuses. Do I need to enable MCLR in the program or does pulling it high do the trick?

emerson
- 9th December 2010, 05:05
I'm having trouble understanding how to set the config fuses, could you give me an example or at least explain it to me? Thanks.

emerson
- 9th December 2010, 16:16
I'm having trouble understanding how to set the config fuses, could you give me an example or at least explain it to me? Thanks.

This is what I have so far, and it compiles with no errors, but it still isn't doing the trick

'Configuration Fuses
@__EXTRC_OSC_NOCLKOUT
@__WDT_OFF
@__PWRTE_ON
@__MCLRE_OFF
@__BOREN_ON
@__LVP_OFF
@__CP_ALL
@__DATA_CP_ON
@__FCMEN_ON

malc-c
- 9th December 2010, 16:47
You've not mentioned which version of PBP you are using. I think I'm correct in stating that you can't use the word loop as a label in vers 2.60. Things like "main" are probably OK.

I've just searched through my PIC samples and don't have the one you are using. Is there any reason why you chose this PIC to use with an LCD as there are lots of other PICs that don't have the amount of functionality crammed into it as the 688.

As you have stated that you have a flashing LED, this would suggest the code is running, but the LCD isn't responding... this suggests a timing issue. You have used what looks like an external config setting (@__EXTRC_OSC_NOCLKOUT) but in the code it states "internal 4Mhz". Are you using the internal 4Mhz timing or an external crystal, if internal then that fuse should be something like @_INTRC_OSC_NOCLKOUT.

It's also worth posting up your schematic of how you have the hardware set up

emerson
- 9th December 2010, 17:24
You've not mentioned which version of PBP you are using. I think I'm correct in stating that you can't use the word loop as a label in vers 2.60. Things like "main" are probably OK.

I'm using PBP v2.47 with the MPASM assembler.


I've just searched through my PIC samples and don't have the one you are using. Is there any reason why you chose this PIC to use with an LCD as there are lots of other PICs that don't have the amount of functionality crammed into it as the 688.

Well, I was introduced to pic chips my freshman year in high school and the 16f688 is what we used in electronics class my 4 years there. All we did with them was blink lots of LEDs so we never had to learn much of the configuration steps.


As you have stated that you have a flashing LED, this would suggest the code is running, but the LCD isn't responding... this suggests a timing issue. You have used what looks like an external config setting (@__EXTRC_OSC_NOCLKOUT) but in the code it states "internal 4Mhz". Are you using the internal 4Mhz timing or an external crystal, if internal then that fuse should be something like @_INTRC_OSC_NOCLKOUT.

I'm using an external 10MHz oscillator. I didn't notice I had two different oscillator settings, good lookin' out.


It's also worth posting up your schematic of how you have the hardware set up

my circuit looks exactly like this with the two exceptions being the reset switch on MCLR (MCLR is still pulled high) and an external 10MHz crystal between pins 2 and 3
http://embedded-lab.com/blog/?attachment_id=685

malc-c
- 9th December 2010, 17:40
my circuit looks exactly like this with the two exceptions being the reset switch on MCLR (MCLR is still pulled high) and an external 10MHz crystal between pins 2 and 3


I assume with two small capacitors between each pin and GND - typically 15pf - 33pf ?

emerson
- 9th December 2010, 18:05
I assume with two small capacitors between each pin and GND - typically 15pf - 33pf ?

What's the purpose of these capacitors? the lowest value I have is 51pf, will this work?

malc-c
- 9th December 2010, 18:19
They are required as part of the timing circuit - take a read of page 9 of the PBP manual.

You can't simply place a crystal between the two pins, it needs to oscillate and these caps between GND and the pins are required to make the thing resonate

http://en.wikipedia.org/wiki/Crystal_oscillator

malc-c
- 9th December 2010, 18:30
What's the purpose of these capacitors? the lowest value I have is 51pf, will this work?

I tend to stick with 22pf. If you google crystal resonators or look at the images most are no higher than 33pf - but you've nothing loose by trying the ones you have

emerson
- 9th December 2010, 19:03
Would the 16c505, 16f630, or 16f627 be any easier to configure? I just found some in a box of components.

emerson
- 9th December 2010, 19:29
Would the 16c505, 16f630, or 16f627 be any easier to configure? I just found some in a box of components.

HEY!!! I tried my code with both the 16f630 and the 16c505 and it worked! Too bad you can only program 16c505 once, oh well.

Thanks to everyone for their help. I really appreciate your time and effort.

Archangel
- 10th December 2010, 04:20
Hi emerson,
glad it works with the chip you tried, but it should work with the 16F688 too. I am still leaning toward an analog function killing it. I did not see ANSELH in the data sheet but have found that to cause chips that have it to not do digital, try ANSELH=0 , if the compiler errors then it is invalid, but it is worth a try,(it is free to try, right?). You say you are set up to use MPASM. MPASM configs are different than the PB configs you have shown, and at any rate to use your own configs you MUST open the 16F688.inc file in your PBP root directory and comment out the config statements inside of it by adding a semicolon [ ; ] just ahead of them, there are 2 configs there one for PB and the other for MPASM. MPASM will look like
@ __config, HS_OSC & MCLRE_OFF & . . . . if you do not comment them out you will get compile error complaint of overwriting . . . and it will use the default config you failed to comment out.
Here is a link similar:
http://www.picbasic.co.uk/forum/showthread.php?t=12695