PDA

View Full Version : Configuring Defines For 8-bit LCD



lerameur
- 28th October 2006, 19:45
HI,

I am trying to make my pic16F648a inot a an 8 bit LCD out.
From what I see in the basic default program ( in the manual) it is at 4 bit default.
I did switch the define to 8 bit.
But the ereg should now be on portA, but with one of the 4 ?
The default at 4 it is set to RB3, why 3 ?
the rest I believe remain unchage

‘ Set LCD Enable port
DEFINE LCD_EREG PORTB

thanks

ken

So far this is what I have:

‘ Set LCD Data port
DEFINE LCD_DREG PORTB

‘ Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 0

‘ Set LCD Register Select port
DEFINE LCD_RSREG PORTB

‘ Set LCD Register Select bit
DEFINE LCD_RSBIT 4

‘ Set LCD Enable port
DEFINE LCD_EREG PORTA

‘ Set LCD Enable bit
DEFINE LCD_EBIT 3

‘ Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 8

LcdOut $FE, 1, "Hello"

amindzo
- 28th October 2006, 20:55
Hi,
please try this:

' Set LCD Data port
DEFINE LCD_DREG PORTB
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTB
' Set LCD Register Select bit
DEFINE LCD_RSBIT 1
' Set LCD Enable port
DEFINE LCD_EREG PORTB
' Set LCD Enable bit
DEFINE LCD_EBIT 0
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
pause 100
lcdout $fe,1,"Hello"
end


LCD Connection
Pin1=Vss: connect to ground
Pin2=Vdd: connect to Vcc=5V
Pin3=Vo: connect to middle pin of the POT(20K) to control brightness
Pin4=RS(register select): connect to micro pins that specify in the software(RB1)
Pin5=RW(Read/Write): connect to ground because we want to only write
Pin6=E(Enable): connect to micro pin that specify in the software(RB0)
Pin7 to 10: No connection
Pin 11 to 14: connect to RB4 to RB7
Pin15: connect to Vcc with a resistor(100 or 200 ohm resistor is good)
Pin16: connect to ground.
pin 16 and pin 16 are for backligh

lerameur
- 28th October 2006, 21:04
this code do not work. I forgot to say that I want an 8 bit transfer. Eventually i will want to display the output on my A/D conversion

I tried this code:
but still do not work

' Define LCD pins
Define LCD_DREG PORTB
Define LCD_DBIT 8
Define LCD_RSREG PORTA
Define LCD_RSBIT 0
Define LCD_EREG PORTA
Define LCD_EBIT 3
Define LCD_BITS 8

LcdOut $FE, 1, "Hello"

lerameur
- 28th October 2006, 21:19
Ok but if there is no connection for Pin7 to 10: it is then a 4 bit output no ?
I wanted to use all the output wires including Pin7 to 10.

ken

lerameur
- 29th October 2006, 02:46
so far so good, I do get someting on the lcd. I had wire connection problems
I found a chip that I have that did A/D conversion. Now I have another problem, my output value is always the same (around 500). It should read the input portC.0 from analog and display its decimal value to the lcd. The analog input is between 2 to 5 volt. I am using a Pic16F876a.

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 1
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 0
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

Define ADC_BITS 10
Define ADC_CLOCK 3
Define ADC_SAMPLEUS 50

adval var word

TRISC = %11111111
ADCON1 = %10000010
Low PORTB.2
Pause 500

loop: ADCIN 4, adval
Lcdout $fe, 1 Lcdout "Value: ", DEC adval
Pause 100
Goto loop
End

end

amindzo
- 29th October 2006, 08:47
Hi,
why don't you use the internal A/D of your microcontroller?

Archangel
- 29th October 2006, 08:51
this code do not work. I forgot to say that I want an 8 bit transfer. Eventually i will want to display the output on my A/D conversion

I tried this code:
but still do not work

' Define LCD pins
Define LCD_DREG PORTB
Define LCD_DBIT 8
Define LCD_RSREG PORTA
Define LCD_RSBIT 0
Define LCD_EREG PORTA
Define LCD_EBIT 3
Define LCD_BITS 8

