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

📄 main.c.bak

📁 上海大宇指纹机软件qqqfwefgergr
💻 BAK
📖 第 1 页 / 共 2 页
字号:
	T1IR = 0x01;
	VICVectAddr = 0x00;
	VICIntEnable = 0x8030;		//VICIntEnable = 0x8070;
}
/*****************************************************************************************
** 函数名称 : IRQEint1()
** 函数功能 : 外部中断口P0.14,中断处理程序,
**      	   
** 入口参数 : 无
** 出口参数 : 无
*****************************************************************************************/
void __irq IRQEint1(void)
{	uint32 StateBuf;
	VICIntEnable = 0x00;
	IO0DIR = IO0DIR|Row2;
	StateBuf = IO0SET;
	if((StateBuf&Row2) == 0)
	IO0SET = IO0SET|Row2;
	else	
	IO0CLR = IO0CLR|Row2;
	/*while((EXTINT&0x02)!=0)
	{	EXTINT = 0x02;
	}*/
	EXTINT = 0x02;
	VICVectAddr = 0x00;
	VICIntEnable = 0x8030;
}
/*****************************************************************************************
** 函数名称 : LedStateClew()
** 函数功能 :  
** 入口参数 : 0=正常状态,1=平时按键,2=密码无效或超长,3=密码有效,4=开锁
**             5=进入编程,6=编程确认,7=退出编程,8=重新输入提示,9=报警
** 出口参数 : 无
*****************************************************************************************/
void LedStateClew(uint8 Event)
{
	BStartLedGlintTime=0;
	TempVar_TimeGlintCnt=0;
	LedEvent_TimeBuzzerCnt=Event;
	switch(Event)
	{
	case 0:
	case 2:
	case 8:/*红秒闪,绿灭*/
		BStartLedGlintTime=1;
		break;
	case 1:/*红亮,绿灭*/
		BStartLedGlintTime=1;
       	RedLedOn();
		GreenLedOff();
		break;
	case 3:
	case 4:/*红灭,绿亮*/
		RedLedOff();
		GreenLedOn();
		break;
	case 5:/*红亮,绿快闪*/
		BStartLedGlintTime=1;
		break;
	case 6:/*红亮,绿亮*/
        	RedLedOn();
		GreenLedOff();
		break;
	case 7:/*红灭,绿灭*/
    	      RedLedOff();
		GreenLedOff();
		break;
	case 9:/*红慢闪,绿灭*/
		BStartLedGlintTime=1;
		break;
	}
}
/*****************************************************************************************
** 函数名称 : BuzzerStateClew()
** 函数功能 :  
** 入口参数 : 1=平时按键,2=密码无效或超长,3=密码有效,4=开锁
**             5=进入编程,6=编程确认,7=退出编程,8=重新输入提示,9=报警
** 出口参数 : 无
*****************************************************************************************/
void BuzzerStateClew(uint8 Event)
{	BuzzerEvent_RevSameDatCnt=Event;
	BStartBuzzerTime = 1;
	switch(BuzzerEvent_RevSameDatCnt)
	{
	case 9://连续长鸣
		//报警可解除
		BStartBuzzerTime=1;
		if(BStopCheck)
		{	BStartBuzzerTime=0;
		    	BuzzerCnt_DecodeDatCnt=0;
			BeepOff();
			AlarmOff();
		}
		break;
	case 10:
		BStartBuzzerTime=1;
		if(BStopCheckBuz)
		{	BStartBuzzerTime=0;
		  	BuzzerCnt_DecodeDatCnt=0;
			BeepOff();
			AlarmOff();
		}
		break;
	case 0:
		BStartBuzzerTime=0;
		BuzzerCnt_DecodeDatCnt=0;
		BeepOff();
		AlarmOff();
		BStartBuzzerTime=1;
		break;
	}
}
/*****************************************************************************************
** 函数功能 : 串行通信开始	   
*****************************************************************************************/
/*****************************************************************************************
** 函数名称 : IRQUart0()
** 函数功能 : 串口初始化,设置为8位数据位,1位停止位,无奇偶校验,波特率为115200
** 入口参数 : 
** 出口参数 :
*****************************************************************************************/
/*int8 Uart0Init(uint32 Baud,UARTMODE Set)
{	uint32 Bak;
	//参数过滤
	if ((Baud == 0)||(Baud>115200)) return(0);
	if ((Set.DataBit<5)||(Set.DataBit>8)) return(0);
	if ((Set.StopBit == 0)||(Set.StopBit>2)) return(0);
	if (Set.Parity>4) return(0);
	//设置串口波特率
	U0LCR = 0x80;
	Bak = (Fpclk>>4)/Baud;
	U0DLM = Bak>>8;
	U0DLL = Bak&0xff;
	//设置串口模式
	Bak = Set.DataBit-5;
	if (Set.StopBit == 2) Bak|=0x04;
	if (Set.Parity!=0)
	{	Set.Parity = Set.Parity-1;
		Bak |=0x08;
	}
	Bak |= Set.Parity<<4;
	U0LCR = Bak;
	return (1);
}*/

/*****************************************************************************************
** 函数名称 : IRQUart0()//GetDatFromFingerprintModule()
** 函数功能 : 从串口接收1字节数据,使用查询方式接收
**      	   
** 入口参数 : 无
** 出口参数 : 无
*****************************************************************************************/
void Uart0Init(void)
{	uint16 Fdiv;
	U0LCR=0x83;
	Fdiv=(Fpclk/16)/UartBps;
	U0DLM=Fdiv/256;
	U0DLL=Fdiv%256;
	U0LCR=0x03;
}
uint8 Uart0GetByte(void)
{	uint8 RcvDat;
	while((U0LSR&0x01)==0);
	RcvDat=U0RBR;
	return (RcvDat);
}
void Uart0GetStr(uint8 *s,uint32 n)
{	for (;n>0;n--)
	{	*s++=Uart0GetByte();
	}
}
void Uart0SendByte(uint8 Dat)
{	U0THR=Dat;
	while((U0LSR&0x40)==0);
}
void Uart0SendStr(uint8 const *Str)
{	while(1)
	{	if(*Str=='\0') break;
		Uart0SendByte(*Str++);
	}
}

/*uint8 UnpackRevDat(uint8 Cmd)
{	//uint8 i;
	uint8 Dat[32];
	uint8 BackCode;
//	PtRevOrSendDat=&RevDatBuf[0];
	VICIntEnable=0x00;
	switch(Cmd)
	{	case 0x02:
			Uart0GetStr(Dat,15);
			BackCode=Dat[7];
			for(i=0;i<15;i++)
			{*PtRevOrSendDat++=Dat[i];}
			SendDataLenth=15;
			break;
		case 0x03||0x04:
			Uart0GetStr(Dat,12);
			BackCode=Dat[7];
			for(i=0;i<15;i++)
			{*PtRevOrSendDat++=Dat[i];}
			SendDataLenth=12;
			break;
		case 0x0f:
			break;
		case 0x16:
			break;
		default:
			{	Uart0GetStr(Dat,12);
				BackCode=Dat[7];
				for(i=0;i<15;i++)
				{*PtRevOrSendDat++=Dat[i];}
				SendDataLenth=10;
				break;
			}
	}
	VICIntEnable=0x8030;
	if(RevDatBuf)
		{return(1);}     
	else return (0);
}*/	
/*****************************************************************************************
** 函数名称 : StartSeriSendDat()
** 函数功能 : 启动串口发送数据,并等待发送完毕,使用查询方式
**      	   
** 入口参数 : 
** 出口参数 : 无
*****************************************************************************************/
/*void StartSeriSendDat()
{	uint8 i;
	PtRevOrSendDat=&RevDatBuf[0];
	i=SendDataLenth;
	for(; i>0; i--)
	{	Uart0SendByte(*PtRevOrSendDat++);}	//等待数据发送完毕
}*/
//串行通信结束****************************************************************************
//指纹模快子程序**************************************************************************
/*****************************************************************************************
** 函数名称 : 
** 函数功能 : 使用查询方式从串口接收应答包数据接收,并应答包进行解包
** 入口参数 : Cmd	指令所对应的应答参数     	   
** 0x02 将ImageBuffer中的原始图像生成指纹特征文件存于Buffer1或Buffer2返回面积上下左右边界5个参数5Byte
** 0x03 精确比对Buffer1与Buffer2中的特征文件,返回比对得分参数2Byte
** 0x04 以Buffer1或Buffer2中的特征文件搜索整个或部分指纹库,搜索到返回页码2Byte
** 0x0		   
** 出口参数 : 1为初始化成功,0为初始化失败
*****************************************************************************************/
/*void Uart0RecStr(uint8 Lenth)
{	PtRevOrSendDat=&RevDatBuf[0];
	SendDataLenth=Lenth;
	for (; Lenth>0; Lenth--)
	{	 *PtRevOrSendDat++=Uart0GetByte();}
}*/

/*uint8 UnpackRevDat(uint8 Cmd)
{	uint8 i;
	uint8 BackCode;
	VICIntEnable=0x00;
	PtRevOrSendDat=&RevDatBuf[0];   
	switch(Cmd)
	{	case 0x02:
			for (i=0;i<15;i++)
			{	*PtRevOrSendDat++=Uart0GetByte();
				SendDataLenth=15;}
			break;
		case 0x03||0x04:
			for (i=0;i<12;i++)
			{	*PtRevOrSendDat++=Uart0GetByte();
				SendDataLenth=12;}
			break;
		case 0x0f:
			break;
		case 0x16:
			break;
		default:
			for (i=0;i<10;i++)
			{	*PtRevOrSendDat++=Uart0GetByte();
			SendDataLenth=10;}
			break;
	}
	for (i=0;i<10;i++)
			{	*PtRevOrSendDat++=Uart0GetByte();
			SendDataLenth=10;}
	BackCode=RevDatBuf[7];
	VICIntEnable=0x8030;
	if(RevDatBuf)
		{return(1);}     
	else return (0);
}*/
/*****************************************************************************************
** 函数名称 : PackSendDat()
** 函数功能 : 对要发送的命令打包    	   
** 入口参数 : PackLenth 包长度,Cmd 指令,
**		   ParaType-需传递的参数类型:
**		    	0 无参数需传递;
**			1 需传递1个缓冲区号(则取Parameter最低字节);
**			2 需传递2个缓冲区号(则取Parameter最低字);
**			3 需传递1个缓冲区号及页长(则取Parameter最低3字节);
**			4 需传递1个缓冲区号与模板号(则取Parameter最低3字节);
**			5 需传递模板号或起始页码(则取Parameter最低字);
**			6 需传递配置表(则取Parameter[xx xx xx 00],再发[00 00 00 00]);
**			7 需传递安全等级(则取Parameter最低字节);
**			8 需传递握手口令(则取Parameter);
**			9 需传递闪灯参数(则取Parameter最低字);
**		    ParaStartPage-起始页;=StartPage
**		    Parameter-需传递的参数(取整个或一部分);=PageNum
** 出口参数 :  无
*****************************************************************************************/
void PackSendDat(uint16 PackLenth, uint8 Cmd,uint8 ParaType, uint16 ParaStartPage, uint32 Parameter)
{	uint8 i;
	uint8 CheckSum;
	CheckSum=0;
	AckPackLenthBuf=0;
	SendDataLenth=0;
	RevDataLenth=0;
	RevDatCnt=0;
	RevEndFlag=0;
	PackCaput=0;
	PtRevOrSendDat=&RevDatBuf[0];
	for(i=0;i<(sizeof(RevDatBuf)-1);i++)
	{*(PtRevOrSendDat+i)=0x00;}
	//for(i=0,i<16,i++)
	//{	*(PtRevOrSendDat+1)=0x00;}
	//放包头
	*PtRevOrSendDat++=0xa5;		
	SendDataLenth++;
	*PtRevOrSendDat++=0xa5;
	SendDataLenth++;
	*PtRevOrSendDat++=0xcc;
	SendDataLenth++;
	*PtRevOrSendDat++=0x33;
	SendDataLenth++;
	//放包标识
	*PtRevOrSendDat++=0x1;
	SendDataLenth++;
	CheckSum+=0x01;
	//放包长度
	*PtRevOrSendDat++=(uint8)((PackLenth&0xff00)>>8);
	*PtRevOrSendDat++=(uint8)(PackLenth&0x00ff);
	CheckSum+=(uint8)((PackLenth&0xff00)>>8);
	CheckSum+=(uint8)(PackLenth&0x00ff);
	SendDataLenth+=2;
	//放指令
	*PtRevOrSendDat++=(int8)(Cmd&0x00ff);
	SendDataLenth++;
	CheckSum+=(int8)(Cmd&0x00ff);
	 switch(ParaType)		//以下程序段还需要更改
	{
	case 0://无参数需传递
		break;
	/*case 1://需传递1个缓冲区号(则取Parameter最低字节)
	case 7://需传递安全等级(则取Parameter最低字节)
		*PtRevOrSendDat++=(uint8)(Parameter&0x000000ff);
		CheckSum+=(uint8)(Parameter&0x000000ff);
		SendDataLenth++;
		break;
	case 2://需传递2个缓冲区号(则取Parameter最低字)
	case 9://需传递闪灯参数(则取Parameter最低字)
		*PtRevOrSendDat++=(uint8)((Parameter&0x0000ff00)>>8);
		*PtRevOrSendDat++=(uint8)(Parameter&0x000000ff);
		CheckSum+=(uint8)((Parameter&0x0000ff00)>>8);
		CheckSum+=(uint8)(Parameter&0x000000ff);
		SendDataLenth+=2;
		break;
	case 3://需传递1个缓冲区号及页长(起始页码默认为0000)(则取Parameter最低3字节);
		for(i=0;i<2;i++)
		{CheckSum+=(uint8)((ParaStartPage&(0x0000ff00>>(8*i)))>>(8-8*i));}
		JudgeAndCoding(2,Cmd,5,ParaStartPage);
		PtRevOrSendDat+=RecordInputCondit_CodingDatCnt;
		SendDataLenth+=RecordInputCondit_CodingDatCnt;
		CmdPackParaLenth+=RecordInputCondit_CodingDatCnt;
		RecordInputCondit_CodingDatCnt=0;
		for(i=0;i<3;i++)
		{CheckSum+=(uint8)((Parameter&(0x00ff0000>>(8*i)))>>(16-8*i));}
		JudgeAndCoding(2,Cmd,ParaType,Parameter);
		PtRevOrSendDat+=RecordInputCondit_CodingDatCnt;
		SendDataLenth+=RecordInputCondit_CodingDatCnt;
		CmdPackParaLenth+=RecordInputCondit_CodingDatCnt;
		RecordInputCondit_CodingDatCnt=0;
        	break;
	case 4://需传递1个缓冲区号与模板号(则取Parameter最低3字节,模板号可能需编码)
		for(i=0;i<3;i++)
		{	CheckNum+=(uint8)((Parameter&(0x00ff0000>>(8*i)))>>(16-8*i));}
			JudgeAndCoding(2,Cmd,ParaType,Parameter);
			PtRevOrSendDat+=RecordInputCondit_CodingDatCnt;
			SendDataLenth+=RecordInputCondit_CodingDatCnt;
			CmdPackParaLenth+=RecordInputCondit_CodingDatCnt;
			RecordInputCondit_CodingDatCnt=0;
			break;
	case 5://需传递模板号(则取Parameter最低字,可能需编码)
		for(i=0;i<2;i++)
		{	CheckSum+=(uint8)((Parameter&(0x0000ff00>>(8*i)))>>(8-8*i));}
			JudgeAndCoding(2,Cmd,ParaType,Parameter);
			PtRevOrSendDat+=RecordInputCondit_CodingDatCnt;
			SendDataLenth+=RecordInputCondit_CodingDatCnt;
			CmdPackParaLenth+=RecordInputCondit_CodingDatCnt;
			RecordInputCondit_CodingDatCnt=0;
			break;
	case 6://需传递配置表(则取Parameter[xx xx xx 00],再发[00 00 00 00])
        	for(i=0;i<4;i++)
			{	CheckSum+=(uint8)((Parameter&(0xff000000>>(8*i)))>>(24-8*i));
				*PtRevOrSendDat++=(uint8)((Parameter&(0xff000000>>(8*i)))>>(24-8*i));
				SendDataLenth++;
			}
			for(i=0;i<4;i++)
				{	*PtRevOrSendDat++=0x00;
					SendDataLenth++;
				}
				break;
	case 8://需传递握手口令(则取Parameter)
		for(i=0;i<4;i++)
		{	CheckNum+=(Uchar)((Parameter&(0xff000000>>(8*i)))>>(24-8*i));
			*PtRevOrSendDat++=(Uchar)((Parameter&(0xff000000>>(8*i)))>>(24-8*i));
			SendDataLenth++;
		}*/
		break;
	}
	//放校验和
	*PtRevOrSendDat++=(uint8)((CheckSum&0xff00)>>8);
	*PtRevOrSendDat++=(uint8)(CheckSum&0x00ff);
	SendDataLenth+=2;
}	
/*****************************************************************************************
** 函数名称 : SoftInit()
** 函数功能 : 软件初始化
**      	   Fpclk/2=0.5s的中断
** 入口参数 : 无
** 出口参数 : 无
*****************************************************************************************/
void SoftInit(void)
{	IRQEnable();
	PINSEL0 = 0x200c0005;				//初始化I/O 设置I/O
	PINSEL1 = 0x00;
	PINSEL2 = PINSEL2&(~0x08);
	IO0DIR = 0x00;
	IO1DIR = 0x00;
	
	T0TC = 0;
	T0PR = 0;
	T0MCR = 0x03;
	T0MR0 = Fpclk/40;
	T0TCR = 0x01;
	VICIntSelect = 0x00;
	VICVectCntl3 = 0x20|0x04;
	VICVectAddr3 = (uint32)IRQTimer0;	//定时器0初始化
	
	T1TC = 0;
	T1PR = 0;
	T1MCR = 0x03;
	T1MR0 = Fpclk/10;
	T1TCR = 0x01;
	VICIntSelect = 0x00;
	VICVectCntl1 = 0x20|0x05;			//?
	VICVectAddr1 = (uint32)IRQTimer1;		//定时器1初始化
	
	EXTMODE = 0x00;
	VICIntSelect = 0x00;
	VICVectCntl2 = 0x20|0x0f;
	VICVectAddr2 = (uint32)IRQEint1;
	EXTINT = 0x02;					//外中断1初始化
	VICIntEnable = VICIntEnable|0x8030;		//	
	
	Uart0Init();
	NumCnt=0;
	BStartBuzzerTime=0;
	BuzzerEvent_RevSameDatCnt=0;
	BuzzerCnt_DecodeDatCnt=0;
	TimeNumCnt=0;
	BstartLawlessOpenDoorTime=0;
	TimeDoorOpenCnt=0;
	RevEndFlag=0;
	PageId=0;
	BEndOneMinuteTime=0;
	EveryOneMinuteCnt_TimeCnt=0;
	BStartLedGlintTime=0;
	TempVar_TimeGlintCnt=0;
	BstartDoorOpenTime=0;
	BStartTimeCnt=0;
	MinuteCnt_LastRevDat=0;
	LedEvent_TimeBuzzerCnt=0;
	BStopCheck=0;
	BStopCheckBuz=0;	
}
/*****************************************************************************************
** 函数名称 : main()
** 函数功能 : 
**      	   
** 入口参数 : 无
** 出口参数 : 无
*****************************************************************************************/
/*****************************************************************************************
** 函数名称 : main()
** 函数功能 : 
**      	   
** 入口参数 : 无
** 出口参数 : 无
*****************************************************************************************/
/*int main(void)
{	//int8 i;
	uint8 SendDat[32];
	DelayNs(10);
//	SoftInit();
//	LedStateClew(5);
//	PackSendDat(0x01,0x1,0x00,0x00,0x00);
//	StartSeriSendDat();
	DelayNs(10);
//	UnpackRevDat(0x01);
	while(1);
	{
		DelayNs(10);
		Uart0GetStr(SendDat,10);
		DelayNs(10);
		Uart0SendStr(SendDat);
//		DelayNs(10);
//		UnpackRevDat(0x02);
//		Uart0RecStr(10);
//		UnpackRevDat(0x01);
//		DelayNs(10);
//		StartSeriSendDat();
	}
}*/	
int main(void)
{	uint8 SendDat[32];
	SoftInit();
	LedStateClew(5);
	PackSendDat(0x01,0x1,0x00,0x00,0x00);
	while(1)
	{	Uart0GetStr(SendDat,10);
		DelayNs(10);
		Uart0SendStr(SendDat);
		DelayNs(10);
	}
}
/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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