PDA

View Full Version : A question regarding PIC16F684 to LCD.



Peter.
- 29th May 2010, 20:49
First off, would like to express my thanks to this forum for imparting all this knowledge here. I've been ear-wigging on the sidelines for the past couple months, in which time have managed to glean a whole pile of much-needed information.
Name here is Peter/Pete, have just recently purchased PBP and in just a few days have so far breadboard'ed several LCD projects.. all working nicely, each one written for the PIC16F628A. From what I have learnt from the PBP manual, and from here, and from the data sheets so far, in order to use a LCD with a 16F684 means having to adjust other parameters, such as ANSEL, etc. I'm obviously not understanding something correctly because it's not working.
Could I trouble you to grok the code and possibly tell me where I'm going wrong, please?

Hopefully can one day contribute something back.
Meantime, top thanks once again.


; -----------------------------------------------------------

; Date: May 2010
; File name: lcd_test.pbp
; Compiler: PicBasic Pro V2.6
; Editor: MicroStudio V3.0.0.5
; Processor: PIC16F684
; Oscillator: External 4MHz
; LCD: 16 characters X 2 lines

; -----------------------------------------------------------

@ DEVICE PWRT_ON ; Set configuration fuses
@ Device BOD_ON
@ Device WDT_ON
@ Device MCLR_OFF
@ Device XT_OSC

; LCD-to-PIC configuration:
DEFINE LCD_DREG PortC ; Utilise Port C for all the data lines
DEFINE LCD_DBIT 0 ; 0 = 4-bit data; 4 = 8-bit data
; LCD pins D4 ~ D7 to PIC Port C.3 ~ C.0 (pins 7 ~ 10)
DEFINE LCD_BITS 4 ; Set bus size (4 = 4-bit data; 8 = 8-bit data)
DEFINE LCD_RSREG PortC ; Put the R/S Register on Port C
DEFINE LCD_RSBIT 5 ; LCD R/S pin to PIC Port C.5 (pin 5)
DEFINE LCD_EREG PortC ; Put the EnABLE Register on Port C
DEFINE LCD_EBIT 4 ; LCD En pin to PIC Port C.4 (pin 6)
DEFINE LCD_LINES 2 ; Set number of LCD lines (1 ~ 4)
DEFINE LCD_COMMANDUS 2000 ; Set 2-millisecond command period
DEFINE LCD_DATAUS 50 ; Set data delay period

CMCON0 = %00000111 ; Disable comparators
ANSEL = %00000111 ; Disable A/D convertors

TrisA = %000000 : Set Port direction Registers
TrisC = %000000
PortA = %000000
PortC = %000000

PAUSE 1000

LCDOUT $FE, 1 ; Initialise and clear the display

start:
LCDOUT $FE, $80, "Line 1" ; $80 = First line
LCDOUT $FE, $C0, "Line 2" ; $C0 = Second line
GOTO start

END

mackrackit
- 30th May 2010, 03:55
Welcome to the forum!

On this chip all analog is turned of by
ANSEL = %00000000
A little different than some... Data sheet section 4.2.1
But that may not be the problem.

; LCD pins D4 ~ D7 to PIC Port C.3 ~ C.0 (pins 7 ~ 10)Do you have the bus pins connected backward?

Peter.
- 30th May 2010, 17:45
Welcome to the forum!
Do you have the bus pins connected backward?

Hi, Mackrackit/Dave ~

Thanks for the welcome.
The ANSEL value in my previous post was indeed another of my typos, but as soon as I inverted the four data lines was when it all came to life.
You obviously have a keen eye. Credit to you for having the noodle to spot such an error.

And thanks a million for helping me out.

mackrackit
- 30th May 2010, 19:03
It was you well commented code that allowed the mistake to be found.
Keep up the good work!

And be sure to read the section of the data sheet I pointed to to see why the analog settings did not cause the problem... This time :)

Peter.
- 31st May 2010, 13:25
...be sure to read the section of the data sheet I pointed to to see why the analog settings did not cause the problem...

Thanks for that.
Okay by you if I pick your brains one more time, pse?.....
Just for the sheer sake of learning/curiosity, I'm reading the value of a standard 1mS~2mS R/C pulse, then writing that value to the LCD (Input mode). One of the ADCs is used to create another 1mS~2mS pulse, then displaying that value and at the same time sending the pulse to a separate pin (Output mode)... which works fine on ports A.1 and A.2, but not on ports A.3 ~ A.5.
I'm not sure that I'm fully understanding the ANSEL/TRISA thing because neither does the mode selection work when A.2 is HIGH - the program jumps straight to output mode and stays there.

Thanks again for your previous help. Appreciate you coming back.

mackrackit
- 31st May 2010, 15:26
Looks like the problem is using an analog configured pin as an input. You can use analog set pins as outputs as the data sheet says but not as digital inputs. The data sheet says something like if a pin is set for analog then all digital reads will be 0(low).

Peter.
- 31st May 2010, 23:03
I've cracked it.
Top thanks once again for the heads-up.