PDA

View Full Version : Help with LCD



teknoman2420
- 20th August 2006, 04:17
the first code works with 4mhz but not 20mhz why
and second code does not work with iether
but is suposed to display ADC value on LCD
from a thermister

do the Defines for ADC need to be changed
Thanks any help is great
--------------
' PicBasic Pro program to display "Hello World" on LCD
' Auther mel
' Define LOADER_USED to allow use of the boot loader.
' This will not affect normal program operation.
DEFINE LOADER_USED 1
DEFINE OSC 4
' Define LCD registers and bits
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 0
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 4000
DEFINE LCD_DATAUS 50


TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
Low PORTE.2 ' LCD R/W line low (W)
Pause 500 ' Wait for LCD to start up

loop: LCDOut $fe, 1 ' Clear screen
Pause 500 ' Wait .5 second

LCDOut "Hello" ' Display "Hello"
Pause 500 ' Wait .5 second

LCDOut "world" ' Display "Hello"
Pause 500 ' Wait .5 second

GoTo loop ' Do it forever
End
-----------------------------------
' PicBasic Pro program to display result of
' 10-bit A/D conversion on LCD
'
' Connect analog input to channel-0 (RA0)

' Define LOADER_USED to allow use of the boot loader.
' This will not affect normal program operation.
DEFINE LOADER_USED 1
DEFINE OSC 4
' Define LCD registers and bits

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 0
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 4000
DEFINE LCD_DATAUS 50
' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 200 ' Set sampling time in uS

adval VAR WORD ' Create adval to store result


TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
Low PORTE.2 ' LCD R/W line low (W)

Pause 500 ' Wait .5 second

loop: ADCIN 0, adval ' Read channel 0 to adval

LCDOut $fe, 1 ' Clear LCD
LCDOut "Value: ", DEC adval ' Display the decimal value

Pause 100 ' Wait .1 second

GoTo loop ' Do it forever
End

mister_e
- 20th August 2006, 09:13
Are you using the Bootloader?
Why you didn't change the DEFINE OSC to 20MHZ?
Did you set the config fuses? i guess not.

'It doesn't work' mean nothing. Wich part doesn't work? LCD or what?

We don't have your PIC model
We don't have your schematic

We have nothing. How can we help you?

Dave
- 20th August 2006, 14:46
teknoman2420, The second version of your code will not work @ 20 Mhz as you have not defined the oscillator frequency to be 20 Mhz. you need to change this line:
DEFINE OSC 4 to DEFINE OSC 20 as well as change the actual crystal.

Dave Purola,
N8NTA

teknoman2420
- 20th August 2006, 21:21
sorry for not giving enough info
i am working with a PIC16F877
the config fuses are set to
HS high speed enable
code protect Disable
WDT disable
PWR enable
WRT enable
debug disable
brown out enable
LV programing disable

now for LCD
RS bit to PORTE.0
E bit to PORTC.0
RW to ground
data bus to portB bits 4 to 7
if i use Define osc 4 or Define osc 20
makes no diference works the same
but if i change the crystal to 4 mhz it works
with the first code
the bootloader will not load at 4 mhz
i must swap it to 20mhz then back to 4mhz
because my target file is for 20mhz and the pic is 20mhz
i could change the target file to 4mhz but that dosn't solve the problem
and i will learn nothing, i want to see why
and it still dosn't work with second code for the thermister

I programed my target file with the LAB-tool 48
and although i am not working PIC16F876 28 pin
i can't get any of my four 28 pin pics to work at all
when programed with LAB-tool 48 even a simple blink test
but the 877 will, i'm not sure if they got damaged
from my other programer it was putting out 16V to pin 1
when it was suposed to put out 13V to pin 1 for programming
am i right about the voltage
can this damage a pic
but i'll find out someday when i order more pics
this lab tool 48 is not the newer version or upgraded
but supports the 40 pin 877 & 28 pin 876
it also suports some of 18 series pics
& 276 other pic micros
and probly about 2000 other devices

thanks i hope that helps

mister_e
- 20th August 2006, 22:05
OK,
Just to make sure everything is done properly, first you must load the 20MHZ bootloader file in your PIC, be sure the HS fuse is set before programming it, then, change DEFINE OSC 4 to DEFINE OSC 20 and last step, load your code in your PIC.

Be sure you use the right capacitor values for the crystal, your PSU is properly filtered and it should work now.

Good luck!

teknoman2420
- 21st August 2006, 08:21
it still jumps around a little,
and not displaying correctly with 20mhz crystal
and the value keeps changing too much
why is that
also when i put my fingers on the thermister
it only changes from 686 to 750
that's with 10K ohm resistor from portA.0 to ground
that brings it down,
and the thermister is connected at portA.0 to VDD 5V
with thermister only it goes to highest value 1023 at 10 bit ADC
and is at or close to 5 volts
maybe i have wrong thermister
or because i'm only changing the temp a few degrese
am i doing it right
i guess i'm learned a few thing anyway

Dave
- 21st August 2006, 11:46
teknoman2420, Have a look at app. note AN685 from Microchip which dives into attaching a thermistor to a microcontroller. A good reference.

Dave Purola,
N8NTA