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

📄 lcd_fucntion.c

📁 RFID读卡器TRH031开发源码
💻 C
字号:
/***********************************************************
* Company	:	3ALOGICS                                   *
************************************************************/
#include <stdio.h>
#include "common.h"
#include "base.h"

#define LCDP P2                            
#define EN   P2_0

void Delay_ms(int p)                  // X=0.001/(1/11.0592/12)*8=115(1ms 狼 掉饭捞 拌魂) 
{
 int i,j;
 for(i=0;i<p;i++)
  {
   for(j=0;j<141;j++);
  }
}  

void Instruction_Out(BYTE b) //INSTRUCTIN 免仿阑 困茄 窃荐
{
   LCDP=b&0xf0;                       //惑困 4BIT 免仿 
   EN=1;                              //ENABLE 
   EN=0;                              //DISABLE
   LCDP=(b&0x0f)<<4;                  //窍困 4BIT 免仿
   EN=1;                              //ENABLE
   EN=0;                              //DISABLE
   //Busy();                            //疙飞绢 荐青捞 肯丰瞪嫐鳖瘤 瘤楷
   Delay_ms(2);
   
}

void Char_Out(BYTE b)        //LCD俊 茄巩磊 免仿窍绰 窃荐
{
   
   LCDP=(b&0xf0)|0x04;                //惑困 4BIT 免仿
   EN=1;                              //ENABLE
   EN=0;                              //DISABLE 
   LCDP=((b&0x0f)<<4)|0x04;           //窍困 4BIT 免仿
   EN=1;                              //ENABLE
   EN=0;                              //DISABLE
   //Busy();                            //疙飞绢 荐青捞 肯丰瞪锭鳖瘤 瘤楷
   Delay_ms(2);
   
}

void Lcd_Initial(void)                //LCD檬扁拳 风凭
{
   
   EN=0;                           
   Delay_ms(100);                        
   Instruction_Out(0x28);             //LCD FUNCTION SET(16*2LINE, 4BIT, 5*8DOT)            
   Delay_ms(100);                        
   Instruction_Out(0x0c);             //LCD DISPLAY ON,CURSOR OFF,BLINK OFF
   Delay_ms(100);                        
   Instruction_Out(0x01);             //LCD CLEAR
   Delay_ms(100);                        
   Instruction_Out(0x06);             //LCD ENTRY MODE SET
   Delay_ms(100);                        
   Instruction_Out(0x02);             //RETURN HOME
   
}

void String_Out(BYTE *str)   //巩磊凯 免仿阑 困茄 窃荐
{
  unsigned int i=0;
  do{
     Char_Out(str[i]);
     }while(str[++i]!='\0');
}

void Int_String_Out(BYTE *str)   //巩磊凯 免仿阑 困茄 窃荐
{
  unsigned int i=0;
  do{
     Char_Out(str[i]);
     }while(str[++i]!='\0');
}

void Hex_String_Out(BYTE str[2])   //巩磊凯 免仿阑 困茄 窃荐
{
     Char_Out(str[0]);
	 Char_Out(str[1]);
}

void Line1_Display (void)
{
	Instruction_Out(0x80);
	}

void Line2_Display (void)
{
	Instruction_Out(0xc0);
	}

void Lcd_Clear (void)
{
	Instruction_Out(0x01);
	}

void Dec2Hex (BYTE deci, BYTE hexa[2])
{
	BYTE Lower=0,Upper=0;
	Lower = (deci&0x0f);
	Upper = (deci&0xf0)>>4;

	if(Lower>9)
	{
		hexa[1] = Lower+55;
	}
	else
	{
		hexa[1] = Lower+48;
	}

	if(Upper>9)
	{
		hexa[0] = Upper+55;
	}
	else
	{
		hexa[0] = Upper+48;	
	}
}

void Dec2HexOut (BYTE deci)
{
	BYTE hexa[2];
	Dec2Hex(deci,hexa);
	Hex_String_Out(hexa);
}

/*void Display_ID(BYTE *BUf)
{
	i=0;
	do{Buf[i]

	}while(Buf[++i]!='\0');*/

void FIFO_Read(void)
{
	BYTE FIFOLength;
	BYTE i;
	FIFOLength = Read(0x04);

	if(FIFOLength != 0)
	{
		printf("\n FIFO Data Read :: Length = %02X [Hex] \n ", (int)FIFOLength);
		for(i=0; i<FIFOLength; i++)
		{
			printf("FIFO Byte[%02X] = %02X \n " ,  (int)i, (int)Read(0x02) );	
	    }
	}
	else {
		printf("\n FIFO EMPTY !! \n ");
	}
}

void Display_SFR(void)
{
	BYTE PriSta;
	BYTE FIFOLength;
	BYTE Command;
	BYTE temp;
	PriSta = (((Read(0x03))&0x70)>>4);
	FIFOLength = Read(0x04);
	if(FIFOLength!=0x00){
		Command = ((Read(0x01))&0x3f);
		Line1_Display();
		String_Out("Pri:    FIFO:   ");
		Instruction_Out(0x85);
		Dec2HexOut(PriSta);
		Instruction_Out(0x8e);
		Dec2HexOut(FIFOLength);
		Line2_Display();
		String_Out("Com:           ");
		Instruction_Out(0xc5);
		Dec2HexOut(Command);
		Delay_ms(1000);
		Lcd_Clear();

//IRQ Check
		temp = Read(0x03);
		if((temp&0x08)>>3)
		{
			temp=Read(0x07);
			if((temp&0x20)>>5)
			{
				Line1_Display();
				String_Out("IRQ TimerlRq");
				Delay_ms(1000);
				Lcd_Clear();
			}
			if((temp&0x10)>>4)
			{
				Line1_Display();
				String_Out("IRQ TxlRq");
				Delay_ms(1000);
				Lcd_Clear();
			}
			if((temp&0x08)>>3)
			{
				Line1_Display();
				String_Out("IRQ RxlRq");
				Delay_ms(1000);
				Lcd_Clear();
			}
			if((temp&0x04)>>2)
			{
				Line1_Display();
				String_Out("IRQ IdleRq");
				Delay_ms(1000);
				Lcd_Clear();
			}
			if((temp&0x02)>>1)
			{
				Line1_Display();
				String_Out("IRQ HiAlertRq");
				Delay_ms(1000);
				Lcd_Clear();
			}
			if (temp&0x01)
			{
				Line1_Display();
				String_Out("IRQ LowAlertRq");
				Delay_ms(1000);
				Lcd_Clear();
			}
		}

//Error Check
		temp = Read(0x03);
		if((temp&0x04)>>2)
		{
			temp=Read(0x0a);
			if((temp&0x10)>>4)
			{
				Line1_Display();
				String_Out("ERR Overfl");
				Delay_ms(1000);
				Lcd_Clear();
			}
			if((temp&0x08)>>3)
			{
				Line1_Display();
				String_Out("ERR CRCErr");
				Delay_ms(1000);
				Lcd_Clear();
			}
			if((temp&0x02)>>1)
			{
				Line1_Display();
				String_Out("ERR ParityErr");
				Delay_ms(1000);
				Lcd_Clear();
			}
			if((temp&0x01))
			{
				Line1_Display();
				String_Out("ERR CollErr");
				Delay_ms(1000);
				Lcd_Clear();
			}
		}
	}
}


void DisplayLCD(void)
{

    unsigned int i;	
    i = 0;
	
	LCDBuf[15] = '\0';	
	
	switch(LCDType)
	{
    	case 0x01       :	// REQA Display
							for (i=0; i<2; i++) {	
	       						Hex2Char(&CIDBuf[i]);
          						LCDBuf[i*3] = msc;
								LCDBuf[i*3+1] = lsc;
								LCDBuf[i*3+2] = ' ';
							}
							LCDBuf[6] = '\0';
							Instruction_Out(0x01);
	                        Instruction_Out(0x80);
		                    String_Out("REQA O.K!!");
		                    Instruction_Out(0xC0);
							String_Out("Answer : ");
		                    String_Out(&LCDBuf);
		                    //delay_ms(10);							
							//instruction_out(0x01);             //LCD CLEAR
				break;

        case 0x02          :     // A-Type ID Display 
							for (i=0; i<5; i++) {	
	       						Hex2Char(&CIDBuf[i]);
          						LCDBuf[i*3] = msc;
								LCDBuf[i*3+1] = lsc;
								LCDBuf[i*3+2] = ' ';
							}	
							Instruction_Out(0x01);
	                        Instruction_Out(0x80);
							String_Out("A-Type Read O.K!! ");
		                    Instruction_Out(0xC0);
							//String_Out(" ");
		                    String_Out(&LCDBuf);
		                    //delay_ms(100);
							break;     
  
         case 0x03        :      
                            for (i=0; i<4; i++) {	
	       						Hex2Char(&CIDBuf[i+1]);
          						LCDBuf[i*3] = msc;
								LCDBuf[i*3+1] = lsc;
								LCDBuf[i*3+2] = ' ';
							}
							LCDBuf[12] = '\0';	
							Instruction_Out(0x01);
	                        Instruction_Out(0x80);
							String_Out("B-Type Read O.K!! ");
		                    Instruction_Out(0xC0);
							//String_Out("ID : ");
		                    String_Out(&LCDBuf);
		                    //delay_ms(100);
							break;     
  
		  case 0x04        :      
                            for (i=0; i<5; i++) {	
	       						Hex2Char(&CIDBuf[i]);
          						LCDBuf[i*3] = msc;
								LCDBuf[i*3+1] = lsc;
								LCDBuf[i*3+2] = ' ';
							}
							Instruction_Out(0x01);
	                        Instruction_Out(0x80);
							String_Out("15693 Read O.K!! ");
		                    Instruction_Out(0xC0);
							//String_Out("ID : ");
		                    String_Out(&LCDBuf);
		                    //delay_ms(100);
							break;     
		 case 0x05        :      
                            for (i=0; i<5; i++) {	
	       						Hex2Char(&CIDBuf[i]);
          						LCDBuf[i*3] = msc;
								LCDBuf[i*3+1] = lsc;
								LCDBuf[i*3+2] = ' ';
							}
							Instruction_Out(0x01);
	                        Instruction_Out(0x80);
							String_Out("Tag-It Read O.K!! ");
		                    Instruction_Out(0xC0);
							//String_Out("ID : ");
		                    String_Out(&LCDBuf);
		                    //delay_ms(100);
							break;     
          default             :  
                         
			      			break;
 	}

    return;
  	
}


void Hex2Char(BYTE *bhp)
{ 
    BYTE bh;
  	unsigned char k;
	bh = *bhp;
     
	k = (bh << 4);
							
		if (bh < 0x10)  
				msc = '0';			
		else if (bh < 0x20)  
				msc = '1';
		else if (bh < 0x30)  
				msc = '2';
			else if (bh < 0x40)  
				msc = '3';
			else if (bh < 0x50)  
				msc = '4';
			else if (bh < 0x60)  
				msc = '5';
			else if (bh < 0x70)  
				msc = '6';
			else if (bh < 0x80)  
				msc = '7';
			else if (bh < 0x90)  
				msc = '8';
			else if (bh < 0xA0)  
				msc = '9';
			else if (bh < 0xB0)  
				msc = 'A';
			else if (bh < 0xC0)  
				msc = 'B';
			else if (bh < 0xD0)  
				msc = 'C';
			else if (bh < 0xE0)  
				msc = 'D';
			else if (bh < 0xF0)  
				msc = 'E';
			else  
				msc = 'F';
			
			if (k == 0x00)  
				lsc = '0';			
			else if (k == 0x10)  
				lsc = '1';
			else if (k == 0x20)  
				lsc = '2';
			else if (k == 0x30)  
				lsc = '3';
			else if (k == 0x40)  
				lsc = '4';
			else if (k == 0x50)  
				lsc = '5';
			else if (k == 0x60)  
				lsc = '6';
			else if (k == 0x70)  
				lsc = '7';
			else if (k == 0x80)  
				lsc = '8';
			else if (k == 0x90)  
				lsc = '9';
			else if (k == 0xA0)  
				lsc = 'A';
			else if (k == 0xB0)  
				lsc = 'B';
			else if (k == 0xC0)  
				lsc = 'C';
			else if (k == 0xD0)  
				lsc = 'D';
			else if (k == 0xE0)  
				lsc = 'E';
			else  
				lsc = 'F';

			return;
	}

⌨️ 快捷键说明

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