📄 chap6.asm
字号:
; 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.; MC68HC708XL36;external signal to PTE7/TCH3TIME rmb 2 ;every 1 msInit sei ;make atomic lda TSC3 mov #$44,TSC3 ;arm, rising; write 0 to bit 7, clears CH3F clr TIME clr TIME+1 cli ;enable rts; Program 6.2. Periodic interrupt using input capture and an external clock.; MC68HC708XL36CH3Han lda TSC3 ;expect 11000100 [3] and #$C4 [2] beq ClkHan [3] swiClkHan pshh ;H not saved [2] bclr 7,TSC3 ;Acknowledge [4] ldhx TIME [4] aix #1 [2] sthx TIME [4] pulh rti org $FFEE ;timer channel 3 fdb CH3Han; Program 6.4. Initialization for period measurement.; MC68HC708XL36;external signal to PTE5/TCH1Period rmb 2 ;units 500 nsFirst rmb 2 ;TCNT at first edgeDone rmb 1 ;set each risingInit sei ;make atomic mov #$02,TSC ;500ns clk lda TSC1 mov #$44,TSC1 ;arm,rising; write 0 to bit 7, clears CH1F ldhx TCNT sthx First clr Done cli ;enable rts; Program 6.5. ISR for period measurement.; MC68HC708XL36CH1Han bclr 7,TSC1 ;Acknowledge [4] lda TCH1+1 [3] sub First+1 [3] sta Period+1 [4] lda TCH1 [3] sbc First [3] sta Period [4] mov #$FF,Done [4] mov TCH1,First [5] mov TCH1+1,First+1 [5] rti [7] org $FFF2 ;timer channel 1 fdb CH1Han; Program 6.7. Assembly initialization for 32-bit period measurement.; MC68HC708XL36;external signal to PTE5/TCH1Period rmb 4 ;units 500 nsFirst rmb 2 ;TCNT at first edgeCount rmb 2 ;number of TOF'sMode rmb 1 Init sei ;make atomic lda TSC ;arm clear TOF mov #$42,TSC ;500ns clk lda TSC1 mov #$44,TSC1 ;arm,rising; write 0 to bit 7, clears CH1F clr Mode cli ;enable rts; Program 6.8. Assembly input capture ISR for 32-bit period measurement.; MC68HC708XL36CH1Han pshh bclr 7,TSC1 ;Ack, CH1F=0 lda Mode bne Mode1 ;skip if mode=1Mode0 mov TCH1,First mov TCH1+1,First+1 clr Count clr Count+1 inc Mode ;change 0 to 1 lda TCH1 bmi done ;skip if TCH1 bit 15 lda TSC bpl done ;skip if not TOF ldhx Count ;both TOF and CH1F aix #-1 ;but TOF was first sthx Count ;so TOF not counted bra doneMode1 lda TCH1 bmi skip ;skip if TCH1 bit 15 lda TSC bpl skip ;skip if not TOF ldhx Count ;both TOF and CH1F aix #1 ;but TOF was first sthx Count ;so TOF is countedskip inc Mode ;change 1 to 2 lda TCH1+1 sub First+1 sta Period+3 ;bottom 8 bits lda TCH1 sbc First sta Period+2 lda Count+1 sbc #0 sta Period+1 lda Count sbc #0 sta Period ;top 16 bits mov #$02,TSC ;disarm TOF mov #$04,TSC1 ;disarm CH1Fdone pulh rti org $FFF2 ;timer channel 1 fdb CH1Han; Program 6.9. Assembly timer overflow ISR for 32-bit period measurement.; MC68HC708XL36TOFHan bclr 7,TSC ;Ack TOF=0 lda Count+1 add #1 sta Count+1 lda Count adc #0 sta Count bcc TOFok mov #2,Mode ;error no first lda #$FF sta Period sta Period+1 sta Period+2 sta Period+3 mov #$02,TSC ;disarm TOF mov #$04,TSC1 ;disarm CH1FTOFok rti org $FFEC ;timer oveflow fdb TOFHan; Program 6.11. Ritual written in assembly language for the pulse width measurement.; MC68HC708XL36; B=PB7, Q=PTE6/TCH6, set global RInit bset 7,DDRB ;PB7 output mov #$02,TSC ;500ns clk rts; Program 6.12. Assembly language pulse width measurement.; MC68HC708XL36Rising rmb 2R rmb 2 ;resistance in Kohm Meas mov #$02,TSC ;500ns clk lda TSC1 mov #$04,TSC2 ;rising,clear CH2F bclr 7,PORTB ;B=0 bset 7,PORTB ;B=1, trigger LS123First brclr 7,TSC2,First ;wait rising mov #$08,TSC2 ;falling,clear CH2F ldhx TCH2 sthx RisingSecnd brclr 7,TSC2,Secnd ;wait falling lda TCH2+1 sub Rising+1 sta R+1 ;R=TCH2-Rising lda TCH2 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.; MC68HC708XL36;external signal to PTE5/TCH1PW rmb 2 ;units 500 nsRising rmb 2 ;TCNT at rising edgeDone rmb 1 ;set each fallInit sei ;make atomic mov #$02,TSC ;500ns clk lda TSC1 mov #$4C,TSC1 ;arm,both,clr CH1F clr Done cli ;enable rtsCH1Han bclr 7,TSC1 ;Acknowledge lda PORTE and #$20 ;check PTE5 beq fall ;falling if PTE5=0 rise mov TCH1,Rising mov TCH1+1,Rising+1 bra CH1rtifall lda TCH1+1 sub Rising+1 sta PW+1 lda TCH1 sbc Rising sta PW mov #$FF,Done CH1rti rti org $FFF2 ;timer channel 1 fdb CH1Han; Program 6.16. Assembly language pulse width measurement using two input captures.; MC68HC708XL36;signal to PTE5/TCH1 and PTE6/TCH2PW rmb 2 ;units 500 nsDone rmb 1 ;set each fallInit sei ;make atomic mov #$02,TSC ;500ns clk lda TSC1 mov #$48,TSC1 ;arm, fall mov #$08,TSC2 ;disarm, rise clr Done cli ;enable rtsCH1Han bclr 7,TSC1 ;Acknowledge lda TCH1+1 sub TCH2+1 sta PW+1 lda TCH1 sbc TCH2 sta PW mov #$FF,Done rti org $FFF2 ;timer channel 1 fdb CH1Han; 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.; MC68HC708XL36
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -