📄 chap3.asm
字号:
; Chapter 3 6808 assembly language programs; Jonathan W. Valvano; This software accompanies the book,; Real Time Embedded Systems published by Brooks Cole;; Program 3.3. Assembly language routines to initialize and output to a printer.; MC68HC708XL36/MC68HC912B32; PortA is DATA, PB0=GOInit lda #$FF sta DDRA lda #$01 sta DDRA sta PORTB ;GO=1 rtsOut sta PORTA ;set data lda #0 sta PORTB ;GO=0 lda #1 sta PORTB ;GO=1 lda #79 ldx #0 ;20224OLoop decx ;[1] bne OLoop ;[3] deca bne Oloop ;wait rts; Program 3.8. Assembly language routines to initialize and read from an A/D.; MC68HC708XL36/MC68HC912B32; PortA is DATA, PB0=GOInit clr DDRA lda #$FF sta DDRB clr PORTB ;GO=0 rtsIn ldaa #1 staa PORTB ;GO=1 clr PORTB ;GO=0 lda #10loop deca ;[1] bne loop ;[3] lda PORTA rts; Program 3.10. Assembly language routines to initialize and read from a keyboard.; MC68HC708XL36/MC68HC912B32; PA6-0 is DATA, PA7=STROBEInit clr DDRA rtsIn brset 7,PORTA,InLoop brclr 7,PORTA,Loop lda PORTA and #$7F rts; Program 3.12. Assembly language routines to initialize and read from an A/D.; MC68HC708XL36/MC68HC912B32; PortA=DATA PB1=DONE PB0=GOInit lda #$01 ;PB1 input sta DDRB ;PB0 output clr DDRA ;PA inputs clr PORTB ;GO=0 rtsIn lda #1 sta PORTB ;GO=1 clr PORTB ;GO=0;wait for rise of DONELoop brclr 1,PORTB,Loop lda PORTA rts; Program 3.14. Handshaking assembly language routines to initialize and read from a sensor.; MC68HC708XL36/MC68HC912B32; PortA=DATA PB1=READY PB0=ACKInit lda #$01 ;PB1 input sta DDRB ;PB0 output clr DDRA ;PA inputs lda #$01 sta PORTB ;ACK=1 rtsIn brclr 1,PORTB,In clr PORTB ;ACK=0 lda PORTA ;read DATA inc PORTB ;ACK=1Loop brset 1,PORTB,Loop rts; Program 3.17. Handshaking assembly language routines to initialize and write to a printer.; MC68HC708XL36/MC68HC912B32; PA=DATA PB1=READY PB0=STARTInit lda #$01 ;PB1 input sta DDRB ;PB0 output lda #$FF sta DDRA ;PA outputs lda #$01 sta PORTB ;START=1 rts; Reg A is data to printOut clr PORTB ;START=0 sta PORTA ;write DATA inc PORTB ;START=1; wait for the rising edgeWait brset 1,PORTB,WaitLoop brclr 1,PORTB,Loop rts; Program 3.19. Assembly language initialization of the DS1620; MC68HC708XL36; PB2=RST PB1=CLK PB0=DQInit lda #$07 ;PB2-0 output sta DDRB lda #$03 ;RST=0,CLK=1 sta PORTB ;DQ=1 rts; Program 3.21. Assembly language helper functions for the DS1620; MC68HC708XL36out8 ldx #8 ;8 bitsclop bclr 1,PORTB ;CLK=0 lsra ;lsb first bcc set0 bset 0,PORTB ;DQ=1 bra nextset0 bclr 0,PORTB ;DQ=0next bset 1,PORTB ;CLK=1 decx bne clop rtsstart bset 3,PORTB ;RST=1 lda #$EE bsr out8 bclr 3,PORTB ;RST=0 rtsstop bset 3,PORTB ;RST=1 ldaa #$22 bsr out8 bclr 3,PORTB ;RST=0 rts; Program 3.23. Assembly language functions to set the configuration register on the DS1620; MC68HC708XL36config psha bset 3,PORTB ;RST=1 lda #$0C bsr out8 pula bsr out8 bclr 3,PORTB ;RST=0 rts; Program 3.25. Assembly language 9-bit output helper function for the DS1620; MC68HC708XL36;output 9 bits, Reg X:A=dataout9 stx temp ldx #8 ;8 bitsolop bclr 1,PORTB ;CLK=0 lsra ;lsb first bcc oset0 bset 0,PORTB ;DQ=1 bra onextoset0 bclr 0,PORTB ;DQ=0onext bset 1,PORTB ;CLK=1 decx bne olop lda temp ;msbit bclr 1,PORTB ;CLK=0 lsra ;msb last bcc mset0 bset 0,PORTB ;DQ=1 bra mnextmset0 bclr 0,PORTB ;DQ=0mnext bset 1,PORTB ;CLK=1 rts; Program 3.26. Assembly language functions to set the threshold registers on the DS1620; MC68HC708XL36WriteTH psha pshx bset 3,PORTB ;RST=1 lda #$01 bsr out8 pulx pula bsr out9 bclr 3,PORTB ;RST=0 rtsWriteTL psha pshx bset 3,PORTB ;RST=1 lda #$02 bsr out8 pulx pula bsr out9 bclr 3,PORTB ;RST=0 rts; Program 3.28. Assembly language functions to read the configuration register on the DS1620; MC68HC708XL36;input 8 bits, Reg A=datain8 ldx #8 ;8 bits lda DDRB and #$FE ;DQ input sta DDRBilop bclr 1,PORTB ;CLK=0 lsra ;lsb first brclr 0,PORTB,inext ora #$80 ;DQ=1inext bset 1,PORTB ;CLK=1 decx bne ilop tax lda DDRB ora #$01 ;DQ output sta DDRB txa rts;Reg A is config valueReadConfig bset 3,PORTB ;RST=1 lda #$AC bsr out8 bsr in8 bclr 3,PORTB ;RST=0 rts; Program 3.29. Assembly language 9-bit read helper function for the DS1620; MC68HC708XL36;input 9 bits, Reg A:X=datain9 ldx #9 ;9 bits lda DDRB and #$FE ;DQ input sta DDRB clra ;ms bytejlop bclr 1,PORTB ;CLK=0 lsra ;lsb first ror temp9 brclr 0,PORTB,jnext ora #$80 ;DQ=1jnext bset 1,PORTB ;CLK=1 decx bne jlop tax lda DDRB ora #$01 ;DQ output sta DDRB txa ldx temp9 rts; Program 3.30. Assembly language functions to read the temperatures from the DS1620; MC68HC708XL36;Reg A:X returned as TH valueReadTH bset 3,PORTB ;RST=1 lda #$A1 bsr out8 bsr in9 bclr 3,PORTB ;RST=0 rts;Reg A:X returned as TL valueReadTL bset 3,PORTB ;RST=1 lda #$A2 bsr out8 bsr in9 bclr 3,PORTB ;RST=0 rts;Reg A:X returned temperatureReadT bset 3,PORTB ;RST=1 lda #$AA bsr out8 bsr in9 bclr 3,PORTB ;RST=0 rts
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -