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

📄 rs232.c

📁 LPC2103的绝大部分驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
				buf[0] = data + '0';
				
			if((ReadData[i] & 0x0F) >= 10)
				buf[1] = (ReadData[i] & 0x0F) + 'A' - 10;
			else
				buf[1] = (ReadData[i] & 0x0F) + '0';
				
			buf[2] = ' ';
			
			if((i%8 == 0) && (i != 0))
				buf[2] = '\n';
				
			DEBUG_PrintBuf(buf,3);
		}
	}

}
*/
/*UART0向FLASH写数据*/
/*
void UTAR0_SPI_Write(void)
{
	uint8	i;
	uint8	WriteChipNum;
	uint16	WriteBeginByte;
	uint16	WriteLength;
	uint32	WriteBeginPage;
	char	WriteData[256];
	uint8 	buf[3];

	uint8	data;

#ifdef use_debugPrint
	uint8 Message1[] = "WriteChipNum is: ";
	uint8 Message2[] = "WriteBeginPage is: ";
	uint8 Message3[] = "WriteBeginByte is: ";
	uint8 Message4[] = "WriteLength is: ";
#endif

	if(rcv_buf[rcv_buf_head] == SPI_WRITE)		//写FLASH
	{
		Rcv_Buf_Head_Plus(1);

		WriteChipNum = rcv_buf[rcv_buf_head];

		data = WriteChipNum >> 4;
		
		if(data >= 10)
			buf[0] = data + 'A' - 10;
		else
			buf[0] = data + '0';
			
		if((WriteChipNum & 0x0F) >= 10)
			buf[1] = (WriteChipNum & 0x0F) + 'A' - 10;
		else
			buf[1] = (WriteChipNum & 0x0F) + '0';
			
		buf[2] = '\n';

		Rcv_Buf_Head_Plus(1);
		DEBUG_PrintBuf(Message1,17);
		DEBUG_PrintBuf(buf,3);
		
		WriteBeginPage = rcv_buf[rcv_buf_head];
		
		data = WriteBeginPage >> 4;
		
		if(data >= 10)
			buf[0] = data + 'A' - 10;
		else
			buf[0] = data + '0';
			
		if((WriteBeginPage & 0x0F) >= 10)
			buf[1] = (WriteBeginPage & 0x0F) + 'A' - 10;
		else
			buf[1] = (WriteBeginPage & 0x0F) + '0';
			
		buf[2] = '\n';
		
		Rcv_Buf_Head_Plus(1);
		DEBUG_PrintBuf(Message2,19);
		DEBUG_PrintBuf(buf,3);

		WriteBeginByte = rcv_buf[rcv_buf_head];
		
		data = WriteBeginByte >> 4;

		if(data >= 10)
			buf[0] = data + 'A' - 10;
		else
			buf[0] = data + '0';
			
		if((WriteBeginPage & 0x0F) >= 10)
			buf[1] = (WriteBeginByte & 0x0F) + 'A' - 10;
		else
			buf[1] = (WriteBeginByte & 0x0F) + '0';
			
		buf[2] = '\n';

		Rcv_Buf_Head_Plus(1);
		DEBUG_PrintBuf(Message3,19);
		DEBUG_PrintBuf(buf,3);

		WriteLength = rcv_buf[rcv_buf_head];

		data = WriteLength >> 4;
		
		if(data >= 10)
			buf[0] = data + 'A' - 10;
		else
			buf[0] = data + '0';
			
		if((WriteLength & 0x0F) >= 10)
			buf[1] = (WriteLength & 0x0F) + 'A' - 10;
		else
			buf[1] = (WriteLength & 0x0F) + '0';

		buf[2] = '\n';
		
		Rcv_Buf_Head_Plus(1);
		DEBUG_PrintBuf(Message4,16);
		DEBUG_PrintBuf(buf,3);

		for(i = 0; i<WriteLength; i++)
		{
			WriteData[i] = 0xFF;
		}

		for(i=0;i<WriteLength;i++)
		{	
			WriteData[i] = i;
			Read_WriteData[i] = WriteData[i];
		}
		
		for(i = 0; i<WriteLength; i++)
		{
			data = WriteData[i] >> 4;
			
			if(data >= 10)
				buf[0] = data + 'A' - 10;
			else
				buf[0] = data + '0';
				
			if((WriteData[i] & 0x0F) >= 10)
				buf[1] = (WriteData[i] & 0x0F) + 'A' - 10;
			else
				buf[1] = (WriteData[i] & 0x0F) + '0';
				
			buf[2] = ' ';
			
			if((i%8 == 0) && (i != 0))
				buf[2] = '\n';
				
			DEBUG_PrintBuf(buf,3);
		}

//		while(1)
//		{
			Write_Flash_Data(WriteChipNum,WriteBeginPage,WriteBeginByte,WriteLength,WriteData);
//			Delay(10);
//		}
	}

}
*/
/********************************************************************************************************
*
* 函数名称:Flag_Judge
*
* 功能描述:判断接收的数据是什么数据
*
* 入口参数:data	RS232接收到的数据
* 出口参数:0:接收到的是卡号,1:接收到的是键值
*
********************************************************************************************************/
/*
int Flag_Judge(uint8 data)
{
	if(rcv_buf[rcv_buf_head]  == ID_Flag)
		return 0;
	else
		return 1;
}
*/
/********************************************************************************************************
*
* 函数名称:Data_long()
*
* 功能描述:判断ID数据是否完全
*
* 入口参数:
* 出口参数:缓冲区有效数据的个数
*
********************************************************************************************************/
/*
int Data_Len(void)
{
	if(rcv_buf_head < rcv_buf_end)
		return rcv_buf_end - rcv_buf_head;
	
	if(rcv_buf_head > rcv_buf_end)
		return rcv_buf_end + rcv_buf_size - rcv_buf_head;	
	
	if(rcv_buf_head == rcv_buf_end)
		return 0;
}
*/
/********************************************************************************************************
*
* 函数名称:rcv_buf_ptr()
*
* 功能描述:对rcv_buf的指针操作
*
* 入口参数:pointer	判断指针是否溢出
* 出口参数:pointer	正确的指针位置
*
********************************************************************************************************/
 /*
int rcv_buf_ptr(int pointer)
{
	if(pointer == rcv_buf_size)
		return 0;
	else
		return pointer;
}
*/
/********************************************************************************************************
*
* 函数名称:Clear_Key_Check()
*
* 功能描述:判断ID数据是否完全
*
* 入口参数:data	输入键值
* 出口参数:0:是CLEAR键,1不是CLEAR键
*
********************************************************************************************************/
/*
int Clear_Key_Check(uint8 data)
{
	if(data == CLEAR_Key)
		return 0;	
	else
		return 1;   
}
*/
/********************************************************************************************************
*
* 函数名称:CardreaderRawDataHandle
*
* 功能描述:对RS232接收的数据进行处理
*
* 入口参数:RS232_state	  RS232数据处理的状态字
* 出口参数:
*
********************************************************************************************************/
/*
#define CardreaderRawDataHandST_Idle			0x00
#define CardreaderRawDataHandST_KeyValue		0x01
#define CardreaderRawDataHandST_CardNo			0x02
#define CardreaderRawDataHandST_Addr			0x03
#define CardreaderRawDataHandST_DutyInfo		0x04
#define CardreaderRawDataHandST_Time			0x05
#define CardreaderRawDataHandST_SetTime			0x06
#define CardreaderRawDataHandST_SetShiftTime	0x07
#define CardreaderRawDataHandST_VoiceType		0x08
#define CardreaderRawDataHandST_SetGroupNo		0x09


uint8 CardreaderRawDataHandST = CardreaderRawDataHandST_Idle;

void CardreaderRawDataHandle(void)
{
	uint8 iLoop;
	
	#ifdef use_debugPrint
	uint8 buf1[] = "New Address:";//12
	uint8 buf3[] = "Old Address:";//12
	uint8 buf2[] = "Set Address error.\n";//19
	uint8 buf4[] = "Set Address to";//14
	uint8 buf5[] = "Group Num:";//10
	#endif
	
	uint8 DataNuInbuf = Data_Len();
	DATE_TIME SetDT;				//数据结构里包含了年月日小时分秒
	uint8 Year1,Year2;
	uint16 ShiftTime1,ShiftTime2;
	if(DataNuInbuf == 0)			//若没有收到数据直接返回,这个决定了Rcv_Buf_Head_Plus(1);的位置,要把要执行的操作执行完后再进行这个动作,否则缓冲中没数据的话就会再进入下面的程序了
		return;
		
	//UART0_PutChar(rcv_buf[rcv_buf_head]);
	//Rcv_Buf_Head_Plus(1);
	//return;
		
	switch (CardreaderRawDataHandST)
	{
		case CardreaderRawDataHandST_Idle:
		
			if(rcv_buf[rcv_buf_head] == INPUTDATATYPE_CARDNO)						//若收到的是卡号,转到卡号状态
			{
				CardreaderRawDataHandST = CardreaderRawDataHandST_CardNo;			
			}
			else if(rcv_buf[rcv_buf_head] == INPUTDATATYPE_KEY)						//若收到的是按键的值
			{
				CardreaderRawDataHandST = CardreaderRawDataHandST_KeyValue;			
			}
			else if(rcv_buf[rcv_buf_head] == INPUTDATATYPE_ADDR)					//若收到的是地址,是计算机通过232发出来的,不是读卡器读出来的,转到地址状态,这个字节用来标识是地址,具体地址在后面一个字节
			{
				if(1==DataNuInbuf)
				{
					DEBUG_PrintBuf(buf3,12);
					DEBUG_PrintByte16(FlashHead.Addr);
					DEBUG_PrintChar('\n');
					DEBUG_PrintBuf(buf5,10);
					DEBUG_PrintByte16(FlashHead.GroupNo);
					DEBUG_PrintChar('\n');					
					CardreaderRawDataHandST =  CardreaderRawDataHandST_Idle;				
				}
				else
				{
					CardreaderRawDataHandST = CardreaderRawDataHandST_Addr;				
				}
				Rcv_Buf_Head_Plus(1);					
			}
			else if(rcv_buf[rcv_buf_head] == INPUTDATATYPE_DutyInfo)				//打印值班信息
			{
				CardreaderRawDataHandST = CardreaderRawDataHandST_DutyInfo;			
			}
			else if(rcv_buf[rcv_buf_head] == INPUTDATATYPE_Time)					//打印当前时间
			{
				CardreaderRawDataHandST = CardreaderRawDataHandST_Time;				
			}
			else if(rcv_buf[rcv_buf_head] == INPUTDATATYPE_SetTime)					//设置当前时间
			{
				CardreaderRawDataHandST = CardreaderRawDataHandST_SetTime;			
			}

			else if(rcv_buf[rcv_buf_head] == INPUTDATATYPE_ShiftTime)				//设置交班时间
			{
				CardreaderRawDataHandST = CardreaderRawDataHandST_SetShiftTime;		
			}
			
			else if(rcv_buf[rcv_buf_head] == INPUTDATATYPE_VoiceType)				//
			{
				CardreaderRawDataHandST = CardreaderRawDataHandST_VoiceType;		
			}
			else if(rcv_buf[rcv_buf_head] ==INPUTDATATYPE_SetGroupNo)
			{
				CardreaderRawDataHandST = CardreaderRawDataHandST_SetGroupNo;
			}
			else
			{
				Rcv_Buf_Head_Plus(1);
			}
				
			break;
			
		case CardreaderRawDataHandST_KeyValue:
		
			if(DataNuInbuf > 1)												//DataNuInbuf,是缓冲区里的数据个数
			{
				CardReadorData.InputType = INPUTDATATYPE_KEY;				//	uint8 InputType;	uint8 CardNo_KeyValue[4]
				Rcv_Buf_Head_Plus(1);
				CardReadorData.CardNo_KeyValue[0] = rcv_buf[rcv_buf_head];	//按键的值
				Rcv_Buf_Head_Plus(1);
				CardreaderRawDataHandST = CardreaderRawDataHandST_Idle;
			}
			break;
			
		case CardreaderRawDataHandST_CardNo:								//卡号时
			if(DataNuInbuf > 4)
			{
				CardReadorData.InputType = INPUTDATATYPE_CARDNO;
				Rcv_Buf_Head_Plus(1);
				for(iLoop = 0;iLoop < 4;iLoop++)
				{
					CardReadorData.CardNo_KeyValue[iLoop] = rcv_buf[rcv_buf_head];
					Rcv_Buf_Head_Plus(1);
				}
				CardreaderRawDataHandST = CardreaderRawDataHandST_Idle;
			}

⌨️ 快捷键说明

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