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

📄 avr12864.i

📁 em4100卡读卡程序
💻 I
📖 第 1 页 / 共 2 页
字号:
    if(bBusy) goto reDetect;
}
*/
/*
void LCD_NOP(void)
{
	uchar i;
	for(i=0;i<10;i++); 
	#asm("NOP");
}
*/
//LCD左半屏写命令字
void LCD_Write_ComL(unsigned char x)
{ 
  	PORTA.3=1;
  	PORTA.4  =0;  
//  	LCD_BUSY();      
//  	LCD_NOP();
  	PORTA.0    =0;       //Instruction
  	PORTA.2=1;
//  	LCD_NOP();
  	PORTA.1=0;      
  	PORTB=x;
  	PORTA.2=1;
  	PORTA.2=0;
  	PORTA.3=1;
  	PORTA.4  =1;
}

//LCD左半屏写数据
void LCD_Write_DatL(unsigned char x)
{ 
  	PORTA.3=1;	
  	PORTA.4  =0;
//  	LCD_BUSY();  
//  	LCD_NOP();
  	PORTA.0    =0;
  	PORTA.2=1;
//  	LCD_NOP();
  	PORTA.0    =1;       //Data
  	PORTA.1=0;
  	PORTB=x;
  	PORTA.2=1;
  	PORTA.2=0;
  	PORTA.3=1;
  	PORTA.4  =1;
}

//LCD右半屏写命令字
void LCD_Write_ComR(unsigned char x)
{ 
  	PORTA.3=0;
  	PORTA.4  =1;
//  	LCD_BUSY();  
//  	LCD_NOP();
  	PORTA.0    =0;
  	PORTA.2=1;
//  	LCD_NOP();
  	PORTA.1=0;
  	PORTB=x;
  	PORTA.2=1;
  	PORTA.2=0;
  	PORTA.3=1;
  	PORTA.4  =1;    
}      

//LCD右半屏写数据
void LCD_Write_DatR(unsigned char x)
{ 
  	PORTA.3=0;
  	PORTA.4  =1;
//  	LCD_BUSY();  
//  	LCD_NOP();
  	PORTA.0    =0;
  	PORTA.2=1;
//  	LCD_NOP();
  	PORTA.0    =1;
  	PORTA.1=0;
  	PORTB=x;
  	PORTA.2=1;
  	PORTA.2=0;
  	PORTA.3=1;
  	PORTA.4  =1;   
}

//LCD初始化
void LCD_Init(void)
{  
	PORTA.5       = 1;
	PORTA.5       = 0;
	Delay(200);
    PORTA.5       = 1;
  	LCD_Write_ComL(0x3e);
  	LCD_Write_ComR(0x3e);
  	LCD_Write_ComL(0x3f);
  	LCD_Write_ComR(0x3f);
  	LCD_Write_ComL(0xc0);
  	LCD_Write_ComR(0xc0);
}

//LCD清屏
void LCD_Clr(void)
{
	unsigned char i,j;      
	for(j=0;j<8;j++)
	{
  		LCD_Write_ComL(0xb8|j);  
  		LCD_Write_ComL(0x40);
  		LCD_Write_ComR(0xb8|j);  
  		LCD_Write_ComR(0x40);
  		for(i=0;i<64;i++)
  		{
    		LCD_Write_DatL(0x00);  
    		LCD_Write_DatR(0x00); 
  		}
	}
}

//------------------------------------------------------
//            中英文写入函数             
//  X:X方向移动1点;Y:Y方向移动8点;fan:=0正常显示,=1为反白显示
//------------------------------------------------------
void CCW_PR(unsigned int neima,unsigned char X,unsigned char Y,unsigned char fan)
{
    unsigned char k,com,dat1,hz;
    unsigned int i;
    Y=Y|0xb8;				 //置页地址
    LCD_Write_ComL(Y);
    LCD_Write_ComR(Y);
    if(neima<0x0000  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  )          //判断字库是不是汉字
        hz=8;
    else
        hz=0;
    if(X<0x40)				 //判断是否写命令字在第一块HD61202
    {
        com=X+0x40; //置列地址
        LCD_Write_ComL(com);
        k='L';
    }
    else
    {
        com=X;
        LCD_Write_ComR(X);   //Com=X-0x40+0x40
    }
    com=com&0x3f;
    for(i=neima;i<(16+neima-hz);i++)
    {
        dat1=hzdot[i];
        if(fan)
            dat1=~dat1;
        if(k=='L')
            LCD_Write_DatL(dat1);
        else
            LCD_Write_DatR(dat1);
        com++;
        if(com==0x40)			//判断是否为第二块HD61202
        {
           LCD_Write_ComR(com);
           k='R';
        }
    }
    Y++;
    LCD_Write_ComL(Y);
    LCD_Write_ComR(Y);
    if(X<0x40)				//判断是否写命令字在第一块HD61202
    {
        com=X|0x40;
        LCD_Write_ComL(com);
        k='L';
    }
    else
    {
        com=X;
        LCD_Write_ComR(X);				//Com=X-0x40+0x40
    }
    com=com&0x3f;
    for(i=(16+neima-hz);i<(32+neima-hz-hz);i++)    //调整字库点阵的位置
    {
        dat1=hzdot[i];
        if(fan)
            dat1=~dat1;
        if(k=='L')
        {
            LCD_Write_DatL(dat1);
        }
        else
        {
            LCD_Write_DatR(dat1);
        }
        com++;
        if(com==0x40)			//判断是否为第二块HD61202
        {
            LCD_Write_ComR(com);
            k='R';
        }
    }
}

