Continue to Site

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.

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

AT90S2313 code help

Status
Not open for further replies.

eugene2021

New Member
anyone use avrs i found some code that does what i need but only will turn on first relay.need help adding code for more.can post code for single relay. this is for at90s2313
 
would like to turn on/off relays ,have been able to turn on/off relays w/code . do not know how to get 7 more relays to go on/off independently .

can post code and data i send to turn on/off relays
 
here is code
.equ BAUD =24
.def temp =R16
.def temp2 =R17
.def EEard =R18
.def byte1 =R19
.def byte2 =R20

.include "2313def.inc"

reset:
ldi temp,RAMEND
out SPL,temp

ldi temp,0b11111111
out DDRB,temp
ldi temp, BAUD
out UBRR, temp
ldi temp,0b00011000
out UCR,temp
ldi byte1,','
rcall transmit
rcall receive
rcall transmit
rcall delay
mov byte2,byte1
rcall receive
rcall transmit
rcall delay
cpi byte2,'n'
breq Check_2nd_char
rjmp NextCheck
Check_2nd_char:
cpi byte1,'1'
brne start
sbi portb,0
rjmp start
NextCheck:
cpi byte2,'w'
brne start
cpi byte1,'1'
brne start
cbi portb,0
rjmp start
transmit:
sbis USR,UDRE
rjmp transmit
out UDR,byte1
ret
receive:
sbis USR,RXC
rjmp receive
in byte1,UDR
ret
delay:
ldi temp2,10
delay_:
ldi temp,255
delay1:
dec temp
brne delay1
dec temp2
brne delay_
ret

as code stats i send n# to chip and that # relay would turn on
send w# and that relay would turn off
 
I am sure there are many like me that would like to help, but don't want to go through all of your code. Can you either insert some text description of what each part does and/or isolate the problem section.
 
Now, mind you, I don't normally program in assembly. And as I understand your problem, you have this working for one relay, and want to add more. Here is a try.

cpi byte2,'n' ;check to see if to turn on relay
breq Check_2nd_char ; turn on relay section
rjmp NextCheck ; turn off relay section

Check_2nd_char: ;turn on relay section
cpi byte1,'1' ;check for relay one
brne C2c2 ;no? check next
sbi portb,0 ;yes, set output
rjmp start ;go back to start of program

C2c2:
cpi byte1,'2' ;check for relay two
brne C2c3 ;no? check next
sbi portb,1 ;yes, set output
rjmp start ; go back to start of program

C2c3:
.
.
.

C2c8:
cpi byte1,'2' ;check for relay eight
brne start ;no? go back to start of program
sbi portb,7 ;yes, set output
rjmp start ; go back to start of program

do likewise for the turn off section

NextCheck:
cpi byte2,'w'
brne start

cpi byte1,'1'
brne Nc2 ;check next
cbi portb,0
rjmp start

Nc2:
cpi byte1,'2'
brne Nc3
cbi portb,1
rjmp start

Nc3:
.
.
.

Nc8:
cpi byte1,'8'
brne start
cbi portb,7
rjmp start

Well, anyway, that's my stab at it. There might be typos. BTW, this program isn't particularly "robust" as there are plenty of opportunities to get stuck in a loop, but if this is all the chip is doing, it might be fine.

j.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top