View Full Version : PIC Basic Code Understanding
pr2don
- 1st March 2010, 09:17
I am Learning Pic Basic, and I took ADC Sample code from melabs. I woul like to understand the following LCD Defination
Define LCD registers and bits
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
Lastly
adval.highbyte = ADRESH ' Move HIGH byte of result to adval
adval.lowbyte = ADRESL ' Move LOW byte of result to adval
Will be thank full if Someone Helps me
aratti
- 1st March 2010, 09:36
Define LCD registers and bits
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
Here you define the pin port that you will use to drive your LCD display.
adval.highbyte = ADRESH ' Move HIGH byte of result to adval
adval.lowbyte = ADRESL ' Move LOW byte of result to adval
adval is a word variable (16 bits) and you load this variable in two steps copying two single bytes (adval.highbyte = ADRESH will transfer the high byte) and ( adval.lowbyte = ADRESL will transfer the low byte)
Al.
pr2don
- 1st March 2010, 10:03
Define LCD registers and bits
1 Define LCD_DREG PORTD
2 Define LCD_DBIT 4
3 Define LCD_RSREG PORTE
4 Define LCD_RSBIT 0
5 Define LCD_EREG PORTE
6 Define LCD_EBIT 1
-Correct me if I am wrong, I understand Line 1 & 2
Line one means the LCD shold read from port D, Line 2 mean 4 bits
Should be connected LCD i.e RD0, RD1, RD2 & RD3
What I dont understand is line 3, 4, 5, 6. I am using pic16f876 & doest not hv pot D & E thats why I want to adapt this code
Thanks
HenrikOlsson
- 1st March 2010, 12:01
1 DEFINE LCD_DREG PORTD
2 DEFINE LCD_DBIT 4
This tells PBP that you have your LCD data-bus connected to PortD and that it "starts" at bit 4 of that port. In other word, the databus is connected to PortD.4-7 which means you are using it in 4-bit mode and that you'll also need:
DEFINE LCD_BITS 4
To tell PBP that you're using it in 4bit mode.
3 DEFINE LCD_RSREG PORTE
4 DEFINE LCD_RSBIT 0
This tells PBP that the RegisterSelect of the LCD is connected to PORTE.0
5 DEFINE LCD_EREG PORTE
6 DEFINE LCD_EBIT 1
This tells PBP that the Enable of the LCD is connected to PORTE.1
If your PIC doesn't have a PORTE then change the DEFINEs so it matches what you have - that's what they are there for.
/Henrik.
malc-c
- 1st March 2010, 20:17
Using the attached image and the following code will better explain Henriks post with regards to using other ports
http://micro-heli.co.uk/lcd.jpg
DEFINE LCD_DREG PORTB ' LCD Data port
DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4)
DEFINE LCD_EREG PORTB ' LCD Enable port
DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD)
DEFINE LCD_RSREG PORTB ' LCD Register Select port
DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD)
DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us
You can then use the following to initialise the LCD
LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 ' Initialize LCD
lilimike
- 10th March 2010, 00:55
Hi pr2don,
I am just one week late but if you are still learning or trying to understand, this is where I learned how it works.
http://iamsuhasm.wordpress.com/tutsproj/using-lcds/
Mike
shah_kunjan
- 20th March 2010, 02:58
Using the attached image and the following code will better explain Henriks post with regards to using other ports
http://micro-heli.co.uk/lcd.jpg
DEFINE LCD_DREG PORTB ' LCD Data port
DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4)
DEFINE LCD_EREG PORTB ' LCD Enable port
DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD)
DEFINE LCD_RSREG PORTB ' LCD Register Select port
DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD)
DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us
You can then use the following to initialise the LCD
LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 ' Initialize LCD
Hello Sir,
I am doing same things and working fine but sometimes when i power on the controller LCD doesn't display anything or it may display some garbage characters.
I am using pic 16f876A controller with crystal freq 10Mhz
LCD controller - Samsung KS0066
any suggestions are well comed...
thanks in advance
malc-c
- 20th March 2010, 11:38
Occasionally I've experienced similar things after the initial re-programming. Resetting the PIC or power to my development board always works for me.
Charles Linquis
- 20th March 2010, 14:40
You often have to pause about a half second before you write anything to the LCD. The displays are slow to get "started". The quarter-second pause in the previous example may not be quite enough.
shah_kunjan
- 31st May 2010, 10:38
Hello everyone,
I m using Picbasic language.
My problem is: I m sending serially data 2 times from PC and get only 1 time on PIC16Fxx controller.
I have tried polling method, then i have tried "ON INTERRUPT GOTO label"..... But in both methods i got same problem.
Actually my code lenth is very long. ... Is it creating a problem?
Pls giv me solution if anybody find out. I cannot optimize code length....
Thanks in advance
with regards
Kunjan Shah
mackrackit
- 31st May 2010, 11:21
shah_kunjan,
Please post your code. We would be guessing without it.
shah_kunjan
- 5th June 2010, 05:14
Hello Sir,
My code is too long of about 3000 lines......
It is not possible to post it here. if u give me ur email id then i can mail u....
Thank u
Kunjan
malc-c
- 5th June 2010, 10:51
Hello Sir,
My code is too long of about 3000 lines......
It is not possible to post it here.
Thank u
Kunjan
if you can't attach the file by renaming it as .txt then use winzip or winrar to compress the files and then attach the zip/rar file to a post
shah_kunjan
- 8th June 2010, 10:33
if you can't attach the file by renaming it as .txt then use winzip or winrar to compress the files and then attach the zip/rar file to a post
Hello Sir,
i m sending u my code. I m using RS-485 bus network. I m using serial interrupt for 16f876A.
I m sending serially data 2 times from PC and get only 1 time on PIC16Fxx controller.
code:
DEFINE HSER_CLROERR 1
goto Main
DEFINE INTHAND myint
asm
; Save W, STATUS and PCLATH registers
myint
movwf wsave
swapf STATUS, W
clrf STATUS
movwf ssave
movf PCLATH, W
movwf psave
; Insert interrupt code here
; Save and restore FSR if used
bsf _LED ; Turn on LED (for example)
GOTO _Serial
; Restore PCLATH, STATUS and W registers
movf psave, W
movwf PCLATH
swapf ssave, W
movwf STATUS
swapf wsave, F
swapf wsave, W
retfie
endasm
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
Main:
LOW LED
INTCON.6 = 1
INTCON.7 = 1
hserout [dec x," ", dec y]
lcdout $FE,1,#x," ",#y
here: goto here
Serial:
hserin [dec x,dec y]
' x = RCREG
' y = RCREG
low led
goto Main
'Resume
mackrackit
- 8th June 2010, 15:33
hserin [dec x,WAIT(" "),dec y]
Maybe???
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.