void logo(void)
{
    CCW_PR(0x0000  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  ,0x00,0x00,0);           //系
    CCW_PR(0x0000  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  +32  ,0x10,0x00,0);           //统
    CCW_PR(0x0000  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +32  +32  +32  +32  +32  +32  +32  +32  ,0x20,0x00,0);           //设
    CCW_PR(0x0000  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +32  +32  +32  +32  +32  +32  +32  +32  +32  ,0x30,0x00,0);           //定    
    CCW_PR(0x0000  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  ,0x40,0x00,0);         //:     
    CCW_PR(0x0000  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +32  +32  +32  +32  ,0x50,0x00,1);           //上
    CCW_PR(0x0000  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +32  +32  +32  +32  +32  ,0x60,0x00,1);           //下   
}

// External Interrupt 0 service routine 
/* WG26 */
interrupt [3] void ext_int1_isr(void)
{
    bit da0;
    unsigned char i;
    
    #asm("cli")  
    da0=PIND.2;				 //端口数据
    if (id_bit==0)
    {
        id_sucess=0;
        check_flag=0;
        id[0]=id[1]=id[2]=0;
    }
    check_flag=check_flag^da0;
    id_bit++;				 //接收的位数
    if(id_bit<10)
        i=0;
    else if(id_bit<18)
        i=1;
    else if(id_bit<26)
        i=2;               
    if(id_bit!=26)
    {
        id[i]=(id[i]<<1);
        if(da0==1)
           id[i]=id[i]+1;
    }
	if (id_bit==14)
	{	
	    if (check_flag!=0) //偶校验 2-13
	        id_bit=0;
		else check_flag=1;	//偶校验成功
    }	            	
	if(id_bit==26)
	{						//奇校验 15-25
	    if(check_flag==0)
	        id_sucess=1;    //校验成功
	    id_bit=0;
	}
	#asm("sei")    
}

void flashled(void)    
{
    unsigned int i=0;
    unsigned char j=0;    
    for(;j<5;j++)
    {
        PORTD.6=~PORTD.6;    
        while(--i);  
    }
    PORTD.6=1; 
}        

interrupt [9] void ext_timer1_isr(void)    
{
    #asm("NOP");
}
void ReadID(void)
{  
//     while(DATA0)
//         NOP10();
//     while(!DATA0)
//         NOP10();
    TCCR1B=0x01; 
    #asm("NOP");
    #asm("NOP");
    #asm("NOP");
    #asm("NOP");
    #asm("NOP");
    #asm("NOP");
    #asm("NOP");
    #asm("NOP");
    #asm("NOP");
    #asm("NOP");


}

void main(void)
{
	unsigned int i;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTD=0xFC;
    DDRD=0xF0;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
    TCCR0=0x00;
    TCNT0=0x00;
    OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
    TCCR1A=0x00;   
//No Prescaling    
    TCCR1B=0x00;
    TCNT1H=0x00;
    TCNT1L=0x00;
    ICR1H=0x00;
    ICR1L=0x00;
    OCR1AH=0x00;
    OCR1AL=0x00;
    OCR1BH=0x00;
    OCR1BL=0x00;    
    TIMSK|=0x04;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
    ASSR=0x00;
    TCCR2=0x00;
    TCNT2=0x00;
    OCR2=0x00;

// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
// INT1: Off
// INT2: Off
    GICR=0;//|=0x80; prohibit int1
    MCUCR=0x08;
    MCUCSR=0x00;
    GIFR=0x80;        

// Global enable interrupts
    #asm("sei")                    
                        
    PORTB=0x00;// set portb as status                
	DDRB=0xff;// set portb as outport   
	
	PORTA=0X00; 
	DDRA=0xff; 
	  
	
	LCD_Init(); //LCD初始化
	LCD_Clr();  //LCD清屏

	logo();
	Delay(200);
	while(1)
	{   
	    Delay(200);               
        Count++;
    	LCDInfoBuf[11]=(Count/10000)%10;
    	LCDInfoBuf[12]=(Count/1000)%10;
    	LCDInfoBuf[13]=(Count/100)%10;
    	LCDInfoBuf[14]=(Count/10)%10;
    	LCDInfoBuf[15]=(Count)%10;
		for (i=11;i<16;i++)
		{
			CCW_PR((int)LCDInfoBuf[i]*16,LCDInfo[i].X,LCDInfo[i].Y,0);	
		}   
		if(id_sucess)
		{    		    
		    id_sucess=0; 
		    LCDIDBUF[0]=id[0]>>4;
		    LCDIDBUF[1]=id[0]&0x0f;    
		    LCDIDBUF[2]=id[1]>>4;
		    LCDIDBUF[3]=id[1]&0x0f;
		    LCDIDBUF[4]=id[2]>>4;
		    LCDIDBUF[5]=id[2]&0x0f;
		    CCW_PR(0x0000  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  ,0x00,0x04,0);	
		    CCW_PR(0x0000  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  ,0x08,0x04,0);	
		    CCW_PR(0x0000  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  +16  ,0x10,0x04,0);
    		for (i=0;i<6;i++)
    		{
    			CCW_PR((int)LCDIDBUF[i]*16,LCDInfo[i+16].X,LCDInfo[i+16].Y,0);	
    		}  	 
    		flashled();	
		}	
		ReadID();
	}   
}

⌨️ 快捷键说明

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