各位大侠,俺写的一段908KX8的程序,PTB2外接一个LED , 低电平驱动,开始的时候外部晶体不会振,后来写了配置寄存器后,可以振荡,但是程序工作仍然不正常,好象执行一条指令就停止那样,灯不会闪,晶体6M,延时没有准确计算,现在搞不清楚问题出在什么地方。希望给予指教。
;*******************************************************************************
; MAIN.ASM
;*******************************************************************************
; Copyright (c) 2005 CDFBY
; cdfby@yahoo.com.cn
;*******************************************************************************
;
; SCI Sample for MC68HC908KX8 Send Data to Bmw instrument Dash
;
;*******************************************************************************
;
;
;
;*******************************************************************************
; Registers definition
;*******************************************************************************
XDEF Entry, main
PTA EQU $0000 ; Port A data register
DDRA EQU $0004 ; Port A data direction register
PTB EQU $0001 ; Port B data register
DDRB EQU $0005 ; Port B data direction register
PTAPUE EQU $000D ; Port A Input Pullup Enable Register
SCC1 EQU $0013 ; SCI Control Register 1
SCC2 EQU $0014 ; SCI Control Register 2
SCC3 EQU $0015 ; SCI Control Register 3
SCS1 EQU $0016 ; SCI Status Register 1
SCS2 EQU $0017 ; SCI Status Register 2
SCDR EQU $0018 ; SCI Data Register
SCBR EQU $0019 ; SCI Baud Rate Register
KBSCR EQU $001A ; Keyboard Status and Control Register
KBIER EQU $001B ; Keyboard Interrupt Enable Register
INTSCR EQU $001D ; IRQ status & control register
CONFIG2 EQU $001E ; Configuration register 2
CONFIG1 EQU $001F ; Configuration register 1
ICGCR EQU $0035 ;
ICGMR EQU $0037 ;
ICGTR EQU $0038 ;
ICGDVR EQU $0039 ;
ICGDSR EQU $003A ;
ADSCR EQU $003C ; ADC status and control register
ADR EQU $003D ; ADC data register
ADICLK EQU $003E ; ADC input clock register
INT1 EQU $FE04 ; Interrupt Status Register1
INT2 EQU $FE05 ; Interrupt Status Register2
INT3 EQU $FE06 ; Interrupt Status Register3
LVISR EQU $FE0C ; LVI Status Register
;*******************************************************************************
;DEFAULT_ROM SECTION
;*******************************************************************************
; Peripheral Initialization
;*******************************************************************************
Entry
init:
mov #%00101000,CONFIG2 ; Extclken ,Extxtalen is 1 ,enable external xtal
;bset 0, CONFIG1 ; Disables COP, Enable LVI
;bset 4, CONFIG2 ; 5V LVI, enable IRQ pull_up
;mov #%00001111,DDRB ; Set PTB2 as output
bset 2,DDRB
clr PTB
bset 1, ICGCR
;mov #%00000011, SCBR ; 00 00 0 011 PD=1 BD=8 Baud 9600
; 4.9152MHz Clk
rts
;*******************************************************************************
; Delay Routine
; -------------
; This subroutine performs a specified delay.
; Based on a 4.9152 MHz external oscillator.
;*******************************************************************************
delay:
clrh
clrx
delay_loop:
aix #1 ; Add immediate Value to H:X
cphx #307 ; Compare H:X with M
bne delay_loop ; Branch if Not Equal
sub #1 ;
bcc delay ; Branch if Carry Bit Clear
rts
;*******************************************************************************
;*******************************************************************************
; Entry Point
;*******************************************************************************
ORG $e000
main:
rsp ; SP <- 0xFF reset stack point
;cli ; Enables global interrupts
bsr init ; Peripheral initialization
main_loop:
lda #100 ; delay time
bsr delay ; Uses the ADC value (in ms) to perform a delay
lda PTB ; Toggles user LED. First reads LED status...
eor #%00000100 ; ...inverts it... for PTB2
sta PTB ; ...and writes it back
bra main_loop ; Forever
END |