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

📄 rfidsys.c

📁 读写器与射频卡通信的设计采用RC522射频读写芯片与射频卡进行通信
💻 C
字号:
/*********************************************************************
             
目    的:   建立操作LCD12864_ST7920液晶的示例程序

目标系统:   基于任何AVR单片机
		                                                                
应用软件:   ICCAVR
		                                                                
版    本:   Version 1.0                                                          
		                                                                
圆版时间:   2008-05-28
	
开发人员:   hky

说    明:   若用于商业用途,请保留此段文字或注明代码来源

*********************************************************************/

/*01010101010101010101010101010101010101010101010101010101010101010101
----------------------------------------------------------------------
版本更新记录:

----------------------------------------------------------------------
实验内容:
初始化、读写Lcd12864_ST7920。
----------------------------------------------------------------------
硬件连接:
LCD12864_ST7920			ATmega16
4.RS(CS)	--------	VCC
5.R/W(SID)	--------	MOSI/PB5
6.E(SCLK)	--------	SCK/PB7
15.PSB		--------	GND
----------------------------------------------------------------------
10101010101010101010101010101010101010101010101010101010101010101010*/

#include <iom16v.h>
#include "D:\Headers\LCD12864_ST7920.H"
//#include "PCF8563.h"
#include "D:\Headers\Hardware.H"
//#include "D:\ICC_H\I2C.H"
//#include "delay1.h"
/*--------------------------------------------------------------------
函数名称:
函数功能:
注意事项:
提示说明:
输    入:
返    回:
--------------------------------------------------------------------*/
void init_device()
{
// Input/Output Ports initialization
// Port A 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
PORTA=0x00;
DDRA=0x00;

// Port B 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
PORTB=0x00;
DDRB=0x00;

// Port C 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
PORTC=0x00;
DDRC=0x00;

// 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=0x00;
DDRD=0x00;

// 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;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// 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: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

}
void main()
{   
  unsigned char a=0;
  init_device();        
  PORTB|=0x02;

    //DDRA|=0x09;
    //PORTA=0xFE;
  DDRA|=0x01;
  PORTA&=0xFE;
	//DDRA|=0x04;
   // PORTA|=0x04;
	
	SEI();
	lcd_init();	
	lcd_puts(2,1,"    启动中 -");
    PORTB|=0x04;
    delay50ms(2); 
	lcd_puts(2,1,"    启动中 \\");
	delay50ms(2);
	lcd_puts(2,1,"    启动中 /");
	delay50ms(2);  
	lcd_puts(2,1,"    启动中 -");
    PORTB&=0xFB;
    delay50ms(2);
	lcd_puts(2,1,"    启动中 \\");
	delay50ms(2); 
	lcd_puts(2,1,"    启动中 /");
    PORTB|=0x04;
    delay50ms(2);
	lcd_puts(2,1,"    启动中 -");
	delay50ms(2); 
	lcd_puts(2,1,"    启动中 \\");
	delay50ms(2); 
	lcd_puts(2,1,"    启动中 /"); 
    PORTB&=0xFB;
    delay50ms(2);
	lcd_puts(2,1,"    启动中 -"); 
	delay50ms(2);
	lcd_puts(2,1,"    启动中 \\"); 
	delay50ms(2);
	//lcd_puts(2,1,"    启动中 /"); 
	lcd_clr();
	
	 // DDRB|=0x01;
     // PORTB&=0xFE;
	delay50ms(6);
	lcd_puts(1,1,"  BESTi-041229");
	lcd_puts(2,1,"    毕业设计");
	lcd_puts(3,1,"手持式射频读写器");
	lcd_puts(4,1," LOADING");
	delay50ms(20);
	lcd_puts(4,1," LOADING·");
	delay50ms(20);
	lcd_puts(4,1," LOADING··");
	delay50ms(20);
	lcd_puts(4,1," LOADING···");
	delay50ms(20);
	lcd_puts(4,1," LOADING····");
	delay50ms(20); 
	lcd_clr();
	delay50ms(10); 
	PORTB&=0xCF;
	
	while(1)
	{	
	  lcd_puts(1,1,"  射频卡检测中");
       if(PINA&0X01==0X01){
       delay50ms(3);
         if(PINA&0X01==0X01){
          if(a==1)
          {
            DDRA|=0X02;
            PORTA&=0XFD;
            a=0;
          }
          else{
               DDRA|=0X02;
               PORTA|=0X02;
               a=1;
              }
          }

        } 
		
	if(PINC&0x04==0x04)
	   {
	    DDRD|=0x01;
	    PORTD&=0xFE;
	    lcd_puts(3,1,"  没有射频卡!");
       }
     else
        {
         DDRD|=0x01;
         PORTD|=0x01;
		 lcd_puts(3,1,"  检测到射频卡");
        }
		//GetPCF8563();
		//lcd_putc(2,1,miao);
		//lcd_putc(3,1,fen);
		//lcd_putc(4,1,shi);
	
	if(PINB&0x01==0x01)
     { lcd_clr();
	   PORTB|=0x04;
	   lcd_puts(2,1,"  关机中");
       delay50ms(14);
       PORTB&=0xFB;
	   lcd_puts(2,1,"  关机中·");
       delay50ms(14);
	   lcd_puts(2,1,"  关机中··");
	   delay50ms(14);
	   lcd_puts(2,1,"  关机中···");
	   delay50ms(14);
	   lcd_clr();
	   delay50ms(14);
       DDRB|=0x02;
       PORTB&=0xFD;
	 }  
  };
}



⌨️ 快捷键说明

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