1 | Using LEDs and Switches
|
2 | Connect PORTB to LEDS and PORTD to SWITCHES.
|
3 | LEDs will operate differently depending on what switch is pressed.
|
4 | Tip: Copy the code from this document into AVR Studio.
|
5 | ;***** STK500 LEDS and SWITCH demonstration
|
6 | ;Example Applications
|
7 | ;9-2 AVR STK500 User Guide 1925CAVR3/03
|
8 | no list
|
9 | .include "m8def.inc";.include 8515def.inc
|
10 | list
|
11 | .def Temp =r16 ; Temporary register
|
12 | .def Delay =r17 ; Delay variable 1
|
13 | .def Delay2 =r18 ; Delay variable 2
|
14 | ;***** Initialization
|
15 | RESET:
|
16 | ldi Temp, 0xFF
|
17 | out DDRB,Temp ; Set PORTB to output
|
18 | ;**** Test input/output
|
19 | LOOP:
|
20 | out PORTB,temp ; Update LEDS
|
21 | sbis PIND,0x00 ; If (Port D, pin0 == 0)
|
22 | inc Temp ; then count LEDS one down
|
23 | sbis PIND,0x01 ; If (Port D, pin1 == 0)
|
24 | dec Temp ; then count LEDS one up
|
25 | sbis PIND,0x02 ; If (Port D, pin2 == 0)
|
26 | ror Temp ; then rotate LEDS one right
|
27 | sbis PIND,0x03 ; If (Port D, pin3 == 0)
|
28 | rol Temp ; then rotate LEDS one left
|
29 | sbis PIND,0x04 ; If (Port D, pin4 == 0)
|
30 | com Temp ; then invert all LEDS
|
31 | sbis PIND,0x05 ; If (Port D, pin5 == 0)
|
32 | neg Temp ; then invert all LEDS and add 1
|
33 | sbis PIND,0x06 ; If (Port D, pin6 == 0)
|
34 | swap Temp ; then swap nibbles of LEDS
|
35 | ;**** Now wait a while to make LED changes visible.
|
36 | DLY:
|
37 | dec Delay
|
38 | brne DLY
|
39 | dec Delay2
|
40 | brne DLY
|
41 | rjmp LOOP ; Repeat loop forever
|