main.asm

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

ASM
177
字号
/*
08/18/2006: Petre M.
  -this program uses the watchdog timer (set at 2sec period) to send character
    strings using the UART whenever the watchdog interrupts are generated
  -The characters may be received by the Hyperterminal on the PC with the
    following settings:
      -In Connect To Window:
        -Connect Using: write COMx used by the connection to the PC
        -Configure:
          -Bits per second: 9600
          -Data Bits: 8
          -Parity: none
          -Stop bits: 1
          -Flow Control: none
*/
#include "ioADE7169F16.h"

STACKSIZE	EQU	030h            ; allocate enough space for stack

          ASEGN  myDseg :DATA           ; starts at 20h. See linker file.
//add IDATA variables here

          ASEGN myXseg :XDATA
//add IXDATA variables here

          ASEGN  INTVEC :CODE

StartVector:
          org 00H
          jmp MAIN

          ORG 03H
          JMP INT0IRQ

          ORG 0BH
          JMP TF0IRQ

          ORG 13H
          JMP IE1IRQ

          ORG 1BH
          JMP TF1IRQ

          ORG 23H
          JMP UartIRQ

          ORG 2BH
          JMP Timer2IRQ

          ORG 33H
          JMP ITEMPIRQ

          ORG 3BH
          JMP SPII2CIRQ

          ORG 43H
          JMP PSMIRQ

          ORG 4BH
          JMP IADEIRQ

          ORG 53H
          JMP RTCIRQ

          ORG 5BH
          JMP WDToutIRQ

          ORG 063H
INT0IRQ:
      RETI

TF0IRQ:
      RETI

IE1IRQ:
      RETI

TF1IRQ:
      RETI

UartIRQ:
      RETI

Timer2IRQ:
      RETI

ITEMPIRQ:
      RETI

SPII2CIRQ:
	RETI

PSMIRQ:
      RETI

IADEIRQ:
      RETI

RTCIRQ:
      RETI

WDToutIRQ:
      MOV   DPTR, #Watchdog_ISR_Message
      CALL  SENDSTRING
      RETI
;____________________________________________________________________
MAIN:						; (main program)
//add the assembly program here

//set 4.096MHz core frequency
        MOV KYREG,#0xa7;
        ANL POWCON,#0xF8; //CD2 CD1 CD0=000

//set up watchdog for 2s and to interrupt instead of reset
        CLR EA
        SETB WDWR
        MOV WDCON, #07Bh 	
        SETB EA


        CALL  uart_init

        MOV DPTR,#Start_Message
        CALL SENDSTRING


FOREVER:
        JMP   FOREVER
;____________________________________________________________________
uart_init:

        /*01=Mode 1=8 bit UART, variable rate
            0=RI is set as soon as the data byte is received
             0=serial port reception disabled
              0=this bit represents the 9th data bit transmitted in Modes 2 and 3
               0=this bit represents the stop bit received in Mode 1 case
                0=Tx INT flag
                 0=Rx INT flag
        */
        SETB SM1

        //for 9600baud@4.096MHz, DIV=4 and SBAUDF=0xab, real freq=9570baud
        mov SBAUDT, #0x04
        mov SBAUDF, #0xab
        RET
;____________________________________________________________________

SENDSTRING:
        PUSH    ACC
        PUSH    B
        CLR     A
        MOV     B,A
next_char:
        MOV     A,B
        INC     B
        MOVC    A,@A+DPTR
        JZ      end_of_string
        CLR     TI              ; must clear TI
        MOV     SBUF,A
        JNB     TI,$            ; wait til present char gone
        SJMP    next_char
end_of_string:
        POP     B
        POP     ACC
        RET

Watchdog_ISR_Message:  DB 13,10,'Reached watchdog ISR due to watchdog timeout',13,10,0
Start_Message:  DB 13,10,'Code is starting',13,10,0


        END





⌨️ 快捷键说明

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