//晶振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//中止回来