cryosc.asm

来自「8051试验程序 基础教材」· 汇编 代码 · 共 86 行

ASM
86
字号
;-----------------------------------------------------------------------------
; cryosc.ASM
;-----------------------------------------------------------------------------
; Copyright (C) 2005 Silicon Laboratories, Inc.
;
; FILE:        cryosc.ASM
; DEVICE:      C8051F30x
; AUTH:        BW
; DATE:        11 DEC 01
;
; This program provides an example of how to configure the C8051F30x device
; to operate from an external 22.1184MHz crystal attached to the XTAL1 and
; XTAL2 pins.  Also enables Missing Clock Detector.
;
;-----------------------------------------------------------------------------

;-----------------------------------------------------------------------------
; EQUATES
;-----------------------------------------------------------------------------

#include "ioC8051F300.h"

SYSCLK      EQU      22118       ; SYSCLK frequency in kHz

;-----------------------------------------------------------------------------
; VARIABLES
;-----------------------------------------------------------------------------

;-------------------
; STACK


            RSEG  STACK_PTR:IDATA ; declare STACK segment
            DS    80h             ; reserve 128 bytes for stack

;-----------------------------------------------------------------------------
; MACRO DEFINITIONS
;-----------------------------------------------------------------------------

;-----------------------------------------------------------------------------
; RESET AND INTERRUPT VECTOR TABLE
;-----------------------------------------------------------------------------

            ASEGN CSEG01:CODE,0
            ljmp  Main                    ; RESET vector

;-----------------------------------------------------------------------------
; MAIN PROGRAM CODE
;-----------------------------------------------------------------------------

            RSEG CRYOSC:CODE

Main:
            ; Disable the WDT.
            anl   PCA0MD, #NOT(040h)      ; clear Watchdog Enable bit

            ; Enable the Port I/O Crossbar
            orl   XBR0, #0ch              ; skip XTAL pins in crossbar
                                          ; assignments
            mov   XBR2, #40h              ; enable Crossbar
            anl   P0MDIN, #NOT(0ch)       ; XTAL1 and XTAL2 are analog inputs

            mov   SP, SFB(STACK_PTR)    ; init stack pointer

            mov   OSCXCN, #67h            ; enable external crystal
                                          ; oscillator at 22.1184MHz

            clr   A                       ; wait at least 1ms
            djnz  ACC, $                  ;  wait ~340us
            djnz  ACC, $                  ;  wait ~340us
            djnz  ACC, $                  ;  wait ~340us

osc_wait:                                 ; poll for XTLVLD-->1
            mov   a, OSCXCN
            jnb   ACC.7, osc_wait

            mov   RSTSRC, #04h            ; enable Missing Clock Detector
            mov   OSCICN, #08h            ; select external oscillator as
                                          ; system clock source

            sjmp  $                       ; spin forever

;-----------------------------------------------------------------------------
; End of file.

            END

⌨️ 快捷键说明

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