View previous topic :: View next topic |
Author |
Message |
muhammadzvl
Joined: 03 Jun 2017 Posts: 8
|
Posted: Sat Jun 03, 2017 6:58 pm Post subject: EEPROM Problem |
|
|
hello, i'm using at8535.
i want to know why the uC can't read and write the bytes from EEPROM. This is the source code of my work.
Code: |
$regfile = "m8535.dat"
$crystal = 8000000
$baud = 9600
Config Portd.7 = Output
Config Portc.0 = Output
Config Portc.1 = Output
Config Portc.2 = Output
Config Portc.3 = Output
Config Portc.4 = Output
Portd.7 = 0
Portc.0 = 0
Portc.1 = 0
Portc.2 = 0
Portc.3 = 0
Portc.4 = 0
Dim I As Byte
$eeprom
Memory1:
Data 1,2
$data
Readeeprom I, Memory1
Do
I = Waitkey()
Writeeeprom I, Memory1
'3 lamp'
If I = "A" Then
Portd.7 = 1
Elseif I = "B" Then
Portd.7 = 0
Elseif I = "C" Then
Portc.0 = 1
Elseif I = "D" Then
Portc.0 = 0
Elseif I = "E" Then
Portc.1 = 1
Elseif I = "F" Then
Portc.1 = 0
'solenoid'
Elseif I = "G" Then
Portc.2 = 0
Elseif I = "H" Then
Portc.2 = 1
'rolling door'
Elseif I = "I" Then
Portc.3 = 1
Portc.4 = 1
Waitms 300
Portc.3 = 0
Portc.4 = 1
Wait 3
Portc.3 = 1
Portc.4 = 1
Elseif I = "I" Then
Portc.3 = 1
Portc.4 = 1
Waitms 300
Portc.3 = 1
Portc.4 = 0
Wait 3
Portc.3 = 1
Portc.4 = 1
End If
Waitms 100
Loop
End
|
When i turned off the supply for uC and turned on again, the EEPROM seems not working. I want to use the EEPROM to control the lamp.
What is wrong with the code, any help would be appreciated. Thanks
Best Regards,
Zulfikar
(BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Sat Jun 03, 2017 10:39 pm Post subject: |
|
|
For the At90S8535 you have to use $regfile = "8535DEF.dat"
If you using the AtMega8535 then $regfile = "m8535.dat" is correct. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
muhammadzvl
Joined: 03 Jun 2017 Posts: 8
|
Posted: Sun Jun 04, 2017 4:21 am Post subject: |
|
|
Evert wrote: | For the At90S8535 you have to use $regfile = "8535DEF.dat"
If you using the AtMega8535 then $regfile = "m8535.dat" is correct. |
i'm using AtMega8535, so the regfile is correct.
the problem is when i turned off the power for the uC and turn it on again, the last command (the bytes that i want to stored to EEPROM) for controlling the lamp is not working. it seems that the bytes didn't wrote to EEPROM.
for example: before the power is off, i'm sending the bytes via bluetooth to turn on the lamp, then i'm shutting down the power and the lamp is not turned on although i've turned it on.
what should i do? is the code is wrong?
any help would be appreciated
best regards,
Zulfikar |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Sun Jun 04, 2017 10:04 am Post subject: |
|
|
The waitkey in your do~loop is blocking the rest of the do loop because is waiting forever for input.
Better is to see every loop is there's input and then handle it.
Something like this
Code: |
$regfile = "m8535.dat"
$crystal = 8000000
$baud = 9600
Config Portd.7 = Output
Config Portc.0 = Output
Config Portc.1 = Output
Config Portc.2 = Output
Config Portc.3 = Output
Config Portc.4 = Output
Portd.7 = 0
Portc.0 = 0
Portc.1 = 0
Portc.2 = 0
Portc.3 = 0
Portc.4 = 0
Dim A As Byte
Dim I As Byte
Dim Memory1 As Byte
Memory1 = 1
Readeeprom I, Memory1
Do
A = Ischarwaiting()
If A = 1 Then 'we got something
I = Waitkey() 'get it
Writeeeprom I , Memory1
End If
'3 lamp'
If I = "A" Then
Portd.7 = 1
Elseif I = "B" Then
Portd.7 = 0
Elseif I = "C" Then
Portc.0 = 1
Elseif I = "D" Then
Portc.0 = 0
Elseif I = "E" Then
Portc.1 = 1
Elseif I = "F" Then
Portc.1 = 0
'solenoid'
Elseif I = "G" Then
Portc.2 = 0
Elseif I = "H" Then
Portc.2 = 1
'rolling door'
Elseif I = "I" Then
Portc.3 = 1
Portc.4 = 1
Waitms 300
Portc.3 = 0
Portc.4 = 1
Wait 3
Portc.3 = 1
Portc.4 = 1
Elseif I = "I" Then
Portc.3 = 1
Portc.4 = 1
Waitms 300
Portc.3 = 1
Portc.4 = 0
Wait 3
Portc.3 = 1
Portc.4 = 1
End If
Waitms 100
Loop
End
|
_________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
muhammadzvl
Joined: 03 Jun 2017 Posts: 8
|
|
Back to top |
|
|
|