PDA

View Full Version : LCD / PC question



luminas
- 23rd August 2008, 09:53
I tried to connect my PIC to PC

LCD shows value exactly as the reading ( 0 to 255 ), but the terminal program shows a 2 bytes combination ( 0 / 0 to 255 / 255 )

For example : at reading 0, LCD shows 0 and terminal shows 0 0,
at reading 255, LCD shows 255 and terminal shows 255 255,

How to make both display the same reading - I want PC terminal displays the same reading as LCD (0 to 255 )? Thank you




main:
adcin 0,reading
lcdout $Fe,1," value: "
LCDOUT $FE, $C0, dec reading
pause 50
hserout [reading]
pause 50
goto main

Archangel
- 23rd August 2008, 19:45
Hi luminas,
is the variable "reading" a word, or byte variable ?

Kamikaze47
- 24th August 2008, 07:46
that "main" loop will continue looping, but each time the LCD will be cleared and the value re-written, however, the pc will just keep receiving a value each time, so you will get a whole heap of values spit out in your terminal.

Archangel
- 24th August 2008, 08:42
So try:


main:
adcin 0,reading
lcdout $Fe,1," value: "
LCDOUT $FE, $C0, dec reading
pause 50
hserout [DEC reading,10] ' DECIMAL VALUE OF READING WITH LINEFEED
pause 50
goto main

PP 80:81 ver 2.47
PP 82:83 ver 2.5
Note: I only looked at Hserout code. . .

luminas
- 24th August 2008, 10:11
Thank you for yor comments,
Joe: adding DEC statement caused the value in Terminal program incorrect , it spits more character

This is my code, please check if there is something wrong with fuses or defines
I use 18F2550, 10mhz xtal with hs pll ( 40mhz)



ASM
__CONFIG _CONFIG1L, _PLLDIV_10_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_1_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _VREGEN_OFF_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_ON_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L

ENDASM

define OSC 40
DEFINE LCD_DREG PORTB ' LCD data port
DEFINE LCD_DBIT 0 ' LCD data starting bit
DEFINE LCD_RSREG PORTB ' LCD register select port
DEFINE LCD_RSBIT 4 ' LCD register select bit
DEFINE LCD_EREG PORTB ' LCD enable port
DEFINE LCD_EBIT 5 ' LCD enable bit
DEFINE LCD_BITS 4 ' LCD data bus size
DEFINE LCD_LINES 2 ' Number lines on LCD
DEFINE LCD_COMMANDUS 1500 ' Command delay time in us
DEFINE LCD_DATAUS 44 ' Data delay time in us

DEFINE ADC_BITS 8 ' ADC resolution 8 bit
DEFINE ADC_CLOCK 3 '
DEFINE ADC_SAMPLEUS 50

define HSER_RCSTA 90H
DEFINE HSER_TXSTA 20H
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 25
DEFINE HSER_CLROERR 1

reading var byte


clear
porta = 0
portb = 0
portc = 0
TRISA = %00000001 ' Set PORTA to all input
TRISB = %00000000 ' Set PORTB to all output
TRISC = %00000000 ' Set PORTC.7 as input, other RC as output
ADCON1 = %00001110


LCDOUT $FE, 1
pause 100


main:
adcin 0,reading
lcdout $Fe,1," Value "
LCDOUT $FE, $C0, dec reading
pause 50
hserout [reading ]
pause 50
goto main

luminas
- 24th August 2008, 17:55
I just modified the program as follow:


main:

LCDOUT $FE, 1
for reading = 1 to 10
LCDOUT $FE, $C0, dec reading
hserout [reading ]
pause 500
next reading



LCD shows 1 to 10 sequence correctly, but the terminal program shows:
3
254
4
254
7
254
8
254
11
254
12
254
15
254
48
254
51
254
52
254

What is wrong ?

Kamikaze47
- 24th August 2008, 18:33
hserout[reading] will not display the value of "reading", it will send "reading" as if it was an ascii character. so for example, if reading=37 you will see the character % on your terminal.

You need to use hserout[DEC reading] for it to display the decimal representation of the value of reading.

*edit* also, check to make sure the serial out is working. try hserout["Test"] and see if u get Test on your terminal.

luminas
- 24th August 2008, 18:53
I changed my code to :


main:
LCDOUT $FE, 1
LCDOUT $FE, $C0, "test"
hserout ["test" ]
pause 1000
goto main


LCD displays "test" , nO problem
Terminal program displays:"
ÈKÛ¼ìÿ ( String )
C8 4B DB BC EC FF (Hex)

Kamikaze47
- 24th August 2008, 20:39
Its a problem with your serial baud settings for your pic.

Change the SPBRG value to 64 like this:

DEFINE HSER_SPBRG 64

You could probably even remove that line altogether.

luminas
- 25th August 2008, 03:54
thanks Kamikaze

After few hours trying any possible setup, I solved the problem

The problem is with HSPLL config.

If I change the config to:
_FOSC_HS_1H
define osc 10, it works

but if I change the config to :
_FOSC_HSPLL_HS_1H
define osc 40, it did not work as expected

HSPLL suppose to multiply the frequency, and if I define osc to 40 ( 4x ) it should be working right out of the box , right ? Or did I forget something ?

Could anyone share information about this ?

Kamikaze47
- 25th August 2008, 09:53
The PLL expects an input frequency that is a multiple of 4, which your 10 Mhz clock is not.

For this PIC I usually use a 4Mhz crystal with _PLLDIV_1_1L, _CPUDIV_OSC1_PLL2_1L, and _USBDIV_2_1L which results in a 48Mhz clock for the processor.

Have a look at the table in the data sheet on pages 29 and 30.

edit: also have a look at the figure on page 24 - it shows that the PLL must have a 4Mhz input.