⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.c

📁 一款收款机C源代码!因为是几年前的代码了
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 * Module: debug.C
 * Modified by: 
 * Modified on: 
 * Copyright WeiHua Tech Ltd.
 */
#include "ECRSYS.h"
#include "ftype.h"
#include "data.h"
#include "string.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

#if 0

// public function
void Dbg_PrintOperateManual(void);
void Dbg_PrintManualHead(const byte *str);
void Dbg_Set(dword cmd);

void Dbg_EmiSetBus(byte wait);
void Dbg_EmiSetFreq(byte division);
void Dbg_EmiNoStopPrint(void);

void Uart_Debug(void);
void Rtc_Debug(void);
void KB_Debug(void);
void Lcm_Debug(void);
void FM_Debug(void);
void Flash_Debug(void);
void Wind_Debug(void);
void Draw_Debug(void);
void Sram_Debug(void);
void Prn_Debug(void);
void Buzzer_Debug(void);
void Vfd_Debug(void);

extern	volatile byte SpluKeyIn;

///////////////////////////////////////////////////////////////////////////////
// Descript:	EMI测试对策:	可自由设置主频和总线速度,以测试不同设置时的辐射情况.
///////////////////////////////////////////////////////////////////////////////
void Dbg_PrintEmiManual(void)
{
	Dbg_PrintManualHead("EMI operate manual");
	
	Prn_InsStr("10100-CASH      list", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);
	Prn_InsStr("10101-.   bus 0 wait", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);
	Prn_InsStr("10102-.   bus 1 wait", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);
	Prn_InsStr("10103-.   bus 2 wait", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);
	Prn_InsStr("10104-.   bus 3 wait", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);
	Prn_InsStr("10105-.   freq 1 div", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);
	Prn_InsStr("10106-.   freq 2 div", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);
	Prn_InsStr("10107-.   freq 4 div", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);
	Prn_InsStr("10108-.   freq 6 div", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);
	Prn_InsStr("10109-.   freq 8 div", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);
	Prn_InsStr("10110-.  freq 10 div", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);

	Prn_InsStr("10120-. no stop print", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
	Prn_Str(1);
	
	prn_Stamp();
}

/******************************************************************************
Description: 
******************************************************************************/
void Dbg_EmiSet(dword cmd)
{
	switch (cmd)
	{
	case 10100:	Dbg_PrintEmiManual();		break;
	case 10101:	Dbg_EmiSetBus(0);			break;
	case 10102:	Dbg_EmiSetBus(1);			break;
	case 10103:	Dbg_EmiSetBus(2);			break;
	case 10104:	Dbg_EmiSetBus(3);			break;
	case 10105:	Dbg_EmiSetFreq(1);			break;
	case 10106:	Dbg_EmiSetFreq(2);			break;
	case 10107:	Dbg_EmiSetFreq(4);			break;
	case 10108:	Dbg_EmiSetFreq(6);			break;
	case 10109:	Dbg_EmiSetFreq(8);			break;
	case 10110:	Dbg_EmiSetFreq(10);			break;

	case 10120:	Dbg_EmiNoStopPrint();		break;
	default:	break;
	}
}

/******************************************************************************
Description: continued printing, print one line every 3 seconds.
******************************************************************************/
void Dbg_EmiNoStopPrint(void)
{
	while (1)
	{
		byte cnt;

		Prn_InsStr("EMI continued print", MAX_PRN_LEN, NM_FONT_PRN, FLUSH_RIGHT);
		Prn_Str(1);
		for (cnt=0; cnt<10; cnt++)
		{
			if (Key_Poll_Chk())
			{
				prn_Stamp();
				return;
			}
			Wait(300);
		}
	}
}

/******************************************************************************
Description: set bus wait status, wait -- [0..3]
******************************************************************************/
void Dbg_EmiSetBus(byte wait)
{
	byte str[2];
	const byte busWait[4] = {0, 0x55, 0xaa, 0xff};

	if (wait > 3)
	{
		wait = 3;
	}
	wcr = busWait[wait];
	Prn_InsStr("set bus wait: ", PRN_START_POS, NM_FONT_PRN, FLUSH_LEFT);
	str[0] = "0123456789"[wait];
	str[1] = '\0';
	Prn_InsStr(str, MAX_PRN_LEN, NM_FONT_PRN, FLUSH_RIGHT);
	Prn_Str(1);
	prn_Stamp();
}

/******************************************************************************
Description: set freqency division status, division -- [1,2,4,6,8,10]
******************************************************************************/
void Dbg_EmiSetFreq(byte division)
{
	byte str[3];
	
	#define	SET_FREQ_DIVI(div)		do {prc0 = 1; mcd = div; prc0 = 0;} while(0)

	switch (division)
	{
	case 1:		SET_FREQ_DIVI(0x12);	break;	// 12h -- 1 division 
	case 2:		SET_FREQ_DIVI(2);	break;
	case 4:		SET_FREQ_DIVI(4);	break;
	case 6:		SET_FREQ_DIVI(6);	break;
	case 8:		SET_FREQ_DIVI(8);	break;
	case 10:	SET_FREQ_DIVI(10);	break;
	default:	return;				break;
	}
	Prn_InsStr("freqency division: ", PRN_START_POS, NM_FONT_PRN, FLUSH_LEFT);
	str[0] = "0123456789"[division/10];
	str[1] = "0123456789"[division%10];
	str[2] = '\0';
	Prn_InsStr(str, MAX_PRN_LEN, NM_FONT_PRN, FLUSH_RIGHT);
	Prn_Str(1);
	prn_Stamp();
}

///////////////////////////////////////////////////////////////////////////////
// Descript:	蜂鸣器调试,实际上同时测MCU和SRAM是否运行. 短鸣三声.
//					注: 若只测MCU,需新建项目,同时不使用外部SRAM作为系统内存.
// In Param:	void
// Out Param:	void
// Return:		void
///////////////////////////////////////////////////////////////////////////////
void Buzzer_Debug(void)
{
	byte i;
	dword cnt;
	

	BUZZER_DIR = 1;
	for (i=0; i<3; i++)
	{
		OpenBuzzer();
		for (cnt=0; cnt<0x3fff; cnt++);
		CloseBuzzer();
		for (cnt=0; cnt<0x3fff; cnt++);
	}
}

///////////////////////////////////////////////////////////////////////////////
// Descript:	SRAM测试. 外部两片SRAM * 512K. 每测试成功一片长鸣一声,否则循环短鸣.
//					先测低地址空间的SRAM.
//					注: 低地址空间的SRAM,跳过了系统变量区.
// In Param:	void
// Out Param:	void
// Return:		void
///////////////////////////////////////////////////////////////////////////////
void Sram_Debug(void)
{
	byte *ptr;
	dword cnt;
	
	// 测低地址空间SRAM.
	ptr = (byte *)(0x100000 + 0x20000);
	for (cnt=0x20000; cnt<0x80000; cnt++)
	{
		*ptr++ = (byte)cnt + (byte)(cnt >> 8) + (byte)(cnt >> 16);
	}

	ptr = (byte *)(0x100000 + 0x20000);
	for (cnt=0x20000; cnt<0x80000; cnt++)
	{
		if (*ptr != ((byte)cnt + (byte)(cnt >> 8) + (byte)(cnt >> 16)))
		{
			while (1)
			{
				OpenBuzzer();
				for (cnt=0; cnt<0x1fff; cnt++);
				CloseBuzzer();
				for (cnt=0; cnt<0x1fff; cnt++);
			}
		}
		ptr++;
	}

	// 长鸣一声.
	OpenBuzzer();
	for (cnt=0; cnt<0x3ffff; cnt++);
	CloseBuzzer();

	// 测高地址空间SRAM.
	ptr = (byte *)(0x100000 + 0x80000);
	for (cnt=0x80000; cnt<0x100000; cnt++)
	{
		*ptr++ = (byte)cnt + (byte)(cnt >> 8) + (byte)(cnt >> 16);
	}

	ptr = (byte *)(0x100000 + 0x80000);
	for (cnt=0x80000; cnt<0x100000; cnt++)
	{
		if (*ptr != ((byte)cnt + (byte)(cnt >> 8) + (byte)(cnt >> 16)))
		{
			while (1)
			{
				OpenBuzzer();
				for (cnt=0; cnt<0x1fff; cnt++);
				CloseBuzzer();
				for (cnt=0; cnt<0x1fff; cnt++);
			}
		}
		ptr++;
	}

	// 长鸣一声.
	OpenBuzzer();
	for (cnt=0; cnt<0x3ffff; cnt++);
	CloseBuzzer();
}

///////////////////////////////////////////////////////////////////////////////
// Descript:	钱箱调试: 间隔两秒开关一次.
// In Param:	void
// Out Param:	void
// Return:		void
///////////////////////////////////////////////////////////////////////////////
void Draw_Debug(void)
{
	byte i;
	
	Init_Drawer();
	for (i=0; i<10; i++)
	{
		_DrawOn();
		Wait(2000);
	}
}

///////////////////////////////////////////////////////////////////////////////
// Descript:	卷纸马达调试: 间隔0.5秒启动一次.
// In Param:	void
// Out Param:	void
// Return:		void
///////////////////////////////////////////////////////////////////////////////
void Wind_Debug(void)
{
	byte i;
	void Prn_InitWind(void);

	Prn_InitWind();
	for (i=0; i<3; i++)
	{
		OpenWindMotor();
		Wait(500);
		CloseWindMotor();
		Wait(500);
	}
}

///////////////////////////////////////////////////////////////////////////////
// Descript:	flash测试: 作为程序存储器的Flash和作为数据存储器的Flash需分别测试,
//					需修改flash.c中的READY信号线定义.
// In Param:	void
// Out Param:	void
// Return:		void
///////////////////////////////////////////////////////////////////////////////
void Flash_Debug(void)
{
//	Wr_Str_Uart(PORT1, (byte *)0x2f0000, 100);
	
	Fls_Test(0);

//	Wr_Str_Uart(PORT1, (byte *)0x2f0000, 100);

	Wr_Str_Uart(PORT1, " Hi ", 4);

	Fls_Test(1);

//	Wr_Str_Uart(PORT1, (byte *)0x2f0000, 100);
}

#if	SW_VER == SW_NE2
///////////////////////////////////////////////////////////////////////////////
// Descript:	Fm测试: 间隔16字节测试其中一个字节(地址循环变化).
// In Param:	void
// Out Param:	void
// Return:		void
///////////////////////////////////////////////////////////////////////////////
void FM_Debug(void)
{
	void Lcd_Qc_Ok(void);
	void Lcd_Qc_Err(void);
	dword addr;
	dword idx;
	byte value;
	byte offset;

	Uart_WriteByte(PORT3, Fm_Exist());

	offset = 0;
	for (idx=0; idx<FM_SIZE; idx+=0x10)
	{
		addr = idx + offset;
		offset = (offset + 1) % 0x10;

		value = (byte)addr + (byte)(addr>>8) + (byte)(addr>>16);
		if (Fm_WriteByte(addr, value) != OK)
		{
			bellcnt = 200;
			Wr_Str_Uart(PORT3, "write ERROR", 11);
			break;
		}
		if ((idx % 0x4000) == 0)
		{
			bellcnt = 2;
			Wr_Str_Uart(PORT3, "Write...", 8);
			Wait(1000);
		}
	}
	offset = 0;
	for (idx=0; idx<FM_SIZE; idx+=0x10)
	{
		addr = idx + offset;
		offset = (offset + 1) % 0x10;

		value = (byte)addr + (byte)(addr>>8) + (byte)(addr>>16);
		if (Fm_ReadByte(addr) != value)
		{
			bellcnt = 200;
			Wr_Str_Uart(PORT3, "read ERROR", 10);
			break;
		}
	}
	if (idx >= FM_SIZE)
	{
		Lcd_Qc_Ok();
		Wr_Str_Uart(PORT3, "OK OK OK OK", 11);
	}
	else
	{
		Lcd_Qc_Err();
		Wr_Str_Uart(PORT3, "ER ER ER ER", 11);
	}
	while (!Key_Poll_Chk());
}
#endif

///////////////////////////////////////////////////////////////////////////////
// Descript:	键盘调试: 将扫描回的键值发送至串口,含控制锁改变时的值.
// In Param:	void
// Out Param:	void
// Return:		void
///////////////////////////////////////////////////////////////////////////////
void KB_Debug(void)
{
	word key, ctrlKey = 0;
	
	while (1)
	{
	   if (Ktail != Khead)
	   {
	      key = KeyBuffer[Ktail];
	      Ktail++;
	      if (Ktail == KEY_BUFF_SIZE)  
	      	Ktail=0;
	      Uart_WriteByte(PORT1, key);
	   }
	   if (ctrlKey != Get_Scan_Lock())
	   {
	   	ctrlKey = Get_Scan_Lock();
	   	Uart_WriteByte(PORT1, ctrlKey);
	   }
	   GetMainMode();
	}
}

///////////////////////////////////////////////////////////////////////////////
// Descript:	RTC debug
// In Param:	void
// Out Param:	void
// Return:		void
///////////////////////////////////////////////////////////////////////////////
void Rtc_Debug(void)
{
	static byte firstPwrOn;
	
	if (firstPwrOn != 0x55)
	{
		bellcnt = 200;										// 长鸣一声.
		GetSecond()= 0;
		GetMinute()= 0;
		GetHour()  = 0;
		GetDay()   = 1;
		GetMonth() = 1;
		GetYear()  = 4;
		firstPwrOn = 0x55;
	}

	while (1)
	{
		disp_Char_Str("---3456---", 0);
		Wait(500);
		bellcnt = 1;
		disp_Char_Str("   8888   ", 0);
		Wait(500);
		Uart_WriteByte(PORT1, GetSecond());
		Uart_WriteByte(PORT1, GetMinute());
		Uart_WriteByte(PORT1, GetHour()  );
		Uart_WriteByte(PORT1, GetDay()   );
		Uart_WriteByte(PORT1, GetMonth() );
		Uart_WriteByte(PORT1, GetYear()  );
		Uart_WriteByte(PORT3, GetSecond());
		Uart_WriteByte(PORT3, GetMinute());
		Uart_WriteByte(PORT3, GetHour()  );
		Uart_WriteByte(PORT3, GetDay()   );
		Uart_WriteByte(PORT3, GetMonth() );
		Uart_WriteByte(PORT3, GetYear()  );
	}

⌨️ 快捷键说明

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