1、本產品采用單片機+獨立按鍵+12864液晶顯示+RFID射頻模塊+繼電器模塊+串口模塊+上位機等組成。
2、下位機具有四個獨立按鍵分別為注冊功能、撤銷功能、充值功能、入庫和出庫等功能。
3、每張IC卡號相當于每輛車的車牌號,在IC卡刷第一次卡是車輛入庫,刷第二次卡是車輛出庫,液晶顯示車牌號、消費、余量、車輛狀態等信息,并且電機轉動來模擬開關。
4、只有注冊過的IC卡才進行停車、充值、撤銷、等操作,并且蜂鳴器會進行提示,無效卡刷卡時蜂鳴器響兩聲。
5、當IC卡余額小于0時, 液晶會顯示余額不足,并且蜂鳴器響兩聲提示,并且車輛是無法出入庫的。
6、上位機管理員可以對車輛信息進行增加、修改、查詢、刪除,并且可以設置IC卡,進和消費范圍0~255之間。
7、上位機可以顯示當前停車場剩下車位數量、用戶的停車狀態、停車總時間、每小時停車費用、消費、入庫時間、出庫時間、并且保存到數據庫方便管理員查詢記錄。
8、通過紅外傳感器檢測當前車位是否有車,并且液晶顯示指導哪里有空車位,方便用戶尋找車位。
9、語音模塊進行播報每次的消費、出入庫、注冊和撤銷、等信息。
制作出來的實物圖如下:
IMG_20210812_152552.jpg (1.41 MB, 下載次數: 45)
下載附件
2023-4-28 15:18 上傳
電路原理圖如下:
51hei.png (276.93 KB, 下載次數: 58)
下載附件
2023-4-28 18:36 上傳
單片機源程序如下:
- #include "reg52.h"
- #include "main.h"
- #include "mfrc522.h"
- #include "LCD12864.h"
- #include <string.h>
- #include <stdio.h>
- sbit rst=P1^2;
- sbit date=P1^1;
- sbit busy=P1^0;
- sbit BEEP=P2^0 ;
- sbit HY0=P2^2 ;
- sbit HY1=P2^3 ;
- sbit HY2=P2^4;
- sbit KEY1=P1^4;
- sbit LED=P1^3;
- #define SET_BEEP BEEP = 0
- #define CLR_BEEP BEEP = 1
- typedef unsigned int u16;
- typedef unsigned char u8;
- signed long money_value;
- signed long dat=0;
- unsigned char dat1=0,ii=0,iii=0,ii1=0,tt1=0;
- char string[]=" ";
- unsigned char code data2[4] = {0x12,0,0,0};
- unsigned char code DefaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- unsigned char idata MLastSelectedSnr[4];
- unsigned char idata RevBuffer[30];
- bit CmdValid;
- signed long xiaofei=0;
- signed long chongzhi=5000;
- unsigned char code ASCII_NUM[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
- unsigned char code Yankey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- unsigned char code XiugaiYunKey[16]= {0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0x07,0x80,0x69,0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- unsigned char code Nowkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE};
- unsigned char code XiugaiNowKey[16]= {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x80,0x69,0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
- unsigned char idata Read_Data[16]={0x00};
- unsigned char data OperationCard;
- uchar data bWarn,bPass,ttt=0,tt=0;
- #define REGCARD 0xa1
- #define CONSUME 0xa2
- #define READCARD 0xa3
- #define ADDMONEY 0xa4
- #define CHEXIAO 0xa5
- void delay(u16 i)
- {
- while(i--);
- }
- void read(uchar z)
- {
- rst=1;
- delay(220);
- rst=0;
- delay(220);
- while(z>0)
- {
- date=1;
- delay(110);
- date=0;
- delay(110);
- z--;
- }
- }
- void STC_send_bluetooth(unsigned char a)
- {
- TI=0;
- SBUF=a;
- while(TI==0);
- TI=0;}
- void KeyScan(void)
- {
- char string[]=" ";
- if(ttt==0)
- {
- if(KEY1 == 0)
- {
- delay_10ms(1);
- if(KEY1 == 0 )
- {
- OperationCard=CHEXIAO;
- tt=4;}
- }
- if(REGCARDBTN == 0)
- {
- delay_10ms(1);
- if(REGCARDBTN == 0 )
- OperationCard = REGCARD;
- tt=3;
- }
- if(CONSUMEBTN == 0)
- {
- delay_10ms(1);
- if(CONSUMEBTN == 0 )
- OperationCard = CONSUME; tt=1;
- }
- if(ADDMONEYBTN == 0)
- {
- delay_10ms(1);
- if(ADDMONEYBTN == 0 )
- OperationCard = ADDMONEY; tt=2;
- }
- }
- }
- void Warn(void)
- {
- uchar data ii;
- for(ii=0;ii<3;ii++)
- {
- SET_BEEP;
- delay_10ms(5);
- CLR_BEEP;
- delay_10ms(5);
- }
- }
- void boyin()
- {
-
- read(1);
- while(!busy);
- if(OperationCard==CONSUME)
- {
- read(17);
- while(!busy);
- if(xiaofei/10000!=0)
- {
- read(xiaofei/10000+1);
- while(!busy);
- read(12);
- while(!busy);
- }
- if(xiaofei%10000/1000!=0)
- {
- if((xiaofei/10000==0)&&(xiaofei%10000/1000==1))
- {
- read(11);
- while(!busy);}
- else
- { read(xiaofei%10000/1000+1);
- while(!busy);
- read(11);
- while(!busy);}
- }
- else if ((xiaofei/10000!=0)&&(xiaofei%10000/1000==0))
- {
- if(xiaofei%1000/100!=0)
- {
- read(31);
- while(!busy);
- }
- }
-
- if(xiaofei%1000/100!=0)
- {
- read(xiaofei%1000/100+1);
- while(!busy);
- }
-
- if(xiaofei%100/10!=0)
- {
- if((xiaofei/10000==0)&&(xiaofei%10000/1000==0)&&(xiaofei%1000/100==0))
- {
- read(31);
- while(!busy);
- }
- read(13);
- while(!busy);
- read(xiaofei%100/10+1);
- while(!busy);
- }
- if(xiaofei==0)
- {
- read(31);
- while(!busy);
- }
- read(30);
- while(!busy);
- }
- if(OperationCard==ADDMONEY)
- {
- read(19);
- while(!busy);
- if(chongzhi/10000!=0)
- {
- read(chongzhi/10000+1);
- while(!busy);
- read(12);
- while(!busy);
- }
-
- if(chongzhi%10000/1000!=0)
- {
- if((chongzhi/10000==0)&&(chongzhi%10000/1000==1))
- {
- read(11);
- while(!busy);}
- else
- { read(chongzhi%10000/1000+1);
- while(!busy);
- read(11);
- while(!busy);}
- }
- else if ((chongzhi/10000!=0)&&(chongzhi%10000/1000==0))
- {
- if(chongzhi%1000/100!=0)
- {
- read(31);
- while(!busy);
- }
- }
- if(chongzhi%1000/100!=0)
- {
- read(chongzhi%1000/100+1);
- while(!busy);
- }
- if(chongzhi==0)
- {
- read(31);
- while(!busy);
- }
- read(30);
- while(!busy);
- }
-
-
- read(18);
- while(!busy);
-
- if(money_value/1000000!=0)
- {
- read(money_value/1000000+1);
- while(!busy);
- read(23);
- while(!busy);
- }
-
-
-
- if(money_value%1000000/100000!=0)
- {
- read(money_value%1000000/100000+1);
- while(!busy);
- read(32);
- while(!busy);
- }
- else if((money_value/1000000!=0)&&(money_value%1000000/100000==0))
- {
- if((money_value%100000/10000==0)&&(money_value%10000/1000==0)&&(money_value%1000/100==0)){;}
- else
- {
- read(31);
- while(!busy);}
- }
-
-
- if(money_value%100000/10000!=0)
- {
- read(money_value%100000/10000+1);
- while(!busy);
- read(12);
- while(!busy);
- }
- else if((money_value%1000000/100000!=0)&&(money_value%100000/10000==0))
- {
-
- if((money_value%10000/1000==0)&&(money_value%1000/100==0)){;}
- else
- {
- read(31);
- while(!busy);}
- }
-
- if(money_value%10000/1000!=0)
- {
-
- read(money_value%10000/1000+1);
- while(!busy);
- read(11);
- while(!busy);
- }
- else if((money_value%100000/10000!=0)&&(money_value%10000/1000==0))
- {
- if(money_value%1000/100!=0)
- {
- read(31);
- while(!busy);}
- }
-
- if(money_value%1000/100!=0)
- {
- read(money_value%1000/100+1);
- while(!busy);
- }
-
- if(money_value%100/10!=0)
- {
- if((money_value/1000000==0)&&(money_value%1000000/100000==0)&&(money_value%100000/10000==0)&&(money_value%10000/1000==0)&&(money_value%1000/100==0))
- {
- read(31);
- while(!busy);
- }
- read(13);
- while(!busy);
- read(money_value%100/10+1);
- while(!busy);
- }
- if(money_value==0)
- {
- read(31);
- while(!busy);
- }
- read(30);
- while(!busy);
- }
- void WaitCardOff(void)
- {
- char status;
- unsigned char TagType[2];
- while(1)
- {
- status = PcdRequest(PICC_REQALL , TagType);
- if(status)
- {
- status = PcdRequest(PICC_REQALL , TagType);
- if(status)
- {
- status = PcdRequest(PICC_REQALL , TagType);
- if(status)
- {
- return;
- }
- }
- }
- }
- }
- void Pass(void)
- {
- SET_BEEP;
- delay_10ms(30);
- CLR_BEEP;
- }
- void CtrlProcess(void)
- {
-
- unsigned char idata Write_Consume_Data[16];
- float f_money_value;
- unsigned char ii;
- char status;
- status=PcdRequest(PICC_REQIDL,&RevBuffer[0]);
-
- if(status!=MI_OK)
- return;
-
- for(ii=0;ii<2;ii++)
- {
- string[2*ii] = ASCII_NUM[(RevBuffer[ii]>>4)&0x0f];
- string[2*ii+1] = ASCII_NUM[RevBuffer[ii]&0x0f];
-
- }
- string[4] = '\0';
-
- LCD_PutString(0,2,"3μ??£o ");
- LCD_PutString(0,3," ");
-
- status=PcdAnticoll(&RevBuffer[2]);
- if(status!=MI_OK)
- return;
- memcpy(MLastSelectedSnr,&RevBuffer[2],4);
- for(ii=0;ii<4;ii++)
- {
- string[2*ii] = ASCII_NUM[(MLastSelectedSnr[ii]>>4)&0x0f];
- string[2*ii+1] = ASCII_NUM[MLastSelectedSnr[ii]&0x0f];
- }
- string[9] = '\0';
- LCD_PutString(3,2,string);
-
- status=PcdSelect(MLastSelectedSnr);
- if(status!=MI_OK)
- return;
-
- if(OperationCard==REGCARD)
- {
- while(1)
- {
-
- LCD_PutString(0,1, ");
- status=PcdAuthState(PICC_AUTHENT1A,7,Yankey,MLastSelectedSnr);
-
- if(status!=MI_OK)
- { LCD_PutString(0,3," "); LCD_PutString(0,4," ");Warn(); read(25);while(!busy); WaitCardOff(); break; }
- status=PcdWrite(7,XiugaiYunKey);
-
- if(status!=MI_OK)
- {
-
- break;
- }
- for(ii=0;ii<16;ii++)
- {
- Write_Consume_Data[ii]=0xaa;
- }
- memset( Write_Consume_Data, 0, sizeof(Write_Consume_Data) );
- money_value = 0000;
- memcpy( Write_Consume_Data, ( uchar * )&money_value, 4 );
-
- status=PcdWrite(4,&Write_Consume_Data[0]);
- if(status!=MI_OK)
- {
- bWarn=1;
- break;
- }
- LCD_PutString(0,3," ");
- LCD_PutString(0,4," ");
- Pass();
- PcdHalt();
- read(21);
- while(!busy);
- break;
- }
- }
- if(OperationCard==CHEXIAO)
- {
- while(1)
- {
- LCD_PutString(0,1," ");
- status = PcdAuthState(PICC_AUTHENT1A,7,Nowkey,MLastSelectedSnr);
- if(status!=MI_OK)
- { LCD_PutString(0,4," "); Warn(); read(15); while(!busy); WaitCardOff(); break; }
- status=PcdWrite(7,XiugaiNowKey);
-
- if(status!=MI_OK)
- {
- break;
- }
- for(ii=0;ii<16;ii++)
- {
- Write_Consume_Data[ii]=0xaa;
- }
- memset( Write_Consume_Data, 0, sizeof(Write_Consume_Data) );
- money_value = 0000;
- memcpy( Write_Consume_Data, ( uchar * )&money_value, 4 );
-
- status=PcdWrite(4,&Write_Consume_Data[0]);
- if(status!=MI_OK)
- {
- bWarn=1;
- break;
- }
- LCD_PutString(0,3," ");
- Pass();
- PcdHalt();
- read(22);
- while(!busy);
- break;
- }
- }
-
- else if(OperationCard==CONSUME)
- {
- while(1)
- {
-
- status=PcdAuthState(PICC_AUTHENT1A,7,Nowkey,MLastSelectedSnr);
-
-
- if(ii1==3) {ii1=0;Warn();}
- status=PcdRead(4,Read_Data);
- if(status!=MI_OK)
- {
- break;
- }
-
- memcpy( (uchar *)&money_value, Read_Data, 4 );
- if(money_value>0)
- {
-
- STC_send_bluetooth('Y');
- delay_10ms(10);
- STC_send_bluetooth(string[0] );
- STC_send_bluetooth(string[1] );
- STC_send_bluetooth(string[2] );
- STC_send_bluetooth(string[3] );
- STC_send_bluetooth(string[4] );
- STC_send_bluetooth(string[5] );
- STC_send_bluetooth(string[6] );
- STC_send_bluetooth(string[7] );
- bPass=1;
- delay_10ms(20);
- if(iii==0){ LCD_PutString(0,1," ");}
- money_value=money_value-xiaofei;
- if(money_value>0)
- {
- if(iii==1){ if(HY0==1) {LCD_PutString(0,1," ");STC_send_bluetooth('S');}
- if((HY0==0)&&(HY1==1)) {LCD_PutString(0,1," ");STC_send_bluetooth('T');}
- if((HY0==0)&&(HY1==0)&&(HY2==1)) {LCD_PutString(0,1," ");STC_send_bluetooth('M');}
- if((HY0==0)&&(HY1==0)&&(HY2==0)) {LCD_PutString(0,1," ");STC_send_bluetooth('N');}
- }
- if(iii==2){ LCD_PutString(0,1,"");}
- if(tt1==1) { LED=0; tt1=0;} }
-
- else {money_value=money_value+xiaofei;xiaofei=0; LCD_PutString(0,1," ");Warn();iii=0;}
- memcpy( Write_Consume_Data, (uchar *)&money_value, 4 );
- status=PcdWrite(4,&Write_Consume_Data[0]);
- delay_10ms(10);
- if(status!=MI_OK)
- {
-
- break;
- }
-
- LCD_PutString(0,3," ");
- LCD_PutString(0,4," ");
- string[0]=xiaofei/10000+0x30;
- string[1]=xiaofei%10000/1000+0x30;
- string[2]=xiaofei%1000/100+0x30;
- string[3]='.';
- string[4]=xiaofei%100/10+0x30;
- string[5] = '\0';
- delay_10ms(3);
- LCD_PutString(3,3,string );
-
-
- f_money_value = money_value * 1.0/100;
- sprintf(string,"%5.1f",f_money_value);
- LCD_PutString(3,4,string);
- delay_10ms(10);
- STC_send_bluetooth('Z');
- delay_10ms(10);
- STC_send_bluetooth(string[0]);
- STC_send_bluetooth(string[1]);
- STC_send_bluetooth(string[2]);
- STC_send_bluetooth(string[3]);
- STC_send_bluetooth(string[4]);
- STC_send_bluetooth(string[5]);
- Pass();
- delay_10ms(10);
- LED=1;
- if(iii==0){boyin();};
- if(iii==1){ read(27);while(!busy);iii=0;}
- if(iii==2){ boyin();iii=0;}
- }
- else
- { LCD_PutString(0,3,"");
- LCD_PutString(0,4," ");
- f_money_value = money_value * 1.0/100;
- sprintf(string,"%5.2f",f_money_value);
- LCD_PutString(3,4,string);
- Warn();
- read(14);
- while(!busy);
- }
- PcdHalt();
- break;
- }
- }
- else if(OperationCard==ADDMONEY)
- { while(1)
- {
- LCD_PutString(0,1," ");
- status=PcdAuthState(PICC_AUTHENT1A,7,Nowkey,MLastSelectedSnr);
- status=PcdRead(4,Read_Data);
- if(status!=MI_OK)
- {
-
- break;
- }
-
- memcpy( (uchar *)&money_value, Read_Data, 4 );
- money_value=money_value+chongzhi;
- memcpy( Write_Consume_Data, (uchar *)&money_value, 4 );
- status=PcdWrite(4,&Write_Consume_Data[0]);
-
- if(status!=MI_OK)
- {
- break;
- }
-
- LCD_PutString(0,3," ");
- LCD_PutString(0,4," ");
- string[0]=chongzhi/10000+0x30;
- string[1]=chongzhi%10000/1000+0x30;
- string[2]=chongzhi%1000/100+0x30;
- string[3] = '\0';
- delay_10ms(1);
- LCD_PutString(3,3,string );
- f_money_value = money_value * 1.0/100;
- sprintf(string,"%5.1f",f_money_value);
- LCD_PutString(3,4,string);
- delay_10ms(1);
- PcdHalt();
- Pass();
- boyin() ;
- break;
- }
- }
- LED=1;
- WaitCardOff();
- PcdHalt();
- BEEP=1;
- }
- void InitializeSystem()
- {
- CmdValid=0;
- PcdReset();
- PcdAntennaOff();
- PcdAntennaOn();
- M500PcdConfigISOType( 'A' );
- }
- void UartProcess(void)
- {
- unsigned char baud;
- if(RevBuffer[0]==11)
- {
- RevBuffer[2]=RevBuffer[1];
- RevBuffer[0]=1;
- RevBuffer[1]=0;
- CALL_isr_UART();
- LED_GREEN = 1;
- delay_10ms(RevBuffer[2]);
- LED_GREEN = 0;
- }
- else if(RevBuffer[0]==13)
- {
- switch(RevBuffer[1])
- {
- case 0:
- baud=BAUD_9600;
- break;
-
- }
- RevBuffer[0]=1;
- RevBuffer[1]=0;
- CALL_isr_UART();
- delay_10ms(5);
- TR1 = 0;
- TH1 = baud;
- TL1 = TH1;
- delay_10ms(2);
- TR1 = TRUE;
- }
- else
- {
-
- CALL_isr_UART();
- }
- }
- void InitializeSystem1()
- {
- P0 = 0xFF; P1 = 0xFF; P3 = 0xFF;P2 = 0xFF;
- TMOD = 0x21;
- TH1 = 0xFd;
- TL1 = 0xFd;
- TH0 = 0xfe;
- TL0 = 0x33;
-
- ET0 = 1;
- TR0 = 1;
- SM0 = 0;
- SM1 = 1;
- REN = 1;
- TR1 = 1;
- ES = 1;
- EA = 1;
- }
- void timer0() interrupt 1
- {
- TH0=0xfe;
- TL0=0xee;
- }
- void sint() interrupt 4
- {
- if(RI)
- {
- RI=0;
- dat=SBUF;
- dat1=SBUF;
- if(ii==1) {xiaofei=dat*100;ii=0;}
- if(ii==2) {chongzhi=dat*100;ii=0;}
- if(dat1=='A') { ii=1;}
- if(dat1=='G') { tt1=1;}
- if(dat1=='H') { ii=2;}
- if(dat1=='D') { ii1=3;}
- if(dat1=='E') { iii=1;}
- if(dat1=='F') { iii=2;}
- if(dat1=='L') { xiaofei=0;}
- if(dat1=='T') { xiaofei=0;}
- }
- }
-
-
-
- void main( )
- {
- Init_ST7920();
- ClrScreen();
- InitializeSystem( );
- InitializeSystem1( );
- OperationCard = 0;
- CALL_isr_UART();
- STC_send_bluetooth('J');
- tt=1;
- OperationCard = CONSUME;
- while (1)
- {
- if (CmdValid)
- {
- CmdValid = FALSE;
- UartProcess();
- }
- rst=0;
- date=0;
- busy=0;
- KeyScan();
- if(ttt==0 && tt==1)
- {
- LCD_PutString(0,1," ");
- LCD_PutString(0,2," ");
- LCD_PutString(0,3," ");
- LCD_PutString(0,4," ");
- CtrlProcess();
-
- }
- if(tt==2)
- {
- LCD_PutString(0,1," ");
- LCD_PutString(0,2," ");
- LCD_PutString(0,3," ");
- LCD_PutString(0,4," ");
- CtrlProcess();
-
- }
- if(tt==3)
- {
- LCD_PutString(0,1," ");
- LCD_PutString(0,2," ");
- LCD_PutString(0,3," ");
- LCD_PutString(0,4," ");
- CtrlProcess();
-
- }
- if(tt==4)
- {
- LCD_PutString(0,1," ");
- LCD_PutString(0,2," ");
- LCD_PutString(0,3," ");
- LCD_PutString(0,4," ");}
- CtrlProcess();
- ii=0;
- tt1= 0;
- ii1=0;
- iii=0;
- }
- }
復制代碼
|