📄 debug.asm
字号:
.title Debug Functions
.sbttl (C) 2005 Spare Time Gizmos. All rights reserved.
;++
;
; Copyright (C) 2005 by Spare Time Gizmos. All rights reserved.
;
; This file is part of the Spare Time Gizmos' MP3 Player firmware.
;
; Thisfirmware is free software; you can redistribute it and/or modify it under
; the terms of the GNU General Public License as published by the Free Software
; Foundation; either version 2 of the License, or (at your option) any later
; version.
;
; This program is distributed in the hope that it will be useful, but WITHOUT
; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
; more details.
;
; You should have received a copy of the GNU General Public License along with
; this program; if not, write to the Free Software Foundation, Inc., 59 Temple
; Place, Suite 330, Boston, MA 02111-1307 USA
;
; DESCRIPTION:
; This module contains routines to initialize and reset the watch dog timer
; (WDT), as well as serial port routines used for debug I/O using the standard
; 8051's internal UART. The only reason we need these special routines for
; serial I/O rather than the standard C library functions is so that the WDT
; can be reset. Otherwise the WDT would time out while we're typing long
; strings or waiting for input.
;
; WARNING:
; The serial port uses timer 1 for baud rate generation!
;
; REVISION HISTORY:
; dd-mmm-yy who description
; 15-May-05 RLA New File
; 03-Jul-05 DJA ported to SDCC/ASX8051
;--
.module DEBUG
.optsdcc -mmcs51 --model-small
.radix d
.include "player.inc"
.globl _InitializeDebugSerial, __getkey, _putchar
.globl _InitializeWDT, _ResetWDT
.area CSEG (CODE)
;
;++
; void InitializeWDT (void)
;
; DESCRIPTION:
; This routine will initialize the standard P89C51Rx2 watch dog timer.
; The WDT used in the Atmel AT89C51Rx2 chips is compatible with the Philips
; parts and will work with this routine. Unfortunately the WDT in the
; Philips 87C66x parts is NOT compatible with this code.
;
; The watch dog timer is _disabled_ by a reset and remains disabled
; until it is enabled by this routine. Once enabled, the WDT cannot
; be disabled again except by another hardware reset!
;
; NOTE:
;-
_InitializeWDT:
; Not yet implemented...
RET
;++
; void ResetWDT (void)
;
; DESCRIPTION:
; This routine will reset the watch dog timer. Needless to say it must be
; called more often than the WDT timeout interval.
;
; NOTE:
;--
_ResetWDT:
; Not yet implemented...
RET
;
; The serial port baud rate is generated by timer 1 in 8 bit auto reload
; mode, and the rate is determined by:
;
; T1RELOAD = 256 - ( CPU_CLOCK / (16*12*BAUD_RATE) ) [SMOD == 1]
; T1RELOAD = 256 - ( CPU_CLOCK / (32*12*BAUD_RATE) ) [SMOD == 0]
;
; NOTE: On the Philips P89CC66x family parts with the 6 clocks per cycle option,
; all baud rates are doubled!
T1RELOAD = 0xFB ; 19,200 bps on P89C66x with SMOD==0 and 18.432MHz clock
;++
; void InitializeDebugSerial (void)
;
; DESCRIPTION:
; This routine will initialize the 8051's internal UART. This interface
; is used only for debugging purposes, so the baud rate is fixed at 9600.
; Timer 1 is used to generate the baud rate clock, and interrupts are _not_
; enabled for the UART!
;--
_InitializeDebugSerial:
MOV SCON, #0x52 ; select mode 1 - 8 bit UART, set REN, TI
ANL TMOD, #0x0F ; set up timer 1 as the baud rate clock
ORL TMOD, #0x20 ; select mode 2 - 8 bit auto reload
MOV TH1, #T1RELOAD ; set the divisor for the baud rate
ANL PCON, #0x3F ; always use SMOD=0 for the baud rate
SETB TR1 ; and start the timer running
SETB TI ; enable the transmitter
;; SETB REN ; and enable the receiver
RET ; and we're done
;++
; char _getkey (void)
;
; DESCRIPTION:
; This function waits for a character to be received on the 8051's serial
; port. The character received is returned as the function's value.
;
; REGISTERS: (determined by the SDCC compiler!)
; DPL -> character/byte returned from terminal
;
; NOTE:
; The only reason we need this function instead of the standard C51 library
; equivalent is that this one keeps the WDT running!
;--
__getkey:
ACALL _ResetWDT ; don't let the WDT run out on us!
JNB RI, __getkey ; but otherwise wait for any key
MOV DPL, SBUF ; there's something there now - read it
CLR RI ; and enable the receiver for next time
RET ; all done
;++
; void putchar (char c)
;
; DESCRIPTION:
; This function transmits the character c to the 8051's serial port. If the
; port is still busy transmitting the last character, it will wait. If the
; character printed is a newline ('\n'), then a carriage return will be added
; automatically.
;
; REGISTERS: (determined by the SDCC compiler!)
; DPL -> character to output (c)
;
; NOTE:
; The only reason we need this function instead of the standard C51 library
; equivalent is that this one keeps the WDT running!
; Unlike the C51 library equivalent, this function does not handle XON or
; XOFF.
; In the case of a newline, it actually outputs <LF> <CR> rather than the
; more usual <CR> <LF>. This doesn't seem to cause any harm...
;--
_putchar:
ACALL _ResetWDT ; keep the WDT going while we wait
JNB TI, _putchar ; wait for the transmitter to be idle
MOV SBUF, DPL ; send this byte to the terminal
CLR TI ; and start the transmitter going
MOV A, DPL ; (can't compare DPL)
CJNE A,#0x0A, putret ; did we just print a newline ("\n") ?
MOV DPL, #0x0D ; yes - send a carriage return too
AJMP _putchar ; ...
putret: RET ; otherwise we're done
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -