<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        一個avr單片機的匯編程序,注意幾個宏指令

        作者:佚名   來源:本站原創   點擊數:  更新時間:2014年03月25日   【字體:

         //晶振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. vector address 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 the flag is set,jump one low
        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
        sbr r16,1<<0//設置標志
        sts flash,r16
        pop r16
        out sreg,r16
        reti//中斷返回

        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