PDA

View Full Version : Pic 16f737 lcd



neocode
- 5th May 2014, 23:49
Hi Everyone

I just received my 16F737 from MELABS. I am using PICBASIC PRO 2.50C

I have used an external 4MHZ Crystal and 2 10uf Capacitors tied to ground.

I have also the PICBASIC PRO Book by Dougan Ibrahim and i used the LCD example which prints "Hello" Clear Screen and then "World" and it works perfectly fine.
I have also made the connections as assumed by PBP without defining ports. The ports connected are as below:
LCD should be connected as follows:
' LCD PIC
' DB4 PortA.0
' DB5 PortA.1
' DB6 PortA.2
' DB7 PortA.3
' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.3
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)
************************************************** *****************

Now the issue i have is i used DEFINE statements to change the ports as below:
PicBasic program to demonstrate operation of an LCD in 4-bit mode
'
' LCD should be connected as follows:
' LCD PIC
' DB4 PortB.0
' DB5 PortB.1
' DB6 PortB.2
' DB7 PortB.3
' RS PortB.5 (add 4.7K pullup resistor to 5 volts)
' E PortB.4
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)
' DB0-3 No connect
************************************************** **



And the code in picbasic pro as follows:

************************************************** **

include "bs1defs.bas"

' Define LCD registers and bits
Define LCD_DREG PORTB
Define LCD_DBIT 0

Define LCD_RSREG PORTB
Define LCD_RSBIT 5

Define LCD_EREG PORTB
Define LCD_EBIT 4

TRISB = 0

pause 10

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


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


Goto loop ' Do it forever


END
************************************************** ************

Now the LCD pauses for a few seconds and there is a blinking cursor on Line 1, Column 1

When i connect back to the old configuration it works fine on the same code.

Also i am using a 4MHZ clock and a beginner in PBP and just switched from 89C51 Controller.
When i give 'PAUSE 5' it will wait for close to 5 seconds. Is there something that i have to mention about the close during flashing ? Or in code?

Also why will the LCD not function with this code. I rechecked and reconnected all the pins and all seems to be fine.

Please help to me find out what i am doing wrong.

Thanks to all in advance.

Demon
- 6th May 2014, 00:06
Try adding DEFINE OSC 4 (by memory, doublecheck syntax).

PAUSE 5 turning into 5000 is usually timing issue.

Are you sure about your cap size? I thought I used about 20pF, what does PBP manual recommend?

Edit: 5 milliseconds is extremely fast, try 1000, it is easier to check for 1 second visually.

Robert

neocode
- 6th May 2014, 00:18
Thanks Demon

I found out the same issue solved on this forum.

Here is the thread.

http://www.picbasic.co.uk/forum/showthread.php?t=3277

I set the ADCON1 = %0011111 to set digital signal and it works perfectly fine now.

I am using a 4MHZ crystal and when i program i select XT. Do we have to change something in the software to fix it ?

If i use the value PAUSE 20 it is close to 20 Seconds :eek:

neocode
- 6th May 2014, 00:24
Demon

I need to use Channel 13 for ADC. Here is what is in the manual


REGISTER 12-1: ADCON0: A/D CONTROL REGISTER 0 (ADDRESS 1Fh)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
ADCS1 ADCS0 CHS2 CHS1 CHS0 GO/DONE CHS3 ADON
bit 7 bit 0
bit 7-6 ADCS1:ADCS0: A/D Conversion Clock Select bits
If ADCS2 = 0:
000 = FOSC/2
001 = FOSC/8
010 = FOSC/32
011 = FRC (clock derived from an RC oscillation)
If ADCS2 = 1:
00 = FOSC/4
01 = FOSC/16
10 = FOSC/64
11 = FRC (clock derived from an RC oscillation)
bit 5-3 CHS<2:0>: Analog Channel Select bits
0000 = Channel 00 (AN0)
0001 = Channel 01 (AN1)
0010 = Channel 02 (AN2)
0011 = Channel 03 (AN3)
0100 = Channel 04 (AN4)
0101 = Channel 05 (AN5)(1)
0110 = Channel 06 (AN6)(1)
0111 = Channel 07 (AN7)(1)
1000 = Channel 08 (AN8)
1001 = Channel 09 (AN9)
1010 = Channel 10 (AN10)
1011 = Channel 11 (AN11)
1100 = Channel 12 (AN12)
1101 = Channel 13 (AN13)
111x = Unused
Note 1: Selecting AN5 through AN7 on the 28-pin product variant (PIC16F737 and
PIC16F767) will result in a full-scale conversion as unimplemented channels are
connected to VDD.
bit 2 GO/DONE: A/D Conversion Status bit
1 = A/D conversion cycle in progress. Setting this bit starts an A/D conversion cycle. This bit is
automatically cleared by hardware when the A/D conversion has completed.
0 = A/D conversion completed/not in progress
bit 1 CHS<3>: Analog Channel Select bit (see bit 5-3 for bit settings)
bit 0 ADON: A/D Conversion Status bit
1 = A/D converter module is operating
0 = A/D converter is shut-off and consumes no operating current
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown

Can you tell me what is the ADCON0 Value if i use a 4MHZ and need to use CHANNEL 13 ?