LcdOut $FE, 1, "Hello"

Hi Lerameur,

Define LCD_DBIT 8
I am no expert, but shouldn't this be Define LCD_DBIT 0 ?
JS

lerameur
- 29th October 2006, 12:48
I thought I was calling the A/D of my controller by using ADCON and ADCIN...

ken

lerameur
- 29th October 2006, 14:38
mainly I just want to use this program but convert it
in picbasic pro and have a LCD out of the input.

‘***Real A to D on the 876****
program RealAtoDSafe
Dim data1 as word
Main:
TrisB = %00000000
TrisA = %00001000
ADCON1 = %10000100
while TRUE
data1=Adc_Read(3)
If data1 < 4 Then
data1 = 4
End If
PortB = word(data1 >> 2)
wend
End.
‘***************************

sayzer
- 29th October 2006, 14:47
Come on lerameur,

"Dim data1 as word"

You are also not using PBP!


-----------

lerameur
- 29th October 2006, 14:55
Like I said, I want to use this program but convert it into PBP
So from basic to PBP
I know that this is a pogram that compiles good with microbasic, but I want to use PBP.

K

BigWumpus
- 29th October 2006, 15:49
Ken,

you have written parts of this thread also to the PicList-mailinglist. Just try to understand the answers there !

I think you have 2 problems in 1 thread:

1. talking to a LCD by 8 data-lines

2. Using the AD-modul of a 16F876A


1.:
You have to wire PortB.0 until PortB.7 to the signals DB0 to DB7 of the LCD. The E-, RS- and RW-signal can be set to any free digital portpin !

2.:
my writing from the PicList:
-----
Ken,
you have to make clear, what ports you are using. This is important !
First you tried PortC.0 as AN4 - wrong,
then you changed it to PortA ? What pin ?
Now you use an unknwon language and refers to channel 3.

So,
make it easy for us to write your program.

What Port-Pin is connected to the analog input ?
-----

lerameur
- 29th October 2006, 16:08
well I do not want to start a new thread.
Mainly,I thought that I needed 8 bit to LCD since I wanted 8 bit analog input, but that is not the case, SO I will stay at 4 bit to LCD. which works fine.
Just my A/D conversion is not working. I have een playing around with ADCON0 AND ADCON1. I looked into PBP manual but no reference of ADCON0, AND THERE IS LITTLE on the spec sheet.

DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

' 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 50 ' Set sampling time in uS


adval var word
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000000
ADCON0 = %00000101
Low PORTB.2 ' LCD R/W line low (W)
Pause 500 ' Wait .5 second

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

Lcdout $fe, 1
Lcdout "Value: ", DEC adval
Pause 100
Goto loop
End

end

lerameur
- 29th October 2006, 16:12
as far as port I am using .
RB4 to RB7 out to LCD
RB0 RB1 as enable and register select bit

RA analog input

k

BigWumpus
- 29th October 2006, 17:27
Hi K,

You can forget to set Register ADCON0, because it is complete done by PBP.

The 16F876A has 5 analog inputs. If you want to use all of them, you should set the lower 4 bits of ADCON1 to "0000". Look at the datasheet !

You WROTE, you want to use 8 bit ad-input.
In your programm you USE 10-bit ad-input. Maybe you should define your parameters.
Using 10-bit ad you have to choose right-justified results, because pbp doesn't convert it. So put a "1" it the MSB of ADCON1!

lerameur
- 29th October 2006, 17:32
hi

I change these lines
TRISA = %11111111
ADCON1 = %10000010
ADCON0 = %11000001

and now it works, but it the output decimal value is never higher then 807, anyone know why

k

sayzer
- 30th October 2006, 07:58
Post the schematic, so that we can see you ADC reading part.

There should be a reference resistor for your ADC pin.

That gives your reading a scale (mostly it is the way)


-----------------------------------

BigWumpus
- 30th October 2006, 14:42
@sayzer
You have to read the piclist-mailist too, because there is the same thread, but there he wrote, that his "sensor" only gives him 3,7-4 volts.

lerameur
- 31st October 2006, 00:46
It is working now, The reference voltage on the Pic chip had to be change to 4 volt from 5 v.
:)

thank you all

ken

lerameur
- 1st November 2006, 03:43
Hi,

i will continue here and not start a new thread.
I am attempting to have two input values for an A/D conversion.
I added these two lines and did some changes.
How do I use the other input analog ports?

ken


' PicBasic Pro program to display result of
' 10-bit A/D conversion on LCD
'
' Connect analog input to channel-0 and channel1 (RA0, RA1)

' Define LCD registers and bits
Define LOADER_USED 1

DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

' 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 50 ' Set sampling time in uS


right var word 'Create right to store result
left var word

TRISA = %11111111 ' Set PORTA to all input
TRISB = 0
ADCON1 = %11000001 ' Set PORTA analog and RIGHT justify result
ADCON0 = %00000001 ' Configure and turn on A/D Module
Pause 500 ' Wait .5 second


loop: ADCON0.2 = 1 'Start Conversion

notdone: pause 5
if ADCON0.2 = 1 Then notdone 'wait for low on bit-2 of ADCON0, conversion finished

ADCIN 0, right 'Read channel 0
ADCIN 1, left 'Read channel 1

right.highbyte = ADRESH 'move HIGH byte of result to right
right.lowbyte = ADRESL 'move LOW byte of result to right

left.highbyte = ADRESH 'move HIGH byte of result to left
left.lowbyte = ADRESL 'move LOW byte of result to left

Lcdout $fe, 1 'Clear screen
Lcdout "Value right: ", DEC right 'Display the decimal value
Lcdout $C0, "Value left: ", DEC left 'Display the decimal value

Pause 100 'Wait .1 second

Goto loop 'Do it forever
End

lerameur
- 1st November 2006, 03:48
the program still displays the first value at channel 0 , but not a the other channel 1.

k

sayzer
- 1st November 2006, 07:33
Remove these parts from your code


ADCON0.2 = 1 'Start Conversion

notdone: pause 5
if ADCON0.2 = 1 Then notdone 'wait for low on bit-2 of ADCON0, conversion finished



and

right.highbyte = ADRESH 'move HIGH byte of result to right
right.lowbyte = ADRESL 'move LOW byte of result to right

left.highbyte = ADRESH 'move HIGH byte of result to left
left.lowbyte = ADRESL 'move LOW byte of result to left

---------------------------------

BigWumpus
- 1st November 2006, 07:47
right var word 'Create right to store result
left var word

TRISA = %11111111 ' Set PORTA to all input
TRISB = 0
ADCON1 = %11000001 ' Set PORTA analog and RIGHT justify result
ADCON0 = %00000001 ' Configure and turn on A/D Module
Pause 500 ' Wait .5 second


loop: ADCON0.2 = 1 'Start Conversion

notdone: pause 5
if ADCON0.2 = 1 Then notdone 'wait for low on bit-2 of ADCON0, conversion finished

ADCIN 0, right 'Read channel 0
ADCIN 1, left 'Read channel 1

right.highbyte = ADRESH 'move HIGH byte of result to right
right.lowbyte = ADRESL 'move LOW byte of result to right

left.highbyte = ADRESH 'move HIGH byte of result to left
left.lowbyte = ADRESL 'move LOW byte of result to left

Here, inside a forum for PicBasic Pro-Compiler, it is allowed to use some of his commands.

ADCIN 0,left
ADCIN 1,right
...will do the job for you.

savnik
- 1st November 2006, 08:01
Lcdout $C0, "Value left: ", DEC left 'Display the decimal value

use this for the second line:

Lcdout $FE, $C0, "Value left: ", DEC left 'Display the decimal value

lerameur
- 1st November 2006, 09:59
great its working
thank you

ken