基于STM32單片機(jī)的智能充電樁計(jì)費(fèi)系統(tǒng)的設(shè)計(jì)(程序+原理圖+論文報(bào)告)
原理圖:Altium Designer
程序編譯器:keil 5
編程語言:C語言
編號C0022
【騰訊文檔】C0022 網(wǎng)盤鏈接
資料下載鏈接 點(diǎn)擊即可跳轉(zhuǎn)現(xiàn)實(shí)工藝與生活中,普通的物理控制方案逐漸不能滿足科技需求,逐一被淘汰,若采用現(xiàn)階段發(fā)展成熟的智能控制方案可以技術(shù)發(fā)展需要。在產(chǎn)品的可靠性、安全性、便捷性和維護(hù)簡易來看目前的充電樁計(jì)費(fèi)系統(tǒng)是不能滿足要求,因此運(yùn)用智能控制器開發(fā)充電樁計(jì)費(fèi)系統(tǒng)可以解決目前產(chǎn)品所在的問題,本設(shè)計(jì)系統(tǒng)運(yùn)用ST公司MCU平臺進(jìn)行研究。
實(shí)現(xiàn)功能如下:
1.本設(shè)計(jì)系統(tǒng)通過IC卡注冊新號,然后可以錄入指紋,LCD1602液晶屏顯示系統(tǒng)運(yùn)行信息;當(dāng)注銷IC卡片,需要驗(yàn)證指紋,其中一個(gè)指紋正確才可成功注銷;
2. 系統(tǒng)可以實(shí)現(xiàn)對卡片進(jìn)行充值。系統(tǒng)掉電后IC卡內(nèi)金額不消失;
3. 對三個(gè)充電樁進(jìn)行選擇;充電樁選擇完選擇三個(gè)充電時(shí)間和金額(1min 1rmb,2min 2rmb,3min 3rmb);
4. 選擇好充電樁和充電時(shí)間后,刷卡并驗(yàn)證指紋(其中一個(gè)正確)后開始充電;
5. 充電時(shí),刷完卡驗(yàn)證完指紋后如果金額不足蜂鳴器報(bào)警;時(shí)間到后繼電器斷開表示充電完成。
原理圖(提供源文件):
源程序(提供源文件):
void Add_FR(void); //添加指紋
void Del_FR(void); //刪除指紋
void press_FR(void);//比對指紋
void My_USART3_Init(void);//串口3初始化
void u3_printf(char* fmt,...);
/*******************************
*????:
*1--SS <----->PB0
*2--SCK <----->PB13
*3--MOSI<----->PB15
*4--MISO<----->PB14
*5--??
*6--GND <----->GND
*7--RST <----->PB1
*8--VCC <----->VCC
************************************/
void InitializeSystem()
{
SPI2_Init();
CmdValid=0;
PcdReset();
PcdAntennaOff();
PcdAntennaOn();
M500PcdConfigISOType( 'A' );
delay_ms(100);
delay_ms(100);
}
char aas[20];
char aat[20];
char aax[20];
char aay[20];
char aaz[20];
int main(void)
{
unsigned char status,i;
unsigned char temp;
u8 ensure;
char *str;
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設(shè)置系統(tǒng)中斷優(yōu)先級分組2
delay_init(); //初始化延時(shí)函數(shù)
uart_init(115200); //初始化串口1波特率為115200,用于支持USMART
usart2_init(usart2_baund);//初始化串口2,用于與指紋模塊通訊
PS_StaGPIO_Init(); //初始化FR讀狀態(tài)引腳
GPIO_Configuration();
LCD1602_Init();
LED_Init();
/// My_USART3_Init();
/// TIM4_Int_Init(4999,7199);//10Khz?????,???5000?500ms
KEY_Init();
printf("aaaaaaaaaarn");
//與指紋模塊握手
while(PS_HandShake(&AS608Addr))
{
printf("我手失敗rn");
}
//握手通過
printf(" Ready To Work rn");
printf("Baudrate:%d Addr:%x",usart2_baund,AS608Addr);//顯示波特率
ensure=PS_ValidTempleteNum(&ValidN);//讀庫指紋個(gè)數(shù)
LCD1602_ClearScreen();
delay_ms(3000);
InitializeSystem( );
Del_FR();
delay_ms(100);
GPIO_ResetBits(GPIOB,GPIO_Pin_10);
GPIO_ResetBits(GPIOB,GPIO_Pin_11);
GPIO_ResetBits(GPIOC,GPIO_Pin_14);
GPIO_SetBits(GPIOA,GPIO_Pin_4);
while(1)
{
sprintf(aas,"ID%d",ID);
LCD1602_Show_String(13,0,3,aas);
if(ID>1)
{
IC_flag=1;
}
//注冊IC卡
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_3)==0)
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_3)==0)
{
LCD1602_Show_String(0,0,3,"IN ");
//IC_flag=1;
}
}
//注銷IC卡
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_4)==0)
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_4)==0)
{
IC_flagaaa=1;
}
}
///從左向右依次是PC15 PA15 PA5
if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_15)==0)//選擇設(shè)置
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_15)==0)
{
while(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_15)==0);
flag_flag++;
}
}
switch(flag_flag)
{
case 1:
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15)==0)
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15)==0)
{
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15)==0);
kapianjiage=kapianjiage+100;
if(kapianjiage>900)
{
kapianjiage=900;
}
}
}
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5)==0)
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5)==0)
{
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5)==0);
kapianjiage=kapianjiage-100;
if(kapianjiage<0)
{
kapianjiage=0;
}
}
}
break;
case 2:
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15)==0)
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15)==0)
{
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15)==0);
chongdianzhuang++;
if(chongdianzhuang>3)
{
chongdianzhuang=3;
}
}
}
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5)==0)
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5)==0)
{
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5)==0);
chongdianzhuang--;
if(chongdianzhuang<1)
{
chongdianzhuang=1;
}
}
}
break;
case 3:
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15)==0)
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15)==0)
{
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15)==0);
chongdianshijian++;
if(chongdianshijian>3)
{
chongdianshijian=3;
}
}
}
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5)==0)
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5)==0)
{
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5)==0);
chongdianshijian--;
if(chongdianshijian<1)
{
chongdianshijian=1;
}
}
}
break;
case 4:
flag_flag=0;
break;
}
int kapianjiage=0;
int chongdianzhuang=0;
int chongdianshijian=0;
if(kapianjiage>99)
{
sprintf(aax,"J:%d",kapianjiage);
}
else if(kapianjiage>9&&kapianjiage<100)
{
sprintf(aax,"J:%d ",kapianjiage);
}
else
{
sprintf(aax,"J:%d ",kapianjiage);
}
LCD1602_Show_String(4,0,5,aax);
sprintf(aay,"Z:%d",chongdianzhuang);
LCD1602_Show_String(10,0,3,aay);
switch(chongdianshijian)
{
case 1:
LCD1602_Show_String(8,1,8,"1min1rmb");
break;
case 2:
LCD1602_Show_String(8,1,8,"2min2rmb");
break;
case 3:
LCD1602_Show_String(8,1,8,"3min3rmb");
break;
default:
break;
}
if(IC_flag_flag==2)
{
if(kapianjiage<chongdianshijian)//缺錢
{
printf("%d--%d",kapianjiage,chongdianshijian);
GPIO_ResetBits(GPIOA,GPIO_Pin_4);
}
else
{
printf("%d--%d",kapianjiage,chongdianshijian);
GPIO_SetBits(GPIOA,GPIO_Pin_4);
switch(chongdianzhuang)
{
case 1:
GPIO_SetBits(GPIOB,GPIO_Pin_10);
GPIO_ResetBits(GPIOB,GPIO_Pin_11);
GPIO_ResetBits(GPIOC,GPIO_Pin_14);
break;
case 2:
GPIO_ResetBits(GPIOB,GPIO_Pin_10);
GPIO_SetBits(GPIOB,GPIO_Pin_11);
GPIO_ResetBits(GPIOC,GPIO_Pin_14);
break;
case 3:
GPIO_ResetBits(GPIOB,GPIO_Pin_10);
GPIO_ResetBits(GPIOB,GPIO_Pin_11);
GPIO_SetBits(GPIOC,GPIO_Pin_14);
break;
default:
break;
}
switch(chongdianshijian)
{
case 1:
if(time1<10)
{
sprintf(aat,"T%d ",time1);
}
else
{
sprintf(aat,"T%d ",time1);
}
LCD1602_Show_String(3,1,4,aat);
time1--;
if(time1<0)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_10);
GPIO_ResetBits(GPIOB,GPIO_Pin_11);
GPIO_ResetBits(GPIOC,GPIO_Pin_14);
IC_flag_flag=0;
kapianjiage--;
time1=60;
}
delay_ms(1000);
break;
case 2:
if(time2>99)
{
sprintf(aat,"T%d",time2);
}
else if(time2>9&&time2<100)
{
sprintf(aat,"T%d ",time2);
}
else
{
sprintf(aat,"T%d ",time2);
}
LCD1602_Show_String(3,1,4,aat);
time2--;
if(time2<0)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_10);
GPIO_ResetBits(GPIOB,GPIO_Pin_11);
GPIO_ResetBits(GPIOC,GPIO_Pin_14);
IC_flag_flag=0;
kapianjiage=kapianjiage-2;
time2=120;
}
delay_ms(1000);
break;
case 3:
if(time3>99)
{
sprintf(aat,"T%d",time3);
}
else if(time3>9&&time3<100)
{
sprintf(aat,"T%d ",time3);
}
else
{
sprintf(aat,"T%d ",time3);
}
LCD1602_Show_String(3,1,4,aat);
time3--;
if(time3<0)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_10);
GPIO_ResetBits(GPIOB,GPIO_Pin_11);
GPIO_ResetBits(GPIOC,GPIO_Pin_14);
IC_flag_flag=0;
kapianjiage=kapianjiage-3;
time3=180;
}
delay_ms(1000);
break;
default:
break;
}
}
}
//刷指紋
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7)==0)
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7)==0)
{
while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7)==0);
//setup=setup+2000;
LCD1602_Show_String(0,1,3,"CHE");
press_FR();//刷指紋
printf(" FUN:CHECK FRIGER rn");
}
}
//添加指紋
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_8)==0)
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_8)==0)
{
//setup=setup+2000;
LCD1602_Show_String(0,1,3,"ADD");
Add_FR();
printf(" FUN:ADD FRIGER rn");
}
}
//刪除指紋
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==0)
{
delay_ms(10);
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==0)
{
LCD1602_Show_String(0,1,3,"DEL");
Del_FR();
printf(" FUN:DEL FRIGER rn");
}
}
status = PcdRequest(PICC_REQALL,g_ucTempbuf);/*???*/
if(status!=0) //???????
{
}
status = PcdAnticoll(g_ucTempbuf);/*???*/
if(status!=0)
{
continue;
}
if(IC_flag==1)
{
if(g_ucTempbuf[0]==0xc3&&g_ucTempbuf[1]==0x4e&&g_ucTempbuf[2]==0x6a&&g_ucTempbuf[3]==0x03)
{
IC_flag_flag=1;
}
}
status = PcdSelect(g_ucTempbuf);//
status = PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey, g_ucTempbuf);//??????
if (status == MI_OK)
{
//printf("??????n");
}
status = PcdWrite(1, da1);
if(status==0)
{
//printf("????n");
}
else
{
//printf("????");
//LCD_Write_String(1,0," ???? ");
}
}
}
void ShowErrMessage(u8 ensure)
{
}
void Add_FR(void)
{
u8 i=0,ensure ,processnum=0;
while(1)
{
switch (processnum)
{
case 0:
i++;
printf(" 請按手指! rn");
ensure=PS_GetImage();
if(ensure==0x00)
{
ensure=PS_GenChar(CharBuffer1);//????
if(ensure==0x00)
{
printf(" 指紋正確 rn");
i=0;
processnum=1;
}else ShowErrMessage(ensure);
}else ShowErrMessage(ensure);
break;
case 1:
i++;
printf(" 再按一次手指 rn");
ensure=PS_GetImage();
if(ensure==0x00)
{
ensure=PS_GenChar(CharBuffer2);//
if(ensure==0x00)
{
printf(" 指紋正確 rn");
i=0;
processnum=2;
}else ShowErrMessage(ensure);
}else ShowErrMessage(ensure);
break;
case 2:
printf(" 對比兩次指紋 rn");
ensure=PS_Match();
if(ensure==0x00)
{
printf(" 兩次指紋是一樣的 rn");
processnum=3;
}
else
{
printf(" 對比失敗,請重新按手指 rn");
ShowErrMessage(ensure);
i=0;
processnum=0;
}
delay_ms(1000);
break;
case 3:
printf("產(chǎn)生一個(gè)指紋模板 rn");
ensure=PS_RegModel();
if(ensure==0x00)
{
printf(" 生成指紋模板成功!rn");
processnum=4;//?????
}else {processnum=0;ShowErrMessage(ensure);}
delay_ms(1000);
break;
case 4:
do
// ID=1;
while(!(ID<300));
ID++;
ensure=PS_StoreChar(CharBuffer2,ID);
printf(" ID為%drn",ID);
if(ensure==0x00)
{
printf(" 輸入ID并按“Enter”保存! rn");
PS_ValidTempleteNum(&ValidN);
delay_ms(1500);
return ;
}else {processnum=0;ShowErrMessage(ensure);}
break;
}
delay_ms(800);
if(i==5)//
{
break;
}
}
}
/**************************************************************
DESC:對比指紋
*****************************************************************/
void press_FR(void)
{
SearchResult seach;
u8 ensure;
//printf(" Begin Compare rn");
ensure=PS_GetImage();
if(ensure==0x00)//
{
ensure=PS_GenChar(CharBuffer1);
if(ensure==0x00) //
{
ensure=PS_HighSpeedSearch(CharBuffer1,0,300,&seach);
if(ensure==0x00)//
{
if(IC_flagaaa==1)
{
LCD1602_Show_String(0,0,3,"OFF");
GPIO_SetBits(GPIOA,GPIO_Pin_4);
IC_flag=0;
IC_flag_flag=0;
}
if(IC_flag_flag==1)
{
IC_flag_flag=2;//刷完卡,并驗(yàn)證完指紋
}
printf("jimiji");
LCD1602_Show_String(0,1,5,"OPEN ");
GPIO_SetBits(GPIOB,GPIO_Pin_10);
}
else
{
//printf(" Comper Fail! rn");
}
}
else
{
//printf(" Comper Fail! rn");
}
delay_ms(1000);//
}
}
/******************************************************************************
DESC:刪除指紋
*******************************************************************************/
void Del_FR(void)
{
u8 ensure;
delay_ms(50);
ensure=PS_Empty();//?????
if(ensure==0)
{
printf(" FINGER DELL OK rn");
printf(" FUN:DEL FRIGER rn");
}
delay_ms(1500);//???????
}
void My_USART3_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Enable the USART3 Pins Software Remapping */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/* Configure USART3 Rx (PB.11) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART3 Tx (PB.10) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Enable the USART3 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
//USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
/* Enable USART3 */
USART_Cmd(USART3, ENABLE);
}
//串口2,printf 函數(shù)
//確保一次發(fā)送數(shù)據(jù)不超過USART2_MAX_SEND_LEN字節(jié)
void u3_printf(char* fmt,...)
{
u16 i,j;
va_list ap;
va_start(ap,fmt);
vsprintf((char*)USART3_TX_BUF,fmt,ap);
va_end(ap);
i=strlen((const char*)USART3_TX_BUF); //此次發(fā)送數(shù)據(jù)的長度
for(j=0;j<i;j++) //循環(huán)發(fā)送數(shù)據(jù)
{
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET); //循環(huán)發(fā)送,直到發(fā)送完畢
USART_SendData(USART3,USART3_TX_BUF[j]);
}
}
論文報(bào)告:
資料清單如下: