基于STM32单片机的智能充电桩计费系统的设计(程序+原理图+论文报告)
原理图:Altium Designer
程序编译器:keil 5
编程语言:C语言
编号C0022
【腾讯文档】C0022 网盘链接
资料下载链接 点击即可跳转现实工艺与生活中,普通的物理控制方案逐渐不能满足科技需求,逐一被淘汰,若采用现阶段发展成熟的智能控制方案可以技术发展需要。在产品的可靠性、安全性、便捷性和维护简易来看目前的充电桩计费系统是不能满足要求,因此运用智能控制器开发充电桩计费系统可以解决目前产品所在的问题,本设计系统运用ST公司MCU平台进行研究。
实现功能如下:
1.本设计系统通过IC卡注册新号,然后可以录入指纹,LCD1602液晶屏显示系统运行信息;当注销IC卡片,需要验证指纹,其中一个指纹正确才可成功注销;
2. 系统可以实现对卡片进行充值。系统掉电后IC卡内金额不消失;
3. 对三个充电桩进行选择;充电桩选择完选择三个充电时间和金额(1min 1rmb,2min 2rmb,3min 3rmb);
4. 选择好充电桩和充电时间后,刷卡并验证指纹(其中一个正确)后开始充电;
5. 充电时,刷完卡验证完指纹后如果金额不足蜂鸣器报警;时间到后继电器断开表示充电完成。
原理图(提供源文件):
源程序(提供源文件):
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);//设置系统中断优先级分组2
delay_init(); //初始化延时函数
uart_init(115200); //初始化串口1波特率为115200,用于支持USMART
usart2_init(usart2_baund);//初始化串口2,用于与指纹模块通讯
PS_StaGPIO_Init(); //初始化FR读状态引脚
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);//读库指纹个数
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)//选择设置
{
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("产生一个指纹模板 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;//刷完卡,并验证完指纹
}
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 函数
//确保一次发送数据不超过USART2_MAX_SEND_LEN字节
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); //此次发送数据的长度
for(j=0;j<i;j++) //循环发送数据
{
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET); //循环发送,直到发送完毕
USART_SendData(USART3,USART3_TX_BUF[j]);
}
}
论文报告:
资料清单如下: