Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

EEPROM Problem

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions
View previous topic :: View next topic  
Author Message
muhammadzvl

Bascom Member



Joined: 03 Jun 2017
Posts: 8

PostPosted: Sat Jun 03, 2017 6:58 pm    Post subject: EEPROM Problem Reply with quote

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
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2108

netherlands.gif
PostPosted: Sat Jun 03, 2017 10:39 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
muhammadzvl

Bascom Member



Joined: 03 Jun 2017
Posts: 8

PostPosted: Sun Jun 04, 2017 4:21 am    Post subject: Reply with quote

Evert Smile 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
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2108

netherlands.gif
PostPosted: Sun Jun 04, 2017 10:04 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
muhammadzvl

Bascom Member



Joined: 03 Jun 2017
Posts: 8

PostPosted: Sun Jun 04, 2017 12:21 pm    Post subject: Reply with quote

Evert Smile wrote:
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
 

Oh dear- work like a charm! thank you mate!
(edit) that source code is just worked with 1 lamp, so how if i controlled more than one, for example 3 lamps? just modifying the A?

one last question, how if i want to set the PWM for the "rolling door"?
i'm using DC motor, 12V supply.
Best Regards,
Zulfikar
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum