系统采用51单片机为主控,rc522为检测装置,主要是模拟,红绿灯通过定时器控制,原理就是逻辑判断,在红灯时有车(卡)扫过,就会存储下车牌号,通过液晶显示车牌,以及红灯信息,有闯红灯信息。代码如下。
单片机源程序如下:
- #include "common.h"
- #include "RC522.h"
- #include "stdio.h"
- #include "12864.h"
- #define uchar unsigned char
- #define uint unsigned int
- char serNum[5];
- char Old_serNum[5]=0,Card_serNum[20][5]=0,buf[9];
- char str[MAX_LEN];
- char code DefaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- int num,flag,i,j,num1=0;
- char temp=29,flag0=0,flag1=0,flag2,flag3,aa;
- char temp1=1;
- void T1_time1(void) interrupt 1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- aa++;
-
- if(aa==20)
- {
- aa=0;
- temp--;
- }
-
- if(flag1==0)
- {
- if((temp>0)&&(temp<30)) {RED=0;YELLOW=1;GREEN=1;flag=1;}
- }
- if(flag0==0)
- {
- if(temp==0)
- {
- temp=29;
- flag1=1;
- }
- }
-
- if(flag1==1)
- {
- if((temp>5)&&(temp<30)) {RED=1;YELLOW=1;GREEN=0;flag=0;}
- if((temp<=5)&&(temp>=0)) {RED=1;YELLOW=0;GREEN=1;flag=0;}
- flag0=1;
- if(temp==0)
- {
- temp=29;
- flag1=0;
- flag0=0;
- }
- }
- }
- void ShowCard_Id()
- {
- int i;
- char *ptr=buf;
- for(i=0; i<4; i++,ptr+=2)
- {
- sprintf(ptr,"%02x",Card_serNum[num1][i]);
- buf[8]='\0';
- Lcd_Display(1,5,buf);
- }
- }
- void show_card()
- {
- char card;
- card=Card_serNum[num1][0];
- switch(card)
- { case 0x25:
- Lcd_Display(3,4,"吉A 88888");
- break;
- case 0x63:
- Lcd_Display(3,4,"吉B 66J67");
- break;
- case 0x96:
- Lcd_Display(3,4,"吉C 98889");
- break;
- case 0x80:
- Lcd_Display(3,4,"吉A YIJ88");
- break;
- case 0x00:
- Lcd_Display(3,4,"00 00000 ");
- break;
- }
- }
- void InoutHandle()
- {
- unsigned char state;
- unsigned char readBuf[16];
-
- state = PcdRequest(PICC_REQIDL, str);
- if(state != MI_OK) return;
-
- state = PcdAnticoll(serNum);
- if(state != MI_OK) return;
- state = PcdSelect(serNum);
- if(state != MI_OK) return;
- state = PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey , serNum);
- if(state != MI_OK) return;
- state = PcdRead(1, readBuf);
- if(state != MI_OK) return;
- for(j=0;j<5;j++)
- {
- if(Old_serNum[j]!=serNum[j])
- {
- flag2=1;
- }
- }
- if(flag2==1)
- {
- for(j=0;j<5;j++)
- {
- Old_serNum[j]=serNum[j];
- }
- Card_serNum[temp1][0]=Old_serNum[0];
- Card_serNum[temp1][1]=Old_serNum[1];
- Card_serNum[temp1][2]=Old_serNum[2];
- Card_serNum[temp1][3]=Old_serNum[3];
- temp1++;
- if(temp1==20)
- {
- temp1=0;
- }
- flag2=0;
- }
- PcdHalt();
- }
- void key_stck()
- {
- key0 = 1;
- key1 = 1;
- key2 = 1;
- key3 = 1;
- if( key0 == 0 )
- {
- delay_10ms(5);
- if( key0 == 0 )
- {
- while(!key0);
- if(num1!=0) num1--;
- else num1=0;
- }
- }
- if( key1 == 0 )
- {
- delay_10ms(5);
- if( key1 == 0 )
- {
- while(!key1);
- num1++;
- if(num1==20)
- {
- num1=0;
- }
- }
- }
- if( key2 == 0 )
- {
- delay_10ms(5);
- if( key2 == 0 )
- {
- while(!key2);
-
- }
- }
- if( key3 == 0 )
- {
- delay_10ms(5);
- if( key3 == 0 )
- {
- while(!key3);
- }
- }
- Lcd_Num_Display(4,1,num1);
- Lcd_Display(3,1,"车牌:");
- Lcd_Display(2,1,"违章车辆: 台");
- Lcd_Num_Display(2,6,temp1-1);
- if(Card_serNum[1][0]!=0)
- {
- Lcd_Display(1,1,"有违章");
- }
- if(Card_serNum[1][0]==0)
- {
- Lcd_Display(1,1,"无违章");
- }
- show_card();
- }
复制代码
所有资料51hei提供下载:
RFID闯红灯检测.zip
(166.88 KB, 下载次数: 26)
|