微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 一个avr单片机的汇编程序,注意几个宏指令

一个avr单片机的汇编程序,注意几个宏指令

时间:12-02 来源:互联网 点击:
//晶振1MHz

//LED接PB0
//使用定时器1,1024分频,0.5秒中断一次,LED闪烁一次
程序如下:
.include "m8def.inc"

.equ led =0
.equ flash =$60

.org$0000//中断向量表

rest:
rjmp START
INT0addre: ; External Interrupt0 Vector Address
reti
INT1addre: ; External Interrupt1 Vector Address
reti
OC2addre : ; Output Compare2 Interrupt Vector Address
reti
OVF2addre: ; Overflow2 Interrupt Vector Address
reti
ICP1addre: ; Input Capture1 Interrupt Vector Address
reti
OC1Aaddre: ; Output Compare1A Interrupt Vector Address
reti
OC1Baddre: ; Output Compare1B Interrupt Vector Address
reti
OVF1addre: ; Overflow1 Interrupt Vector Address
rjmp Timer1_ovf
OVF0addre: ; Overflow0 Interrupt Vector Address
reti
SPIaddre : ; SPI Interrupt Vector Address
reti
URXCaddre: ; USART Receive Complete Interrupt Vector Address
reti
UDREaddre: ; USART Data Register Empty Interrupt Vector Address
reti
UTXCaddre: ; USART Transmit Complete Interrupt Vector Address
reti
ADCCaddre: ; ADC Interrupt Vector Address
reti
ERDYaddre: ; EEPROM Interrupt Vector Address
reti
ACIaddre : ; Analog Comparator Interrupt Vector Address
reti
TWIaddre : ; Irq.vectoraddress for Two-Wire Interface
reti
SPMaddre : ; SPM complete Interrupt Vector Address
reti
SPMRaddre: ; SPM complete Interrupt Vector Address
reti

.org$20

START:
ldi r16,low(ramend)//设置堆栈指针
out spl,r16
ldi r16,high(ramend)
out sph,r16
clr r16
sts flash,r16
sbi ddrb,led//PB0接led
rcall Timer1_ovf_init//调用初始化函数

MAIN:
lds r16,flash
sbrs r16,0 ;if theflagis set,jump onelow
rjmp main

ldi r16,0x01//LED取反
in r17,pinb
eor r17,r16
out portb,r17
clr r16
sts flash,r16

rjmp main

Timer1_ovf_init:
ldi r16,0xfe
out tcnt1h,r16
ldi r16,0x17
out tcnt1l,r16
in r16,timsk
sbr r16,1<2//开溢出中断
out timsk,r16
ldi r16,0x05
out tccr1b,r16//开定时器
sei //开中断
ret

Timer1_ovf://定时器2定时0.5S
in r16,sreg
push r16//保存SREG入栈
ldi r16,0xfe
out tcnt1h,r16
ldi r16,0x17
out tcnt1l,r16
clr r16
sbrr16,1<0//设置标志
stsflash,r16
pop r16
out sreg,r16
reti//中断返回

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top