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

📄 main.c

📁 这个是一个带有IC卡
💻 C
📖 第 1 页 / 共 4 页
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			main.c
** Last modified Date:  2004-09-16
** Last Version:		1.0
** Descriptions:		The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by:			Chenmingji
** Created date:		2004-09-16
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include 	"config.h"
#define __SRC

#include"main.h"

#undef __SRC

#include    "UART0.h"
#include    "I2CINT.h"
#include    "PCF8563.h"
#include    "KEY.h"
#include	"LCM.h"

#include 	"zlg500S_test.h"
#include     "zlg500s.h"
#include     "zlg500s_comm.h"

#include 	"delay.h"
#include    "gprs.h"

#include	"SUM1356.h"



//uint8  yyy;
///////////////////////系统用到的内部RAM的全局变量///////////////////////////
    ////////////////////SUM1356读卡器的数据初始化////////////////////////////////////////
    extern uint8 ReadOut_SUM1356_DataBuf[16];
    extern uint8 WriteIn_SUM1356_DataBuf[16];
    
	////////////////读卡器的数据////////////////////////////////
	extern INT8U DataBfr[16];
	extern INT8U Card_Snr[4];
	extern INT8U TxMode;
	extern INT8U Atq[2];
	extern INT8U Sak;
	
	
	uint8 MI_ProCard_Block4[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	uint8 MI_ProCard_Block5[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	uint8 MI_ProCard_Block6[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	uint8 MI_ProCard_Block8[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	uint8 MI_ProCard_Block9[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	uint8 MI_ProCard_Block10[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	uint8 MI_ProCard_Block12[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	uint8 MI_ProCard_Block62[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
		
	
	
	
	uint8 DataCardKey[6];//这里是我自己定义的,所以不要加extern
	
	uint32 ui32_testval; //在调试过程中用来调试用
	
   ////////////////////Main函数里用到的全局标志量/////////////////////////////
	uint8 volatile ui8_FLG_TransMode;
	//数据传输的标志位。当为1时表示进入数据传输模式
	 

	/////////////////////
	uint8 PIN_TEST_BUF[PINWEISHU]={0,0,0,0,0,0};//用来存放密码值

	struct BaoZhiTimeOut BaoZhiTimeOutListVAL[LNMAX];//


//////////////////////以下为外部NVRAM的地址空间分配'///////////////////

#define 	ADDR_Termilog				0x82000000	//实际使用的地址范围:0x82000000-0x82000653
#define   	ADDR_GuiGeListVAL           0x82000700	//实际使用的地址范围:0x82000700-0x82000713
#define   	ADDR_RecvIndexListVAL      	0x82000720	//实际使用的地址范围:0x82000720-0x82000977


#define     ADDR_AdminHisVAL			0x82000980  //实际使用的地址范围:0x82000980-0x82000a1f
#define   	ADDR_MachHisVAL             0x82000a30  //实际使用的地址范围:0x82000a30-0x82000acf
#define     ADDR_DeliHisVAL             0x82000b00	//实际使用的地址范围:0x82000b00-0x82003fbb


#define     ADDR_ui16_Count_AdmiHis 	0x82004000	//实际使用的地址范围:0x82004000-0x82004001
#define     ADDR_ui16_Count_DeliHis		0x82004002	//实际使用的地址范围:0x82004002-0x82004003
#define     ADDR_ui16_Count_MachHis		0x82004004	//实际使用的地址范围:0x82004004-0x82004005
#define     ADDR_FLG_AdmiHis_OVERFLOW  	0x82004006  //实际使用的地址范围:0x82004006-0x82004007
#define     ADDR_FLG_DeliHis_OVERFLOW  	0x82004008	//实际使用的地址范围:0x82004008-0x82004009
#define     ADDR_FLG_MachHis_OVERFLOW  	0x8200400a  //实际使用的地址范围:0x8200400a-0x8200400b



	
struct StructTermilog 	*  	pTermilogVAL		=	(struct StructTermilog *)			ADDR_Termilog;
struct GuiGeList 	  	* 	pGuiGeListVAL		=	(struct GuiGeList *)				ADDR_GuiGeListVAL;
struct RecvIndexList	*	pRecvIndexListVAL	=	(struct RecvIndexList	*)			ADDR_RecvIndexListVAL;
struct tagAdminHistoryFormat * pAdminHisVAL		=	(struct tagAdminHistoryFormat *)	ADDR_AdminHisVAL;
struct tagMachineHistoryFormat	* pMachHisVAL	=	(struct tagMachineHistoryFormat *)	ADDR_MachHisVAL;
struct tagDeliveryHistoryFormat  *pDeliHisVAL	=	(struct tagDeliveryHistoryFormat  *)ADDR_DeliHisVAL;

uint16 * pui16_Count_AdmiHis=(uint16 *)ADDR_ui16_Count_AdmiHis;
uint16 * pui16_Count_DeliHis=(uint16 *)ADDR_ui16_Count_DeliHis;
uint16 * pui16_Count_MachHis=(uint16 *)ADDR_ui16_Count_MachHis;

uint8  * pFLG_AdmiHis_OVERFLOW=(uint8 *)ADDR_FLG_AdmiHis_OVERFLOW;
uint8  * pFLG_DeliHis_OVERFLOW=(uint8 *)ADDR_FLG_DeliHis_OVERFLOW;
uint8  * pFLG_MachHis_OVERFLOW=(uint8 *)ADDR_FLG_MachHis_OVERFLOW;


void system_init(void)
{	
	int i;
	
	Lcdinit();					//液晶屏初试化
    Lcdclear();					//清屏
	beep_init();				//蜂鸣器初试花
	Init_Flash();				//初始化FLASH
	print_init();				//打印机初始化
	I2C_Init(400000);			//I2C初始化
	Init_SUM1356_CheckPIN();	//射频卡初始化

	Time0Init();				//定时器初试化
	IRQEnable();
	
	//////////////////////////欢迎词///////////////////////////////////
	wrzw16x16_string(0,1,"上海速致电子科技",8);	
	for(i = 9; i > 0; i--)
	{
		delay_500ms();
		wryw16x8s(14,3,i);	
	}
	
	return;
}

#define GPRS_DEBUG
int main (void)

{
    //系统初始化    
    uint32 m_i,m_k,m_j;
    Delay_n100MS(20);  
      
#ifdef LCD_DEBUG
	lcd_debug();
#endif
#ifdef BEEP_DEBUG
	beep_debug();
#endif
#ifdef KEY_DEBUG
	key_debug();
#endif
#ifdef FLASH_DEBUG
	flash_debug();
#endif
#ifdef TIME_DEBUG
	time_debug();
#endif
#ifdef UART0_DEBUG
	uart0_debug();
#endif
#ifdef PRINT_DEBUG
	print_debug();
#endif
#ifdef SUM1356_DEBUG
	sum1356_debug();
#endif
#ifdef GPRS_DEBUG
	gprs_debug();
#endif

	system_init();
	  	
   	///////////////程序测试////////////////////
   //	PlaySound_2wei(88);
   	
   	PCF8563_WrIn_databuf[2] = 0x09;		//PCF8583_WrIn_databuf[3]:秒,BIT7为1时数据无效,为0时数据有效
	PCF8563_WrIn_databuf[3] = 0x00;		//PCF8583_WrIn_databuf[4]:分
	PCF8563_WrIn_databuf[4] = 0x00;		//PCF8583_WrIn_databuf[5]:时
	PCF8563_WrIn_databuf[5] = 0x01;		//PCF8583_WrIn_databuf[6]:日
	PCF8563_WrIn_databuf[6] = 0x01;		//PCF8583_WrIn_databuf[7]:周
	PCF8563_WrIn_databuf[7] = 0x01;		//PCF8583_WrIn_databuf[8]:月
	PCF8563_WrIn_databuf[8] = 0x00;		//PCF8583_WrIn_databuf[9]:年
		
	///////////////////程序全局变量的初始化/////////////////////////////
	
	
	for(m_i=0;m_i<16;m_i++)
	{
		MI_ProCard_Block4[m_i]=0;
		MI_ProCard_Block5[m_i]=0;
		MI_ProCard_Block6[m_i]=0;
		MI_ProCard_Block8[m_i]=0;
		MI_ProCard_Block9[m_i]=0;
		MI_ProCard_Block10[m_i]=0;
		MI_ProCard_Block12[m_i]=0;
		MI_ProCard_Block62[m_i]=0;
		
	}
	
	for(m_i=0;m_i<LNMAX;m_i++)
	{
		BaoZhiTimeOutListVAL[m_i].FLG_TimeOut=0;
		BaoZhiTimeOutListVAL[m_i].FLG_record=0;
	}
		
	for(m_i=0;m_i<PINWEISHU;m_i++)
	{
		PIN_TEST_BUF[m_i]=0;
	}

   	        
    //主程序的主循环 
    

   	 /////////////////////////读卡模块初始化/////////////////////////////////
/*  	DisablePCF8563_IIC_INT();//禁止PCF8563的数据读取
   	
   	
   	ZLG500S_COMM_Init();	
   	Time0Init();	
        
    
    DataCardKey[0] = 0xff;
    DataCardKey[1] = 0xff;
    DataCardKey[2] = 0xff;
    DataCardKey[3] = 0xff;
 	DataCardKey[4] = 0xff;
 	DataCardKey[5] = 0xff;
 
  	PCDLoadKey(KEYA,0,DataCardKey); 
  	
  	EnablePCF8563_IIC_INT();//使能PCF8563的数据读取
  	
  	
  	*/
  	/*
  	
  	WriteIn_SUM1356_DataBuf[0]='1';
  	WriteIn_SUM1356_DataBuf[1]='2';
  	WriteIn_SUM1356_DataBuf[2]='3';
  	WriteIn_SUM1356_DataBuf[3]='4';
  	
  	while(1)
  	{
  		if(Check_SUM1356_IN_ATAN()==0)//当
  		{
  			
  			Search_SUM1356();  			
  			Write_SUM1356_Block(WriteIn_SUM1356_DataBuf,4);
	  		if(Read_SUM1356_Block(ReadOut_SUM1356_DataBuf,4))
	  		{
	  			while(1);
	  		}   			
    	} 			
  		
  	}
  	*/
  	
  	while(1)
  	{
  		 ScanKey();
  		
  	//	if(yyy==KEY_0)
  		//{
  		//	ScanKey();
  		//	ScanKey();
  		//}
  	}
   	while(1)					//主程序循环体			
   	{	  
   		ShowMainPic();						//显示主界面
   		ReadAndDisplayTime();				//读取时间并且显示
   		CheckAndDisplayOutTimeIfo();		//检查超时信息,并进行显示
   		DealWithMifareCard();
   		   		
   	} //while(1) 
    return 0;//main
    
}

void ReadAndDisplayTime(void)
{
	
	ReadTimeFromPCF8563(PCF8563_RdOut_databuf);
	Delay_n10MS(1);//延时40毫秒
	ChangePCF8563_BCD_to_HEX(PCF8563_RdOut_databuf);
		
	wryw16x8_2wei(0,2,20);
	wryw16x8_2wei(2,2,PCF8563_RdOut_databuf[6]);//年
	wryw16x8(4,2,"-");
	wryw16x8_2wei(5,2,PCF8563_RdOut_databuf[5]);//月
	wryw16x8(7,2,"-");
	wryw16x8_2wei(8,2,PCF8563_RdOut_databuf[3]);//日
			
	wryw16x8_2wei(0,3,PCF8563_RdOut_databuf[2]);//时
	wryw16x8(2,3,":");
	wryw16x8_2wei(3,3,PCF8563_RdOut_databuf[1]);//分
	wryw16x8(5,3,":");
	wryw16x8_2wei(6,3,PCF8563_RdOut_databuf[0]);//秒

	
}
void CheckAndDisplayOutTimeIfo(void)
{
	
   		
}

void ShowMainPic(void)
{
	wrzw16x16_string(4,0,"已用",2);
	wrzw16x16_string(0,0,"过期",2);
	//wryw16x8_2wei(12,0,TermilogVAL.StoreProductNum);
	wrzw16x16_string(1,1,"请刷卡。。。",6);   		
}
void DealWithMifareCard(void)
{
	while(Check_SUM1356_IN_ATAN()==0)//当检测到有卡的时候
	{//当数据传输模式为正常工作模式的时候,进行读卡操作
		Search_SUM1356();
		Read_SUM1356_Block(DataBfr,1);				
   		if((DataBfr[0]=='W')&&(DataBfr[1]=='L')&&(DataBfr[2]=='Z')&&(DataBfr[3]=='Z'))
		{//如果这个卡是有效卡,则进入卡型号的判别模式。
						
			Read_SUM1356_Block(DataBfr,4);								//读块4	
			//读取这个卡的类型是否为管理员,送货,发货卡,标签卡
			if(DataBfr[0]==DELI_CARD)//如果是送货员卡
			{//////////////////送货员的情况处理////////////////////
				uint32 ui32_ID;
				uint32 ui32_SXdate; //失效的日期
				uint32 ui32_XTdate; //系统当前日期
				ui32_ID=
				(((uint32)DataBfr[1])*256*256*256)+(DataBfr[2]*256*256)+(DataBfr[3]*256)+DataBfr[4];

⌨️ 快捷键说明

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