1. 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.
    Dismiss Notice

pic programming.................. what next?

Discussion in 'Microcontrollers' started by tama182, Jan 4, 2006.

  1. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,203
    Likes:
    640
    Location:
    Derbyshire, UK
    You're thinking too deeply! - the controller on the LCD module has it's own memory, and stores the first nibble internally 'somewhere', there's no reason to know where, and probably no way to find out.

    As far as I'm concerned (and you!) the LCD module is a black box, there's no need to know what happens inside it, as long as you know it's response to external actions.
     
  2. tama182

    tama182 New Member

    Joined:
    Jan 4, 2006
    Messages:
    57
    Likes:
    0
    No im not thinking too deeply !!, i dont understand the program you've written,

    youve sent a load of letters to the LCD, where each letter takes two passes, as a letter is 8 bit and it set up to do only 4 bit,

    heres how im understanding it, and i dont see how it works

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

    Send H to LCD (01001000)

    send 00000100 to Porta (first half of H)

    Porta=00000100

    send 00001000 to Porta (second half of H)

    Porta now becomes = 00001000

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

    so if porta is now 00001000 (second half of H), how does it remember the first half because that has been overwritten
     
  3. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,203
    Likes:
    640
    Location:
    Derbyshire, UK
    As I said above, it's stored internally in the LCD module.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. tama182

    tama182 New Member

    Joined:
    Jan 4, 2006
    Messages:
    57
    Likes:
    0

    so then once it starts E, is H also stored? so that in the end the LCD stores the boths words?
     
  6. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,203
    Likes:
    640
    Location:
    Derbyshire, UK
    They don't provide you all the internal details of the LCD controller, only the details you need to use it - certainly all text you send is stored in the display buffer, until overwritten or cleared. Command instructions are not stored in the display buffer though, but may be stored elsewhere?.
     
  7. tama182

    tama182 New Member

    Joined:
    Jan 4, 2006
    Messages:
    57
    Likes:
    0
    i just noticed this, i understand that you have given porta the name LCD_PORT, and that you have also given some of the bits in porta names as well, to make it easy to read, ie LCD_RS and LCD_RW,

    Code (text):

    LCD_PORT    Equ PORTA
    LCD_TRIS    Equ TRISA
    LCD_RS      Equ 0x04       
    LCD_RW      Equ 0x06
    LCD_E       Equ 0x07
     
    but when you write
    , how come it doesn't try to give register 4 (fsr) the name of lcd_rs, how does it know that you mean the bits of register 5 (porta)
     
  8. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,203
    Likes:
    640
    Location:
    Derbyshire, UK
    The equates and includes are simply text substitution items - that line "LCD_RS Equ 0x04" simply instructs the assembler to replace every occurance of 'LCD_RS' with '0x04' - so it in no way affects anything else.
     
  9. tama182

    tama182 New Member

    Joined:
    Jan 4, 2006
    Messages:
    57
    Likes:
    0
    yes i understand that, but is'nt the hex number 0x04 the location of register fsr,

    Code (text):

    INDF                         EQU     H'0000'
    TMR0                         EQU     H'0001'
    PCL                          EQU     H'0002'
    STATUS                       EQU     H'0003'
    FSR                          EQU     H'0004'
    PORTA                        EQU     H'0005'
    PORTB                        EQU     H'0006'
    PCLATH                       EQU     H'000A'
    INTCON                       EQU     H'000B'
    PIR1                         EQU     H'000C'
    TMR1L                        EQU     H'000E'
    TMR1H                        EQU     H'000F'
    T1CON                        EQU     H'0010'
    TMR2                         EQU     H'0011'
    T2CON                        EQU     H'0012'
    CCPR1L                       EQU     H'0015'
    CCPR1H                       EQU     H'0016'
    CCP1CON                      EQU     H'0017'
    RCSTA                        EQU     H'0018'
    TXREG                        EQU     H'0019'
    RCREG                        EQU     H'001A'
    CMCON                        EQU     H'001F'
     
  10. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    But "4" is simply a value which is not to mean just a register address. You asked the question, "What is the address of FSR?", the answer is four.

    Depending on the circumstances, many other things can have the value of four.

    Sides_of_a_square EQU 4
    Legs_of_a_cow EQU 4
    ....
     
  11. tama182

    tama182 New Member

    Joined:
    Jan 4, 2006
    Messages:
    57
    Likes:
    0
    ok, let me just ask this first, going from the 628 text,

    when the pic master wrote his code, he put at the top

    now going back to the 628 test its says that PORTA EQU H'0005',

    so Nigel could have witten this instead, which is the same thing

    is that correct?
     
  12. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,203
    Likes:
    640
    Location:
    Derbyshire, UK
    Yes it is, but the whole point of using the includes is that you don't even need to know what the register addresses are - I'm assuming that you are correct that PortA is at address 0x05?.

    The example above is also designed to make it easy to change, you simply change PortA and TRISA to PortB and TRISB, which is easier than remembering obscure numbers. Also, when you read the lines it's obvious what it means - the numbers mean very little!.
     
  13. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    Code (text):
    LCD_PORT    Equ 0x05 (=H'0005')
    LCD_TRIS    Equ TRISA
    LCD_RS      Equ 0x04       
    LCD_RW      Equ 0x06
    LCD_E       Equ 0x07
     
    The code generated is the same but there is a difference. Say if one wants to use PORTB for the LCD instead, one just change LCD_PORT Equ into PORTB.

    While in your case you have to lookup the register address for PORTB and manually input 0x06 into the definition.
     
  14. tama182

    tama182 New Member

    Joined:
    Jan 4, 2006
    Messages:
    57
    Likes:
    0
    yep hang on though, thats not the bit that i dont understand, heres the bit i dont understand,

    LCD_PORT Equ 0x05 (=H'0005')
    LCD_TRIS Equ TRISA
    LCD_RS Equ 0x04
    LCD_RW Equ 0x06
    LCD_E Equ 0x07


    you said that the above would work, in that lcd_port equals porta, and

    LCD_RS Equ 0x04
    LCD_RW Equ 0x06
    LCD_E Equ 0x07

    all are bits in porta,

    but howcome writing LCD_PORT Equ 0x05, signifies a regisiter, and LCD_RS Equ 0x04 signifies a bit in a register,

    ok say i wanted to call the register FSR, the name LCD_RS, then i would write LCD_RS Equ 0x04, (FSR is a at h'0x04', look at table in previous posts)

    but thats the same code a giving bit 4 in the porta register a name, now can you see where i dont get it?
     
  15. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,007
    Likes:
    316
    Location:
    Brisbane Australia
    I'll try and describe it a different way.
    Code (text):

       bsf PORTA,legs_on_a_table
       bsf PORTA,FSR
       bsf PORTA,4
     
    The above are all the same instruction.
    It is where the number is used that defines what it is.

    An Alternative
    Code (text):

      movlw FSR
      movlw legs_on_a_table
     
    The above will put 4 into W

    Also
    Code (text):

      movfw FSR
      movfw legs_on_a_table
     
    The above will get the contents of location 4 and put it in W.

    Mike.
     
  16. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    4 by itself is meanlingless. If your software requires an address, then the 4 becomes an address.

    So MOVWF LCD_PORT would expect and require 0x5 to mean an actual port address.

    If the software requires an reference to a particular bit, then 4 become the position of the bit.

    BSF LCD_PORT, LCD_RS would mean the 4th bit of address 5.

    Now if you write:

    MOVWF LCD_RS ; <<<<< mistake, LCD_RS is not a port address

    You are sending the content of W to address 4, which is a big mistake.
     
  17. tama182

    tama182 New Member

    Joined:
    Jan 4, 2006
    Messages:
    57
    Likes:
    0
    ahh get it.......when nigel was writing

    LCD_RS Equ 0x04

    i was thinking that lcd_rs was only bit 4 of porta, and that no matter where you wrote lcd-rs, it would refer to bit 4 of porta,

    but lcd-rs = 4, and just 4


    ah so........ ((lcd-rs x lcd-rs)/(lcd-rs x lcd-rs))x(lcd-rs) = lcd- rs :lol:
     
  18. tama182

    tama182 New Member

    Joined:
    Jan 4, 2006
    Messages:
    57
    Likes:
    0
    im using a picdem plus 2 and an icd 2, to program my 16f628, i gather that the icd 2 is simply there to just debug, so can i simply plug the pic dem straight into my computer?
     

Share This Page