Test Program for AVR-IO

I had some problems getting the AVR-IO up and doing something. Here is a sample program to help the next person.

For AVRSTUDIO4

;***** AVR-IO RELAY and SWITCH demonstration

;***** Setup with switch and small voltage across inputs

;***** 12-7-03 RW

.include “2313def.inc”

.def Delay1 = r17 ; Delay variable 1

.def Delay2 = r18 ; Delay variable 2

.def Temp = r19 ; Temporary register

.def Led = r20 ; Led9 store

.def Pin1 = r21 ; Input 1 state - pin PD2

.def Pin2 = r22 ; Input 2 state - pin PD3 (jmp on 2,3)

.def Pin3 = r23 ; Input 3 state - pin PD5

.def Pin4 = r24 ; Input 4 state - pin PD6 - Bottom away from RS232

;*** Other Notes

;*** Outputs:

;*** PB0 - Relay 4 - bottom away from RS232

;*** PB1 - Relay 3

;*** PB2 - Relay 2

;*** PB3 - Relay 1

;*** PB4 - LED9

;***

;*** Initialization

RESET:

CLR r17 ; Clear Register r17

CLR r18 ; Clear Register r18

CLR r19 ; Clear Register r19

CLR r20 ; Clear Register r20

CLR r21 ; Clear Register r21

CLR r22 ; Clear Register r22

CLR r23 ; Clear Register r23

CLR r24 ; Clear Register r24

SBR Temp, 16 ; Set temp to 00010000

;*** LED9 goes on when dropped from 1 to 0

;*** Relays go on when changed from 0 to 1

OUT DDRB,Temp ; Set PORTB to output turn relays off

;**** Test input/output

LOOP:

OUT PORTB,Temp ; Update LEDS

;*** Ceck switches

SBIS PIND,0x02 ; If (Port D, pin2 == 0) switch open

RJMP in1

RJMP relay1on

IN1RET:

SBIS PIND,0x03 ; If (Port D, pin3 == 0) switch open

RJMP in2

RJMP relay2on

IN2RET:

SBIS PIND,0x05 ; If (Port D, pin5 == 0) switch open

RJMP in3

RJMP relay3on

IN3RET:

SBIS PIND,0x06 ; If (Port D, pin6 == 0) switch open

RJMP in4

RJMP relay4on

IN4RET:

;*** Turn on LED9 if not already on

SBRC temp, 4

RJMP led

;**** Now wait a while to make LED changes visible.

DELAY:

DEC Delay1

BRNE DELAY

DEC Delay2

BRNE DELAY

RJMP LOOP ; Repeat loop forever

;**** LED9

LED:

CLR led

SBR led, 16

SBRC temp, 4

SUB temp, led

RJMP DELAY

;**** Button 1

in1: ; switch 1 closed turn on relay 1

CLR pin1

SBR pin1, 8

SBRS temp, 3

ADD temp, pin1

RJMP in1ret

relay1on: ; switch 1 open turn off relay 1

CLR pin1

SBR pin1, 8

SBRC temp, 3

SUB temp, pin1

RJMP in1ret

;**** Button 2

in2: ; switch 2 closed turn on relay 2

CLR pin2

SBR pin2, 4

SBRS temp, 2

ADD temp, pin2

RJMP in2ret

relay2on: ; switch 2 open turn off relay 2

CLR pin2

SBR pin2, 4

SBRC temp, 2

SUB temp, pin2

RJMP in2ret

;**** Button 3

in3: ; switch 3 closed turn on relay 3

CLR pin3

SBR pin3, 2

SBRS temp, 1

ADD temp, pin3

RJMP in3ret

relay3on: ; switch 3 open turn off relay 3

CLR pin3

SBR pin3, 2

SBRC temp, 1

SUB temp, pin3

RJMP in3ret

;**** Button 4

in4: ; switch 4 closed turn on relay 4

CLR pin4

SBR pin4, 1

SBRS temp, 0

ADD temp, pin4

RJMP in4ret

relay4on: ; switch 4 open turn off relay 4

CLR pin4

SBR pin4, 1

SBRC temp, 0

SUB temp, pin4

RJMP in4ret

Hey! Thanks! We appreciate helper code!