PIC Basic Code Understanding


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Feb 2010
    Posts
    4

    Default PIC Basic Code Understanding

    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

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Code:
    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.

    Code:
    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.
    Last edited by aratti; - 1st March 2010 at 09:39.
    All progress began with an idea

  3. #3
    Join Date
    Feb 2010
    Posts
    4


    Did you find this post helpful? Yes | No

    Default LCD config prob

    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

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Using the attached image and the following code will better explain Henriks post with regards to using other ports



    Code:
    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

    Code:
    LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 ' Initialize LCD
    Last edited by malc-c; - 1st March 2010 at 20:19.

  6. #6
    Join Date
    May 2009
    Location
    Montreal, QC, Canada
    Posts
    118


    Did you find this post helpful? Yes | No

    Default

    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

  7. #7


    Did you find this post helpful? Yes | No

    Default LCD initialization problem

    Quote Originally Posted by malc-c View Post
    Using the attached image and the following code will better explain Henriks post with regards to using other ports



    Code:
    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

    Code:
    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

  8. #8
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Occasionally I've experienced similar things after the initial re-programming. Resetting the PIC or power to my development board always works for me.

  9. #9
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    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.
    Charles Linquist

  10. #10


    Did you find this post helpful? Yes | No

    Default Serial Interrupt Problem

    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

  11. #11
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    shah_kunjan,
    Please post your code. We would be guessing without it.
    Dave
    Always wear safety glasses while programming.

  12. #12


    Did you find this post helpful? Yes | No

    Default Re:

    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

  13. #13
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default try attaching the files

    Quote Originally Posted by shah_kunjan View Post
    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

  14. #14


    Did you find this post helpful? Yes | No

    Default Re: Code for Serial Interrupt

    Quote Originally Posted by malc-c View Post
    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

  15. #15
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Code:
    hserin [dec x,WAIT(" "),dec y]
    Maybe???
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  2. pic Basic Pro 2.50a & debug statement
    By Phil Moore in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 17th March 2008, 09:41
  3. PIC BASIC or PIC BASIC PRO
    By kirkmans in forum USB
    Replies: 3
    Last Post: - 20th April 2007, 00:52
  4. Replies: 5
    Last Post: - 17th January 2006, 19:26
  5. Help with MPASM and PIC Basic
    By johngb in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 21st February 2003, 13:07

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts