cryosc.asm

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

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

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

;TARGET MCU  : C8051F206, 'F220, 'F221, 'F226, 'F230, 'F231 and F236.
;Uncomment to include SFR declarations for desired derivative

#include <ioC8051F206.h>                    ; SFR declarations
;#include <ioC8051F220.h>                    ; SFR declarations
;#include <ioC8051F221.h>                    ; SFR declarations
;#include <ioC8051F226.h>                    ; SFR declarations
;#include <ioC8051F230.h>                    ; SFR declarations
;#include <ioC8051F231.h>                    ; SFR declarations
;#include <ioC8051F236.h>                    ; SFR declarations


LED         EQU      P2.4        ; LED on target board ('1' is LED ON)

SYSCLK      EQU      18432       ; SYSCLK frequency in kHz

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

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

            RSEG  STACK_PTR:IDATA
            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             ; select CODE segment
Main:
            mov   WDTCN, #0deh            ; disable watchdog timer
            mov   WDTCN, #0adh

            mov   SP, SFB(STACK_PTR)            ; init stack pointer

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

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

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

            orl   OSCICN, #08h            ; select external oscillator as
                                          ; system clock source
            orl   OSCICN, #80h            ; enable missing clock detector

            sjmp  $                       ; spin forever

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

            END

⌨️ 快捷键说明

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