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

Function Read and Write EEPROM

Discussion in 'Oshonsoft' started by Winch, Feb 4, 2015.

  1. Winch

    Winch New Member

    Joined:
    Sep 5, 2014
    Messages:
    24
    Likes:
    0
    Can someone provide me with some additional information about the function Read and Write.
    I have some problems with the processing of the code in the program.

    Why do these simple code below not work properly?

    Code (text):
    'DEVICE PIC16F628A

    Define CONFIG = 0x3f50

    Define CLOCK_FREQUENCY = 4

    AllDigital  'alle ports digital

    'Poortnamen
    Symbol led = PORTA.1
    Symbol s1 = PORTB.0

    '76543210
    PORTA = %00000000
    TRISA = %11111011
    TRISB = %11111111

    OPTION_REG.7 = 0

    Read 0, led

    main:
    While s1 = 0
    Wend
    WaitMs 10

    Toggle led
    Write 0, led

    While s1 = 1
    Wend
    WaitMs 10

    Goto main

    End
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    ONLINE
    What doesn't work?? Eprom write or read??
     
  3. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    ONLINE
    Ok never mind.... You can't compile it..

    led is defined as a bit.... Read and write require bytes.. Use a port buffer to access the bits..

    Code (basic):


    Define CONFIG = 0x3f50

    Define CLOCK_FREQUENCY = 4

    AllDigital  'alle ports digital

    'Poortnamen
    Symbol led = PORTA.1
    Symbol s1 = PORTB.0

    '76543210
    PORTA = %00000000
    TRISA = %11111011
    TRISB = %11111111

    Dim portbuf As Byte
    OPTION_REG.7 = 0

    Read 0, portbuf
    led = portbuf.1

    main:
    While s1 = 0
    Wend
    WaitMs 10

    Toggle led
    portbuf.1 = led
    Write 0, portbuf

    While s1 = 1
    Wend
    WaitMs 10

    Goto main

    End
     
     
  4. dave

    Dave New Member

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


     
  5. Winch

    Winch New Member

    Joined:
    Sep 5, 2014
    Messages:
    24
    Likes:
    0

    Oke, I did try this.
    It looks to work. But I am not sure?

    The intention was to make the LED high (make the output high) write to the "0" address of the EEprom en read it again out with the result the LED high output. And visa versa.
    Now it looks like to work just the other way the LED is high if you take the power supply of and back again then the LED is Low. And visa versa.

    What I don't understand in this code is you write "portbuf.1" what is that ".1" exactly doing?
    I use this solution earlier but without that ".1" now I am wondering what does that?

    Please explain this.
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    ONLINE
    Accessing bits within a byte,, The dot operator can achieve this...

    portbuf.1 accesses bit 1 within the byte..
    byte.png
     
  7. Winch

    Winch New Member

    Joined:
    Sep 5, 2014
    Messages:
    24
    Likes:
    0
    I suppose that I can also use bit 2 or 3? With the same result.
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    ONLINE
    Yes...
    The dot operator can also be used with word sized variables to access hi byte and low byte.

    Code (basic):

    dim x as word
    dim y as byte

    y = x.HB
     
     
  9. Winch

    Winch New Member

    Joined:
    Sep 5, 2014
    Messages:
    24
    Likes:
    0
    Thanks for the explanation!
     

Share This Page