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

📄 timmer.c

📁 一款收款机C源代码!因为是几年前的代码了
💻 C
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************
*								Timer.c
*
* Create at:	2003.4
* Create by:	Chen Huahai
* Simple Descripe:	
*************************************************************************/
#include 	<string.h>
#include		"ecrsys.h"
#include		"data.h"
#include		"sysdata.h"
#include 	"ftype.h" 
#include    "disp.h"
#include 	"lcm.h"

extern	volatile word rs0_In;
extern	volatile word rs0_Out;
extern	volatile byte rs0_Buff[];
extern	volatile byte wr0_In ;
extern	volatile byte wr0_Out;
extern	volatile byte wr0_Buff[];
extern	volatile byte uart0_Sending ;
extern	volatile word rs1_In;
extern	volatile word rs1_Out;
extern	volatile byte rs1_Buff[];
extern	volatile byte wr1_In ;
extern	volatile byte wr1_Out;
extern	volatile byte wr1_Buff[];
extern	volatile byte uart1_Sending ;
extern	volatile word rs2_In;
extern	volatile word rs2_Out;
extern	volatile byte rs2_Buff[];
extern	volatile byte wr2_In ;
extern	volatile byte wr2_Out;
extern	volatile byte wr2_Buff[];
extern	volatile byte uart2_Sending ;
extern	volatile word rs3_In;
extern	volatile word rs3_Out;
extern	volatile byte rs3_Buff[];
extern	volatile byte wr3_In ;
extern	volatile byte wr3_Out;
extern	volatile byte wr3_Buff[];
extern	volatile byte uart3_Sending ;
extern	volatile word rs4_In;
extern	volatile word rs4_Out;
extern	volatile byte rs4_Buff[];
extern	volatile byte wr4_In ;
extern	volatile byte wr4_Out;
extern	volatile byte wr4_Buff[];
extern	volatile byte uart4_Sending ;

byte prnThPause = 0;

byte pause_Prn = 0;
word succesivePrnTime = 0;
word stopPrnTime = 0;
byte currCloseFlag = 0;
word currCloseTime = 0;

#define		STOP_TIME			20000
#define		PRN_TIME			60000
//#define		STOP_TIME			1000
//#define		PRN_TIME			3000
#define		CURR_CLOSE_TIME		500

/******************************************************************************
* Describe:	Timer A0 initial function, use for system clocker. inteval 1ms
* Input :	void
* Output:	void
* return:	void
******************************************************************************/
void InitialSysTimer(void)
{
	// set timer A0 work mode
	ta0mr = 0x40;						// f8, disable gate, timer mode
	// set timer A0 initial value
	ta0 = 1000 * FOSC / 8;				// 10M xtal, 800ns * 1250 = 1 ms
	// enable timer A0 downflow interrupt
	ta0ic = 0x03;
	ta0s = 1;							// Start timer A0
}

