⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap6.asm

📁 摩托罗拉Mc6805利程
💻 ASM
📖 第 1 页 / 共 2 页
字号:
; Chapter 6 6808 assembly language programs; Jonathan W. Valvano; This software accompanies the book,; Real Time Embedded Systems published by Brooks Cole;; Program 6.1. Initialization of a periodic interrupt using input capture and an external clock.; MC68HC05C8;external signal to TCAPTIME rmb  2      ;every 1 msInit sei         ;make atomic     lda #$80     sta TCR     ;arm, rising     lda TSR     ; clear ICF     lda ISR+1   ; read low byte     clr TIME     clr TIME+1     cli         ;enable     rts; Program 6.2. Periodic interrupt using input capture and an external clock.; MC68HC05C8ICHan  lda TSR ;expect 1XXX0000[3]                          and #$8F                [2]       cmp #$80                [2]       beq  ClkHan             [3]       swiClkHan lda ISR+1 ; Acknowledge [4]                                lda TIME+1              [3]                                                   inca                    [3]                                                    sta TIME+1              [4]       lda TIME                [3]       adc #0                  [2]       sta TIME                [4]                                               rti       org  $1FF8       fdb  ICHan;  Program 6.4. Initialization for period measurement.; MC68HC05C8;external signal to TCAPPeriod rmb  2  ;units 500 nsFirst  rmb  2  ;TCNT at first edgeDone   rmb  1  ;set each risingInit sei         ;make atomic     lda #$80     sta TCR     ;arm,rising     lda TSR     ;clear ICF     lda ISR+1   ;read low byte     lda TCNT     sta First     lda TCNT+1     sta First+1     clr Done     cli         ;enable     rts;  Program 6.5. ISR for period measurement.; MC68HC05C8ICHan  lda TSR ; Acknowledge   [3]                          lda ICR+1               [3]                                                   sub First+1             [3]                                                    sta Period+1            [4]       lda ICR                 [3]       sbc First               [3]       sta Period              [4]                                               lda ICR+1               [3]                                                   sta First+1             [4]       lda ICR                 [3]       sta First               [4]                                               lda #$FF                [2]       sta Done                [4]                                               rti                     [6]       org  $1FF8       fdb  ICHan;  Program 6.7. Assembly initialization for 32-bit period measurement.; MC68HC05C8;external signal to TCAPPeriod rmb  4  ;units 500 nsFirst  rmb  2  ;TCNT at first edgeCount  rmb  2  ;number of TOF'sMode   rmb  1 Init sei         ;make atomic     lda #$A0    ;arm TOF, ICF     sta TCR     ;ICF rising     lda TSR     ;part of clear      lda ISR+1   ;clear ICF     lda TCNT+1  ;clear TOF     clr Mode     cli         ;enable     rts;  Program 6.8. Assembly input capture ISR for 32-bit period measurement.; MC68HC05C8TimHan lda TSR   ;poll for ICF       bpl ChkTOF                    ICHan  lda Mode       bne Mode1   ;skip if mode=1Mode0  lda ICR1       sta First                                               lda ICR+1   ;ack ICF       sta First+1        clr Count       clr Count+1       inc Mode     ;change 0 to 1       lda ICR       bmi ChkTOF ;skip if ICR:15       lda TSR       and #$40   ;check TOF       beq ChkTOF ;skip if not TOF       lda TCNT+1 ;TOF and ICF       bra TOFok  ;TOF was firstMode1  lda ICR       bmi skip  ;skip if ICR:15       lda TSR       and #$40   ;check TOF       beq skip   ;skip if not TOF       lda Count+1 ;TOF and ICF       add #1     ;TOF was first       sta Count+1       lda Count       adc #0       sta Count ;TOF is countedskip   inc Mode  ;change 1 to 2       lda ICR+1 ;ack ICF                                                   sub First+1                                                    sta Period+3 ;bottom 8 bits       lda ICR       sbc First          sta Period+2                                                 lda Count+1                                                    sbc #0                                                    sta Period+1        lda Count         sbc #0          sta Period  ;top 16 bits       clr TCR   ;disarm TOF,ICF       rti       org  $1FF8       fdb  TimHan ;TOF and ICF;  Program 6.9. Assembly timer overflow ISR for 32-bit period measurement.; MC68HC05C8ChkTOF lda TSR       and #$40   ;check TOF       beq TOFok  ;skip if not TOF       lda Count+1       add #1       sta Count+1       lda Count       adc #0       sta Count       bcc TOFok       lda #2       sta Mode ;error no first       lda #$FF       sta Period       sta Period+1       sta Period+2       sta Period+3       clr TCR   ;disarm TOF,ICFTOFok  rti;  Program 6.11. Ritual written in assembly language for the pulse width measurement.; MC68HC05C8; B=PB7,  Q=TCAP, set global R Init bset 7,DDRB  ;PB7 output     rts;  Program 6.12. Assembly language pulse width measurement.; MC68HC05C8Rising rmb 2 R    rmb 2     ;resistance in Kohm Meas lda #$00  ;disarm TOF, ICF     sta TCR   ;ICF rising     lda TSR     lda ICR+1 ;clear ICF     bclr 7,PORTB  ;B=0     bset 7,PORTB  ;trigger LS123First brclr 7,TSR,First ;wait      lda #$02       sta TCR   ;ICF falling     lda TSR     lda ICR+1 ;clear ICF     lda TCH2     sta Rising     lda TCH2+1     sta Rising+1Secnd brclr 7,TSR,Secnd ;wait     lda ICR+1     sub Rising+1     sta R+1   ;R=ICR-Rising     lda ICR     sbc Rising     sta R     lda R+1     sub #232  ;1000=3*256+232     sta R+1   ;R=R-1000     lda R     sbc #3     sta R     rts;  Program 6.14. Assembly language pulse width measurement.; MC68HC05C8;external signal to TCAPPW     rmb  2  ;units 500 nsRising rmb  2  ;TCNT at rising Done   rmb  1  ;set each fallInit sei         ;make atomic     lda #$80     sta TCR     ;arm,rising     lda TSR     ;clear ICF     lda ISR+1   ;read low byte     clr Done     cli         ;enable     rtsICHan  lda TSR ; Acknowledge       lda TCR ;which one?       and #$02 ;IEDG       bne fallrise   lda ICR+1                                                   sta Rising+1       lda ICR       sta Rising       bra ICrti fall   lda ICR+1                                                       sub Rising+1                                                        sta PW+1          lda ICR            sbc Rising       sta PW                                                      dec Done  ;set to $FF                                           ICrti  rti        org  $1FF8       fdb  ICHan;  Program 6.16. Assembly language pulse width measurement using two input captures.; MC68HC05C8; not available; because only one input capture;  Program 6.18. 6808 assembly language pulse-width-modulated output.;external signal to PTE7/TCH3Init ldhx #9999  generate a 100 Hz square wave, 10000 cycles 1祍 each     sthx TMOD   when TCNT=TMOD, then TOF is set and TCNT=0 again     mov  #$03,TSC no TOF interrupts, 1祍 counting     mov  #$1A,TSC3  ;       6=0    no interrupts; 5,4,3,2=0110 clear on output compare;       1=1    TOV3 toggle when TOF set (will set to one);       0=0    CH3MAX off, regular PWM     ldhx #5000 50% duty cycle     sthx TCH3     rts;  Program 6.19. Assembly language ritual for periodic interrupt using output compare.; MC68HC05C8TIME rmb  2      ;every 1 msInit sei         ;make atomic     mov #$40,TCR  ;arm OCF     lda TSR     ;clear OCF     ldx TCNT    ;latches LSB too     lda TCNT+1  ;read low byte     add #$D0    ;$07D0=2000     sta OCR+1     txa     adc #$07     sta OCR     ; first in 1ms     clr TIME     clr TIME+1     cli         ;enable     rts;  Program 6.20. Assembly language ISR for periodic interrupt using output compare.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -