Strona Domowa

Dawida Urbanskiego

- Dział: arts -

< Go Back to List

elektronika/avr

Progamowanie mikrokontrolerów rodziny AVR

autor: Dawid napiano:2009-11-09

Pierwszy projekt (źródło)

Kod napisany w asemblerze. ;################################
;## 10.9.2009 ##
;################################
;## Dawid Urbańki ##
;################################
;## opis:
;##Zapala i gasi piny portu D
;PORTD_0 - led1
;PORTD_1 - led2
;PORTD_2 - led3
;PORTD_3 - led4
;##############################
.nolist
.include "tn2313def.inc"
.list
.listmac


.def acc = r16
.equ del_s = 4 ;del_s = 4 -> 1s

.cseg
.org 0

;inicjacja
cli ;
ldi r16,LOW(RAMEND) ;inicjacja stosu...
out SPL,r16 ;...progamowego

ldi r16,0xFF ;
out DDRD,r16 ; PORTD - wyjscie w stanie wysokim

;##############################
;## pętla gówna programu
Main:

;wyłącz portD
rcall PORTD_OFF


;wł LED1 na 1s
rcall PORTD_0_ON
;czekaj
ldi r19,4
rcall Delay
rcall PORTD_0_OFF

;wł lED4 na 1s
rcall PORTD_3_ON
;czekaj
ldi r19,4
rcall Delay
rcall PORTD_3_OFF

;------------------------------
;wł LED2 na 2s
rcall PORTD_1_ON
;czekaj
ldi r19,8
rcall Delay
rcall PORTD_1_OFF
;wł LED 3 na 2s
rcall PORTD_2_ON
;czekaj
ldi r19,8
rcall Delay
rcall PORTD_2_OFF


;wł LED 2,3 na 1s
rcall PORTD_2_ON
rcall PORTD_3_ON
;czekaj
ldi r19,4
rcall Delay
rcall PORTD_2_OFF
rcall PORTD_3_OFF
;------------------------------


rjmp Main ; powrot do petli
;##############################

;##############################
;## PORTD led swieci
PORTD_ON:
ldi r16,0xFF
out PORTD,r16 ; PORTD - wyjscie w stanie wysokim
ret

PORTD_0_ON:
sbi PORTD,0
ret
PORTD_1_ON:
sbi PORTD,1
ret
PORTD_2_ON:
sbi PORTD,2
ret
PORTd_3_ON:
sbi PORTD,3
ret
PORTD_4_ON:
sbi PORTD,4
ret
PORTD_5_ON:
sbi PORTD,5
ret
;#############################
;## PORTD led NIE swieci
PORTD_OFF:
ldi r16,0x00
out PORTD,r16 ; PORTD - wyjscie w stanie wysokim
ret

PORTD_0_OFF:
cbi PORTD,0
ret
PORTD_1_OFF:
cbi PORTD,1
ret
PORTD_2_OFF:
cbi PORTD,2
ret
PORTd_3_OFF:
cbi PORTD,3
ret
PORTD_4_OFF:
cbi PORTD,4
ret
PORTD_5_OFF:
cbi PORTD,5
ret

;########################################
;## opóźnienie
;## ustawiamy rejestrem 19 'r19'
Delay:
ldi r19,del_s
clr r1
clr r2

delay_loop:
dec r1
brne delay_loop
dec r2
brne delay_loop
dec r19
brne delay_loop
ret

.exit
;-----------------------------------------

Teraz musimy ten kod przerzucić na nasz mikrokontroler.

  • Otwieramy AVR Studio tworzymy nowy projetk w języku asembler.
  • Wklejamy powyższy kod. kompikujemy F7.
  • Uruchamiamy eXtreme Burner - AVR
  • otwieramy 'twoja_nazwa_projektu.hex'
  • Wgrywamy na mikrokontroler klikając na guzik 'write all'

strony [1] [2] [3] [4] [5] [6] [7] [8]
czytaj dalej...

Back to List


komentarze

  • gość
    Warning: strftime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/dawidurb2/domains/dawidurbanski.pl/public_html/engine/framework/smarty/libs/plugins/modifier.date_format.php on line 53
    Jul 6, 2013
    Tu podaj treść
  • gość
    Warning: strftime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/dawidurb2/domains/dawidurbanski.pl/public_html/engine/framework/smarty/libs/plugins/modifier.date_format.php on line 53
    Nov 23, 2013
    Tu podaj treść

dodaj komntarz

tools

qrcode:
qrcode
-

code by: Dawid Urbanski

Copyright © by Dawid Urbanski 2010 - 2020