/******************************************************************************
* Describe:	Timer A0 (System Timer) ISR
* Input :	void
* Output:	void
* return:	void
******************************************************************************/
void SysTimer(void)
{
//	static word timesCount = 0;
   static byte sysTimeCnt = 0;

//	wdts = 0xff;						/* for the ISP function, cannot use the Watch-Dog function. */

	#ifdef HW_PRN
	if ( PRN_TH == 1 )									//Temperature high.
	{
		STB1 = STB2 = 1;			// Off all STB segment.
		if (prnThPause == 0)
		{
			prnThPause = 1;
			disp_Char_Str("PRN COOL -",0);
		}
	}
	else if (prnThPause == 1)
	{
		prnThPause = 0;
		// display print protect
		Insert_Char(' ', 0);
		Insert_Char(' ', 1);
		Insert_Char(' ', 2);
		Insert_Char(' ', 4);
		Insert_Char(' ', 5);
		Insert_Char(' ', 6);
		Insert_Char(' ', 7);
		Insert_Num(0, 8);
		Insert_Num(0, 9);
	}

	// check succesive print time
	if ( currCloseFlag == 1 )
	{
		succesivePrnTime++;
		if (succesivePrnTime > PRN_TIME)
		{
			STB1 = STB2 = 1;		// Off all STB segment.
			pause_Prn = 1;
			succesivePrnTime = 0;
			stopPrnTime = 0;
			// display print protect
			Insert_Char('P', 0);
			Insert_Char('R', 1);
			Insert_Char('N', 2);
			Insert_Char(' ', 3);
			Insert_Char('C', 4);
			Insert_Char('O', 5);
			Insert_Char('O', 6);
			Insert_Char('L', 7);
			Insert_Char(' ', 8);
			Insert_Char(' ', 9);
		}
		currCloseTime = 0;
	}
	else if (pause_Prn != 1)
	{
		currCloseTime++;
		if (currCloseTime > CURR_CLOSE_TIME)
		{
			if (succesivePrnTime > CURR_CLOSE_TIME)
				succesivePrnTime -= CURR_CLOSE_TIME;
			else
				succesivePrnTime = 0;
			currCloseTime = 0;
		}
	}
	else
	{
		currCloseTime = 0;
		stopPrnTime++;
		if (stopPrnTime % 1000 == 0)
			Insert_Num((STOP_TIME - stopPrnTime)/1000, 9);
		if (stopPrnTime > STOP_TIME)
		{
			// display print protect
			Insert_Char(' ', 0);
			Insert_Char(' ', 1);
			Insert_Char(' ', 2);
			Insert_Char(' ', 4);
			Insert_Char(' ', 5);
			Insert_Char(' ', 6);
			Insert_Char(' ', 7);
//			Insert_Num(0, 8);
//			Insert_Num(0, 9);
			Insert_Num(0, 7);
			Insert_Num(0, 8);
			pause_Prn = 0;
			stopPrnTime = 0;
			succesivePrnTime = 0;
		}
	}

	if ( Prn_Stat == PRN_IDLE )
	{
/*	Note: Temporary for the sample machine to U.K., need modify this function later. 2003-09-13 15:59 */
		if ( sysflag->fl_wmotor )
		{
//			WMTOR = 0;									/*OFF the windmotor */
		}
/*	Note: Temporary for the sample machine to U.K., need modify this function later. 2003-09-13 15:59 */
		prn_schedule();							// printer task schedule
	}
	#endif

   sysTimeCnt++;
   if (sysTimeCnt >= 5)									// 每5ms执行一次的任务.
   {
   	sysTimeCnt = 0;
   	Comm_ChkTimeOut();
   }

    #ifdef VFD_OLD
	Vfd_Flush();
    #endif
    
	if (g_sysCount != 0)						// system delay count
	{
		g_sysCount--;
	}

	if (delay_cnt<=10000)
		delay_cnt++;

	if(TS_timercnt >= 5)//  100ms
		TS_timercnt --;

	#ifdef HW_PRN
	prn_schedule();
	#endif

	{
		void Ts_KeyOffChk(void);
		Ts_KeyOffChk();
	}

//	// 每3s处理一次.
//	timesCount++;
//	if (timesCount > 3000)
//	{
//		timesCount = 0;
//		Sys_ChkBatteryAbnormal();
//	}
	if(wmtor_timmer != 0)
	{
		if(-- wmtor_timmer == 0)
			WMTOR = 0;
	}

	if ( (wr0_In != wr0_Out) && ( uart0_Sending == 0 ) )	/*Port 0 checking*/
	{
		Uart_Transfer(PORT0);
	}
	if ( (wr1_In != wr1_Out) && ( uart1_Sending == 0 ) )	/*Port 1 checking*/
	{
		Uart_Transfer(PORT1);
	}
	if ( (wr2_In != wr2_Out) && ( uart2_Sending == 0 ) )	/*Port 2 checking*/
	{
		Uart_Transfer(PORT2);
	}
	if ( (wr3_In != wr3_Out) && ( uart3_Sending == 0 ) )	/*Port 3 checking*/
	{
		Uart_Transfer(PORT3);
	}
	if ( (wr4_In != wr4_Out) && ( uart4_Sending == 0 ) )	/*Port 4 checking*/
	{
//		DEBUG_TMP(bellcnt = 0xff);
		Uart_Transfer(PORT4);
	}
	if ( uc_kp_wait_timer != 0 )
	{
		if ( --uc_kp_wait_timer == 0 )
		{
			fl_kp_tm_out = 1;
		}
	}
	if ( port_use_print == PRN_PORT )	/*kp connected in port 2 */
	{
		if ( handshake_method == HW_SHAKE )
		{
			if ( DSR == 0 )
			{
				fl_kp_rp_busy = 1;					  /*kp is busy */
				uc_kp_wait_timer = KP_WAIT_TM;
			}
			else											  /*kp is free */
			{
				fl_kp_rp_busy = 0;
				uc_kp_wait_timer = 0;	/* no need spy the kp wait time */
			}
		}
	}
}

/******************************************************************************
* Describe:WatchDog Timer initial, Please refer to Hardware handbook Page98
*			Note:	This is a non-maskable interrupt
* Input :	void
* Output:	void
* return:	void
******************************************************************************/
void InitialWatchDog(void)
{
	word i;

	return;
	wdc7 = 1;			// 0 is 16 division, 1 is 128 division, and MCU run in fc, 2 division regardless
	prc0 = 1;
	cm06 = 1;			// when watchdog timer downflow occur, 1 will reset MCU, 0 will due to WDT interrupt
	prc0 = 0;
	wdts = 0xff;		// start watchdog timer
}

/******************************************************************************
* Describe:WatchDog Timer ISR, 
*			Note:	This is a non-maskable interrupt
* Input :	void
* Output:	void
* return:	void
******************************************************************************/
void WdtIsr(void)
{
//	word i;
//	
//	while (1)
//	{
//		LCD_Back(ON);
//		OpenBuzzer();
//		for (i=0; i<0x7fff; i++);
//		LCD_Back(OFF);
//		CloseBuzzer();
//		for (i=0; i<0x7fff; i++);
//	}
}

void PwrDownISR(void);

