📄 debug.c
字号:
/*****************************************************************************
* (c) Freescale Semiconductor Inc. 2005 All rights reserved
*
* File Name : debug.c
*
* PURPOSE: Diagnostics output through SCI
*
*
* DESCRIPTION: Implementation of the diagnostics output - enabled when
* ETH_DEBUG keyword is defined (-DETH_DEBUG)
* _SCI_BASE must be set to SCI0 or SCI1
* (see compiler command line arguments)
*
* Version : 1.0
* Date : 05/01/05
*
*****************************************************************************/
#include <stdio.h>
#include "debug.h"
//#include "MC9S08AW60_local.h"
#include <MC9S08AW60.h>
#ifdef EN_DEBUG
#define _BASE 0x0000 /**< Base on register map */
#define ECLK 4000000 /**< this is BUSCLK */
#define reg(x) *((volatile tU08 *)(_BASE+x))
#define regw(x) *((volatile tU16 *)(_BASE+x))
#define SCI0 0x0038
#define SCI1 0x0040
//#ifndef _SCI_BASE
//#error _SCI_BASE not defined, use SCI0 or SCI1
//#endif
#define SCIBD regw(_SCI_BASE+0x00)
#define SCIC1 reg(_SCI_BASE+0x02)
#define SCIC2 reg(_SCI_BASE+0x03)
#define SCIS1 reg(_SCI_BASE+0x04)
#define SCIS2 reg(_SCI_BASE+0x05)
#define SCIC3 reg(_SCI_BASE+0x06)
#define SCID reg(_SCI_BASE+0x07)
//===================================================
void InitDebug(void)
{
#define BAUD_RATE 9600
#define BAUD_DIV ECLK/16/BAUD_RATE
SCIBD= BAUD_DIV;
SCI1C1= 0;
SCI1C2= SCI1C2_TE_MASK | SCI1C2_RE_MASK | SCI1C2_RWU_MASK ;
}
//===================================================
/* send string via SCI */
//===================================================
void Debugt(tS08 * s)
{
while (*s != 0)
{
while (!(SCIS1 & 0x80));
SCID=*s;
s++;
}
}
//===================================================
/* convert 8bit number to 2 hexadecimal ascii characters */
//===================================================
tS08 cvt[16]={ '0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F' };
//===================================================
void Ctoh (tS08 * s, tU08 c)
{
*s= cvt[c / 16];
s++;
*s= cvt[c % 16];
}
//===================================================
/* send 16bit number in hexa via SCI */
//===================================================
void Debugi(tU16 i)
{
tS08 s[6];
s[0]=' ';
Ctoh(s+1,(tU08)(i / 256));
Ctoh(s+3,i % 256);
s[5]=0;
Debugt(s);
}
//===================================================
/* send 8bit number in hexa via SCI */
//===================================================
void Debugc(tU08 c)
{
tS08 s[4];
s[0]=' ';
Ctoh(s+1,c);
s[3]=0;
Debugt(s);
}
//===================================================
/* send newline and return characters via SCI */
//===================================================
void Debugnl(void)
{
Debugt("\r\n");
}
//===================================================
/* read a character via SCI */
//===================================================
unsigned char SCI_Read(void)
{
unsigned char rc;
// rc = SCISR1; // dummy read to clear flags
// rc = SCIDRL; // data read
while ( !(SCIS1 & 0x20)); // wait for data to arrive
rc = SCIS1; // dummy read to clear flags
rc = SCID; // data read
return rc;
}
//=============================================
void SCI_Write_CH(char data_out)
{
while (!(SCIS1 & 0x80)); // wait for output buffer empty
SCID = data_out;
}
//=============================================
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -