📄 chap1.asm
字号:
; Chapter 1 6812 assembly language programs; Jonathan W. Valvano; This software accompanies the book,; Embedded Microcomputer Systems: Real Time Interfacing; published by Brooks Cole, 1999; Program 1.2. 6812 software to enable the timer system.TSCR = $0086TMSK2 = $008D movb #$80,TSCR movb #$33,TMSK2;Program 1.3. 6812 assembly software that programs its internal EEPROM.TCNT = $0084EEPROT = $00F1EEPROG = $00F3EraseAll = $06 ; bulk erase all EEPROMEraseWord= $16 ; erase an aligned 16-bit wordEraseRow = $0E ; erase 32 bytes in one rowProgWord = $02 ; prgram an aligned 16-bit word; **********program EEPROM**************************; RegX points into aligned address to change; (RegX needs to point into EEPROM for erase functions); RegY has data, returns actual data at that address; RegA has command $06,$16,$0E,$02Prog: ldab EEPROT ; save previous block protect pshb clr EEPROT ; allow changes staa EEPROG ; BULKP=0, ELAT=1, EEPRGM=0 sty 0,x ; latches address, data inca ; sets EEPRGM=1 staa EEPROG ldd TCNT ; 10000 counts at 1_s each addd #10000 ; EndT=RegD is TCNT value 10ms from nowwloop: cpd TCNT ; EndT-TCNT bpl wloop ; wait for TCNT to pass EndT clr EEPROG pulb stab EEPROT ; restore previous block protect ldy 0,x ; actual value in EEPROM rts ; Program 1.12. Assembly definitions of the MC68HC812A4 I/O portsPORTA equ $0000 General Purpose Input/Output PortPORTB equ $0001 General Purpose Input/Output PortDDRA equ $0002 Data Direction RegisterDDRB equ $0003 Data Direction RegisterPORTC equ $0004 General Purpose Input/Output PortPORTD equ $0005 General Purpose Input/Output PortDDRC equ $0006 Data Direction RegisterDDRD equ $0007 Data Direction RegisterPORTE equ $0008 General Purpose Input/Output PortDDRE equ $0009 Data Direction RegisterPORTH equ $0024 General Purpose I/O Port, Key wakeup, interruptDDRH equ $0025 Data Direction RegisterPORTJ equ $0028 General Purpose I/O Port, Key wakeup, interruptDDRJ equ $0029 Data Direction RegisterPORTF equ $0030 General Purpose I/O Port, Chip select logicPORTG equ $0031 General Purpose I/O PortDDRF equ $0032 Data Direction RegisterDDRG equ $0033 Data Direction RegisterPORTAD equ $006F Analog input General Purpose Input PortTCNT equ $0084 16-bit TimerPORTT equ $00AE Timer Input/Output Port General Purpose I/O PortDDRT equ $00AF Data Direction RegisterSC0BD equ $00C0 16-bit Baud rate RegisterSC0CR1 equ $00C2 Serial Port Control RegisterSC0CR2 equ $00C3 Serial Port Control RegisterSC0SR1 equ $00C4 Serial Port Status RegisterSC0SR2 equ $00C5 Serial Port Status RegisterSC0DRH equ $00C6 high byte of Serial Port DataSC0DRL equ $00C7 Serial Port Data RegisterPORTS equ $00D6 Serial Input/Output Port General Purpose I/O port DDRS equ $00D7 Data Direction Register; Assembly definitions of the MC68HC912B32 I/O ports.PORTA equ $0000 General Purpose Input/Output PortPORTB equ $0001 General Purpose Input/Output PortDDRA equ $0002 Data Direction Register DDRB equ $0003 Data Direction Register PORTE equ $0008 General Purpose I/O Port, Mode and bus controlDDRE equ $0009 Data Direction Register PORTP equ $0056 General Purpose I/O Port, Pulse-Width ModulationDDRP equ $0057 Data Direction Register PORTAD equ $006F Analog input General Purpose Input PortTCNT equ $0084 16-bit Timer PORTT equ $00AE Timer I/O Port, General Purpose I/O PortDDRT equ $00AF Data Direction Register SC0BD equ $00C0 16-bit Baud rate Register SC0CR1 equ $00C2 Serial Port Control Register SC0CR2 equ $00C3 Serial Port Control Register SC0SR1 equ $00C4 Serial Port Status Register SC0SR2 equ $00C5 Serial Port Status Register SC0DRH equ $00C6 high byte of Serial Port Data SC0DRL equ $00C7 Serial Port Data Register PORTS equ $00D6 Serial I/O Port, General Purpose Input/Output PortDDRS equ $00D7 Data Direction Register PORTDLC equ $00FE Byte Data Link Communications, General Purpose I/ODDRDLC equ $00FF Data Direction Register ; Program 1.14. Assembly software that reads from port A and writes to port B.; Program to implement a NOT gate; Port A are the 8 digital inputs and Port B are the 8 digital outputs; Software continuously repeats the following; 1) Read value from Port A; 2) Calculate the logical complement; 3) Write the result out to Port BNotGate ldaa PORTA Read from Port A into Register A coma Logical complement staa PORTB Write from Register A to Port B bra NotGate; Program 1.16. Assembly software that initializes an I/O port to input.; MC68HC812A4 clr DDRJ; Program 1.18. Assembly software that reads from an I/O port input.; MC68HC812A4 ldaa PORTJ staa Happiness; MC68HC912B32 ldaa PORTA staa Happiness; Program 1.20. Assembly software that initializes an I/O port to output.; MC68HC812A4 ldaa #$0F staa DDRJ; MC68HC912B32 ldaa #$0F staa DDRA;Program 1.22. Assembly software that outputs an I/O port output.; MC68HC812A4 ldaa #$FF staa PORTJ; MC68HC912B32 lda #$FF sta PORTA ; Program 1.24. Assembly subroutines that provide initialization, read and write access an I/O port.; MC68HC812A4Init staa DDRJ rtsSet staa PORTJ rtsRead ldaa PORTJ rts; MC68HC912B32Init staa DDRA rtsSet staa PORTA rtsRead ldaa PORTA rts; Program 1.26. Assembly subroutine that initializes the I/O port.; MC68HC812A4PORTC equ $0004 ;I/O portDDRC equ $0006 init movb #$F0,DDRC rts; Program 1.27. Assembly program that implements the 4 bit NOT gate.; MC68HC812A4 org $F000 ;EEPROMmain lds #$0C00 ;SP=$00FF bsr init ;ritualloop ldaa PORTC ;input coma ;logical not lsla ;shift lsla lsla lsla staa PORTC ;output bra loop ;repeat org $FFFE fdb main ;reset vector
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -