Full Version : STK500 Novice Project with PushButton (ASM)
avr >>BEGINNER PROJECTS >>STK500 Novice Project with PushButton (ASM)


AVR_Admin- 04-17-2006
newbie project for normaly open pushbutton.

Hardware:
STK500

Compiler: AVR Studio 4

Device: ATTiny15

Input: Port B -> pin 2 & 3 (From pushbutton)

Output: Port B -> pin 0 & 1 (To Led)

Description:

The ATTiny15 has active low at its Port B. STK500 supplied normaly open pushbutton. The project is to maintaint user input by manifesting it to the led display. If the user push the same button again, the led will goes off.


CODE

;My Very First AVR Project

.include "tn15def.inc" ;Includes the 8515 definitions file
;.include "tn2313def.inc" ;Includes the 8515 definitions file

.def Input = R16         ;Gives "Defines" Register R16 the name Temp
.def Displayer = R17
.def Const1 = R18  
.def Delay1 = R19
.def Delay2 = R20

.org 0x0000            ;Places the following code from address 0x0000
  rjmp  RESET         ;Take a Relative Jump to the RESET Label

RESET:                 ;Reset Label
  ldi Input, 0x03     ;Store 255 in R16 (Since we have defined R16 = Temp)
  out DDRB, Input     ;Setting the value of DDRD to WRITE.
  clr Displayer ;Initialized to zeros
  ser Const1  ;Set to high
  ser Delay1
  ldi Delay2, 0xcf
  out PORTB,Delay1 ;Turn the led off

Loop:                  ;Loop Label
  in   Input,PINB      ;Normally open push-button.
  eor  Input,Const1
  lsr  Input
  lsr  Input
  andi Input,0x03 ;Took Input bit as high bit
  cpi  Input,0x00
  breq Loop
  eor  Displayer,Input
Loop1:    ;Delay so you had time to get ur finger off
  dec  Delay1
  brne Loop1
  dec  Delay2
  brne Loop1
  com  Displayer
  out  PORTB,Displayer
  com  Displayer ;return the value again
  ldi  Delay1,0xFF
  ldi  Delay2,0xcf
  rjmp Loop           ;Take a relative jump to the Loop label




Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.