|
;*******************************************************************************
;
; NEC Electronics 78K0S/KB1+
;
;*******************************************************************************
; 78K0S/KB1+ Sample program
;*******************************************************************************
; Initialization
;*******************************************************************************
;<<History>>
; 2007.4.-- Release
;*******************************************************************************
;
;<<Overview>>
;
; This sample program initializes the microcontroller by setting functions
; such as clock frequency and the port to the input or output.
; After the initialization, three LED lights are controlled by two switches.
;
; <Principal setting contents in initialization>
;
; - Set the vector table
; - Set the stack pointer
; - Stop the watchdog timer operation
; - Set the CPU clock frequency at 2 MHz
; - Stop the low-speed internal oscillator
; - Set the ports to the input or output mode
; - Set the connection of on-chip pull-up resistors (input port only)
; - Set the output latches of the output ports
;
;
; <Switch input and LED output>
;
; +---------------------------------------+
; | SW1 | SW2 | LED1 | LED2 | LED3 |
; | (P40) | (P43) | (P20) | (P21) | (P22) |
; |---------------|-----------------------|
; | OFF | OFF | OFF | OFF | OFF |
; | ON | OFF | ON | OFF | OFF |
; | OFF | ON | OFF | ON | OFF |
; | ON | ON | OFF | OFF | ON |
; +---------------------------------------+
;
;
;<<I/O port settings>>
;
; Input: P40, P43
; Output: P00-03, P20-23, P30-33, P41, P42, P44-P47, P120-P123, P130
; # All unused ports are set as the output mode.
;
;*******************************************************************************
;===============================================================================
;
; Vector table
;
;===============================================================================
XVCT CSEG AT 0000H
DW RESET_START ;(00) RESET
DW RESET_START ;(02) --
DW RESET_START ;(04) --
DW RESET_START ;(06) INTLVI
DW RESET_START ;(08) INTP0
DW RESET_START ;(0A) INTP1
DW RESET_START ;(0C) INTTMH1
DW RESET_START ;(0E) INTTM000
DW RESET_START ;(10) INTTM010
DW RESET_START ;(12) INTAD
DW RESET_START ;(14) --
DW RESET_START ;(16) INTP2
DW RESET_START ;(18) INTP3
DW RESET_START ;(1A) INTTM80
DW RESET_START ;(1C) INTSRE6
DW RESET_START ;(1E) INTSR6
DW RESET_START ;(20) INTST6
;===============================================================================
;
; Define the ROM data table
;
;===============================================================================
XTBL1 CSEG AT 0100H 改动处////////
LEDDATA:
DB 00000011B ;00: SW1=ON, SW2=ON -> LED3=ON
DB 00000101B ;01: SW1=OFF,SW2=ON -> LED2=ON
DB 00000111B ;02: Dummy
DB 00000111B ;03: Dummy
DB 00000111B ;04: Dummy
DB 00000111B ;05: Dummy
DB 00000111B ;06: Dummy
DB 00000111B ;07: Dummy
DB 00000110B ;08: SW1=ON, SW2=OFF -> LED1=ON
DB 00000111B ;09: SW1=OFF,SW2=OFF -> LED1,2,3=OFF
;===============================================================================
;
; Define the memory stack area
;
;===============================================================================
XSTK DSEG AT 0FEE0H
STACKEND:
DS 20H ; Memory stack area = 32byte
STACKTOP: ; Start address of the memory stack area = FF00H
;*******************************************************************************
;
; Initialization after RESET
;
;*******************************************************************************
XMAIN CSEG UNIT
RESET_START:
;-------------------------------------------------------------------------------
; Initialize the stack pointer
;-------------------------------------------------------------------------------
MOVW AX, #STACKTOP
MOVW SP, AX ; Set the stack pointer at FF00H
;-------------------------------------------------------------------------------
; Initialize the watchdog timer
;-------------------------------------------------------------------------------
MOV WDTM, #01110111B ; Stop the watchdog timer operation
;-------------------------------------------------------------------------------
; Initialize the clock generators
;-------------------------------------------------------------------------------
MOV PPCC, #00000010B ; The clock supplied to the peripheral hardware (fxp) = fx/4 (= 2MHz)
MOV PCC, #00000000B ; The clock supplied to the CPU (fcpu) = fxp (= 2MHz)
MOV LSRCM, #00000001B ; Stop the low-speed internal oscillator
;-------------------------------------------------------------------------------
; Initialize the port 0
;-------------------------------------------------------------------------------
MOV PM0, #11110000B ; Set P00-P03 as output mode
MOV P0, #00000000B ; Set output latches of P00-P03 as low
;-------------------------------------------------------------------------------
; Initialize the port 2
;-------------------------------------------------------------------------------
MOV PM2, #11110000B ; Set P20-P23 as output mode
MOV P2, #00000111B ; Set output latches of P20-P22 as high, P23 as low
;-------------------------------------------------------------------------------
; Initialize the port 3
;-------------------------------------------------------------------------------
MOV PM3, #11110000B ; Set P30-P33 as output mode
MOV P3, #00000000B ; Set output latches of P30-P33 as low
;-------------------------------------------------------------------------------
; Initialize the port 4
;-------------------------------------------------------------------------------
MOV PM4, #00001001B ; Set P40 and P43 as input mode, P41, P42 and P44-P47 as output mode
MOV PU4, #00001001B ; Connect on-chip pull-up resistors to P40 and P43
MOV P4, #00000000B ; Set output latches of P41, P42 and P44-P47 as low
;-------------------------------------------------------------------------------
; Initialize the port 12
;-------------------------------------------------------------------------------
MOV PM12, #11110000B ; Set P120-P123 as output mode
MOV P12, #00000000B ; Set output latches of P120-P123 as low
;-------------------------------------------------------------------------------
; Initialize the port 13
;-------------------------------------------------------------------------------
MOV P13, #00000001B ; Set output latch of P130 as high
;-------------------------------------------------------------------------------
; Initialize the general-purpose register
;-------------------------------------------------------------------------------
MOVW HL, #LEDDATA ; Set the table address to the HL register
;*******************************************************************************
;
; Main loop
;
;*******************************************************************************
MAIN_LOOP:
MOV A, P4 ; Read switch-input status
AND A, #00001001B ; Mask the data except the switch-input status
MOV L, A ; Set switch-input status to the lower 8 bits of the table address
MOV A, [HL] ; Read LED output data from the table
MOV P2, A ; Output the LED light
BR $MAIN_LOOP ; Go to the MAIN_LOOP
end
改动的语句为 XTBL1 CSEG AT 0100H 改为XTBL1 CSEG AT 0088H |
|