• 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.

Function Read and Write EEPROM

Status
Not open for further replies.

Winch

Member
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:
'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
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
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:
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
 

Winch

Member
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.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top