Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

using pic16f628A portb for lcd

Status
Not open for further replies.

abofar

New Member
Greetings ,All
Can someone please help me with this code for 16f628a, it does not work I get black squares on the lcd first line. I verified that pic is working and the lcd is lalso working and the circuit is working because I used hex file and burned it every thing working, except my code. I want to use portb for the lcd.The code is:


'PicBasic program (Picbasic pro 2.46) to demonstrate operation of an LCD in 4-bit mode
' 16F628A
'
Define osc 16
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 0 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 1 ' 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 LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us


Pause 500 ' Wait for LCD to startup

loop: Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Hello" ' Display Hello

Lcdout $fe, $c0 ' Move cursol to Second line
Lcdout "World" ' Display World
Pause 500 ' Wait .5 second

Lcdout $fe, 1 ' Clear LCD screen
Lcdout "abcdefg"

Lcdout $fe, $c0 ' Move cursol to Second line
Lcdout "1234567"
Pause 500
Goto loop ' Do it forever

END

Obaid
 
I have no knowledge in picbasic but here are some tips:
- Did you connect to the databus on the LCD correctly?
- Did you try adjusting contrast?
-Isnt there some Init routine for the LCD?
-Try to show something very basic on the lcd like one character.
-Is your PORTB set to Digital IO?

Greetings, tubos
 
Last edited:
Thank you ,Tubos, for your quick response.
The circuit I am using is working including lcd. I know that because I used hex file which is coded for this circuit. I wanted to use the same circuit but I wanted to modify the code and since there is only hex code I have to do my code in Picbasic pro. Data connections ok . Why hex file work and my code does not work. I tried some smaller code still no luck. Portb is unlike porta there is no analoge comparators or ADC.

Obaid
 
Last edited:
you should find some other picbasic code for an LCD
then you can start from there.
Sorry i cant be of more help.
tubos
 
For starters post how your LCD is hooked up which pin where


And to write to the LCD it's like this
Code:
Define	LCD_DREG	PORTB
Define	LCD_DBIT	4
Define	LCD_RSREG	PORTB
Define	LCD_RSBIT	0
Define	LCD_EREG	PORTB
Define	LCD_EBIT	1


Loop:
pause 500
LCDOut $fe,1, "Hello World"
pause 500
goto Loop
end
 
Last edited:
The connections as fellow:
Lcd:
1-GNG
2-+5v
3-GND or to center point potentiometer.
4 (RS)-RB0
5-(RW)-GND
6E-RB1
11D4-RB4
12D5-RB5
13D6-RB6
14D7-RB7
I did as per your suggestion:
Define osc 16
Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTB
Define LCD_RSBIT 0
Define LCD_EREG PORTB
Define LCD_EBIT 1


Loop:
pause 500
LCDOut $fe,1, "Hello World"
pause 500
goto Loop
end
Obaid
 
Last edited:
You using a crystal intosc is not able to be 16mhz

The default Is the 4 mhz so if your not using crystal and have not changed the configure.

The delays will be longer then your thinking they should be and you may not be waiting long enough
 
Last edited:
I used 4Mz crystal it works .When I use 20Mz It does not work although I defined the osc frequency (define osc 20). Why is this?. I did not understand what you mean by the delay, if you mean the pause statement before lcdout, I used PAUSE 1000, still no luck.

Obaid
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top