long softRtcAddr;
/******************************************************************************
* Describe:	Timer A1 initial function, use to Soft-Real-Time-Clocker, inteval 0.5s
*			use sub-clock
* Input :	void
* Output:	void
* return:	void
******************************************************************************/
void InitialRtcTimer(void)
{
	byte i;
//	const byte day_of_month_int[12] = {31,28,31,30,31,30,31,31,30,31,30,31};

	// open sub clocker (32.768k)
	prc0 = 1;
	cm04 = 1;				// enable Xc
//	for (i=0; i<100; i++);	// wait Xc stable
//	cm03 = 0;				// set Xcin-Xcout low driver
	prc0 = 0;

	SOFT_TIME_CNT = 0;
	*(SOFT_day_of_month + 0) = 31;
	*(SOFT_day_of_month + 1) = 28;
	*(SOFT_day_of_month + 2) = 31;
	*(SOFT_day_of_month + 3) = 30;
	*(SOFT_day_of_month + 4) = 31;
	*(SOFT_day_of_month + 5) = 30;
	*(SOFT_day_of_month + 6) = 31;
	*(SOFT_day_of_month + 7) = 31;
	*(SOFT_day_of_month + 8) = 30;
	*(SOFT_day_of_month + 9) = 31;
	*(SOFT_day_of_month + 10) = 30;
	*(SOFT_day_of_month + 11) = 31;
	
//	for (i=0; i<12; i++)
//	{
//		*(SOFT_day_of_month + i) = day_of_month_int[i];
//	}
	
	// copy Timer ISR to Sram 0x2500~0x26ff
	asm("mov.l #_RtcTimer, _softRtcAddr");
//	memcpy((byte *)0x2500, (byte *)softRtcAddr, 0x200);
	memcpy((byte *)0x2500, (byte *)softRtcAddr, 0x130 + 0x10);

	// copy PowerDown Isr to RAM 0x2400~0x24FF
	asm("mov.l #_PwrDownISR, _softRtcAddr");
//	memcpy((byte *)0x2400, (byte *)softRtcAddr, 0x100);
	memcpy((byte *)0x2400, (byte *)softRtcAddr, 8 + 0x10);

	// copy interrupt Vector Table to Sram 0x2700~0x27ff, 
	// and modify the Timer A1 ISR Enter address.
	memcpy((byte *)0x2700, (byte *)0xfffd00, 0x100);
	asm("mov.l #2500h, 2734h");			// RTC ISR
	asm("mov.l #2400h, 277Ch");			// Power Down ISR
	asm("ldc	#2700H,intb");					// modify it in Powerdown routine

	// set exit Stop/Wait mode interrupt level, and disable other interrupt
	rlvl = 0x0;

	// copy program to Sram 0x2000~0x22ff
	asm("mov.l #_SoftRtcSram, _softRtcAddr");
//	memcpy((byte *)0x1F00, (byte *)softRtcAddr, 0x400);
	memcpy((byte *)0x1F00, (byte *)softRtcAddr, 0x28a + 0x10);

	prc0 = 1;
//	cm03 = 0;				// set Xcin-Xcout low driver
	prc0 = 0;

	// set timer A1 work mode
	ta1mr = 0xc0;						// fc32, disable gate, timer mode
	// set timer A1 initial value
	ta1 = (0.5 / 1) * 1024 - 1;
	// enable timer A1 downflow interrupt
	ta1ic = 0x04;
	ta1s = 1;							// Start timer A1

//	Vfd_CopyFuncToRam();									// 0x1e00 ~ 0x1eff

	// copy program to Sram 0x1e00 ~ 0x1eff
	asm("mov.l #_MainSramWaitPFO, _softRtcAddr");
	memcpy((byte *)0x1e00, (byte *)softRtcAddr, 0x100);
}
/******************************************************************************
* Describe:soft rtc function, run it when Power down.
*			We can detect Next Power ON in External Interrupt, and close buzzer
* Input :	void
* Output:	void
* return:	void
******************************************************************************/
void SoftRtcSram(void)
{
	volatile byte powerOnCount = 0;
	byte i;
	
//	Vfd_Cls();

	int0ic = 0;
	
	ta3mr = 0;
	ta3 = 0;
	ta3ic = 0;
	ta3s = 0;
	adcon0 = 0x0;
	adcon1 = 0x00;
	adcon2 = 0x0;
	ta4mr = 0;
	ta4 = 0;
	ta4ic = 0;
	ta4s = 0;
	ta2mr = 0;
	ta2 = 0;
	ta2ic = 0;
	ta2s = 0;
	dm0ic = 0;
	dm0sl = 0;
	//--timmer
	ta0mr = 0;
	ta0 = 0;
	ta0ic = 0;
	ta0s = 0;
//	tb0mr = 0;
//	tb0 = 0;
//	tb0ic = 0;
//	tb0s = 0;
//	tb1mr = 0;
//	tb1 = 0;
//	tb1ic = 0;
//	tb1s = 0;
	tb2mr = 0;
	tb2 = 0;
	tb2ic = 0;
	tb2s = 0;
//	tb3mr = 0;
//	tb3 = 0;

⌨️ 快捷键说明

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