当前位置:网站首页>Design of STM32 and rc522 simple bus card system
Design of STM32 and rc522 simple bus card system
2022-06-27 22:50:00 【One Internet of things rookie】
Catalog
System structure block diagram
Pin connection and related interface design
Preface
This blog aims to provide you with a bus card system design ideas , Please refer to my last blog for related hardware and the process of card reading and writing .
System structure block diagram

The hardware used at present is RC522,STM32 And matrix keyboard , The physical drawing is as follows :

Pin connection and related interface design
RC522 The related pins have been mentioned in my last blog , Please click the link at the beginning of this blog to view ,4x4 The pins we use in the relevant lines of the matrix keyboard are PF8,9,10,11, The pins used in the relevant columns are PF12,13,14,15.
Key related codes are as follows :
Key initialization function
void Matrix_ssKey_Pin_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;// Line key
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU ;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;// Column key
GPIO_Init(GPIOF,&GPIO_InitStructure);
}
Key scan function
int Matrix_Key_Scan(void)
{
u8 temp = 0;
int key_val = -1;
GPIO_ResetBits(GPIOF,GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11);
delay_us(10);
temp=(GPIO_ReadInputData(GPIOF) >> 8)&0xff;
if (temp == 0xf0)
{
delay_ms(50);
GPIO_ResetBits(GPIOF,GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11);
delay_us(10);
temp=(GPIO_ReadInputData(GPIOF) >> 8)&0xff;
if (temp != 0xf0)
{
GPIO_Write(GPIOF,0);
delay_ms(5);
GPIO_Write(GPIOF,(uint16_t)(0xFE << 8));
if(((GPIO_ReadInputData(GPIOF) >> 8) & 0XF0) != 0XF0)
{
delay_ms(20);
if(((GPIO_ReadInputData(GPIOF) >> 8) & 0XF0) != 0XF0)
{
temp=((GPIO_ReadInputData(GPIOF) >> 8) & 0XFE);
switch(temp)
{
case 0xEE: key_val = 1; break;
case 0xDE: key_val = 2; break;
case 0xBE: key_val = 3; break;
case 0x7E: key_val = 4; break;
default: key_val = -1; break;
}
}
}
GPIO_Write(GPIOF,0);
delay_ms(5);
GPIO_Write(GPIOF,(uint16_t)(0xFD << 8));
if(((GPIO_ReadInputData(GPIOF) >> 8) & 0XF0)!= 0XF0)
{
delay_ms(20);
if(((GPIO_ReadInputData(GPIOF) >> 8) & 0XF0) != 0XF0)
{
temp=((GPIO_ReadInputData(GPIOF) >> 8) & 0XFD);
switch(temp)
{
case 0xED: key_val = 5; break;
case 0xDD: key_val = 6; break;
case 0xBD: key_val = 7; break;
case 0x7D: key_val = 8; break;
default: key_val = -1; break;
}
}
}
GPIO_Write(GPIOF,0);
delay_ms(5);
GPIO_Write(GPIOF,(uint16_t)(0xFB << 8));
if(((GPIO_ReadInputData(GPIOF) >> 8) & 0XF0) != 0XF0)
{
delay_ms(20);
if(((GPIO_ReadInputData(GPIOF) >> 8) & 0XF0) != 0XF0)
{
temp=((GPIO_ReadInputData(GPIOF) >> 8) & 0XFB);
switch(temp)
{
case 0xEB: key_val = 9; break;
case 0xDB: key_val = 10; break;
case 0xBB: key_val = 11; break;
case 0x7B: key_val = 12; break;
default: key_val = -1; break;
}
}
}
GPIO_Write(GPIOF,0);
delay_ms(5);
GPIO_Write(GPIOF,(uint16_t)(0xF7 << 8));
if(((GPIO_ReadInputData(GPIOF) >> 8) & 0XF0) !=0XF0)
{
delay_ms(20);
if(((GPIO_ReadInputData(GPIOF) >> 8) & 0XF0) != 0XF0)
{
temp=((GPIO_ReadInputData(GPIOF) >> 8) & 0XF7);
switch(temp)
{
case 0xE7: key_val = 13; break;
case 0xD7: key_val = 14; break;
case 0xB7: key_val = 15; break;
case 0x77: key_val = 16; break;
default: key_val = -1; break;
}
}
}
}
}
return key_val;
}
Software flow chart

Commissioning process
The function I designed at the beginning is to write the card number and define it in the array , But in this case, there is no card issuing function , So I thought about setting up an empty array , When reading the card, put the card number into this array . And then , I'm having trouble setting up my personal information , After I press a button , You don't need to press the next three buttons, and he will automatically follow the first button , So I looked in the code for the reason , It turns out that every time you input a key, you need to rescan , Otherwise, the key will stay at the previous value .
After the card issuing and personal information binding settings are completed , I want to set up the loss reporting and release reporting functions . At this time, I used a temporary array , Used for temporary storage of card numbers .

When the entered personal information matches the corresponding card , Just store the card number in the temporary array .

At first, I only considered the correct input , Failure to take into account the error of input information , So I made a small change to the function , hold if Changed to else if Finally, if the personal information entered does not match , The password error will be printed .

When designing the debit function of the card , Due to the decimal digits to be deducted , At first, I didn't think of a good way to set decimal places . Then I suddenly thought of a way , The tenth digit of the data is used as the decimal place , Like data 100, Then the actual amount is 10.0. According to this idea , I changed the code .

Divide the data of the value block by 10 Re cast to double type , In this way, the decimal function is realized . However, the disadvantage of this is that the overall available amount is ten times less .
When I thought all the functions were designed to be the same , I found another problem , That is the module of loss reporting and release reporting , I originally wrote this function after reading the card successfully . The actual function is the function that cannot enter the loss reporting and release reporting mode without swiping the card , This is not consistent with the actual situation , I just want to report the loss because I lost my card , Now you want me to swipe my card , What brush do I take ? So I wrote this function before reading the card , such , Even if you don't swipe your card , You can also enter the card loss reporting and cancellation reporting functions , More in line with the actual situation .
Related codes
Loss reporting code
if(WK_UP==1)// Enter the loss reporting and release reporting mode
{
printf("\r\n Enter the loss reporting and release reporting mode \r\n");
printf("\r\n Press down S1 Enter loss reporting mode , Press down S2 Enter the release loss reporting mode \r\n");
while(1)
{
key_val = Matrix_Key_Scan();
if(key_val > 0 && key_val < 17)
{
if(key_val==1)// Enter loss reporting mode
{
printf("\r\n Enter loss reporting mode \r\n");
printf("\r\n Please enter 4 Personal information \r\n");
while(1)
{
key_val = Matrix_Key_Scan();
if(key_val > 0 && key_val < 17)//¸ Personal information comes first
{
if(key_val==1)card_3[0]=1;
if(key_val==2)card_3[0]=2;
if(key_val==3)card_3[0]=3;
if(key_val==4)card_3[0]=4;
if(key_val==5)card_3[0]=5;
if(key_val==6)card_3[0]=6;
if(key_val==7)card_3[0]=7;
if(key_val==8)card_3[0]=8;
if(key_val==9)card_3[0]=9;
if(key_val==10)card_3[0]=0;
printf("\r\n %d \r\n",card_3[0]);
if(card_3[0]==0|card_3[0]==1|card_3[0]==2|card_3[0]==3|card_3[0]==4|card_3[0]==5|card_3[0]==6|card_3[0]==7|card_3[0]==8|card_3[0]==9)break;
}
}
delay_ms(10000);
while(1)
{
key_val = Matrix_Key_Scan();
if(key_val > 0 && key_val < 17)// Personal information comes second
{
if(key_val==1)card_3[1]=1;
if(key_val==2)card_3[1]=2;
if(key_val==3)card_3[1]=3;
if(key_val==4)card_3[1]=4;
if(key_val==5)card_3[1]=5;
if(key_val==6)card_3[1]=6;
if(key_val==7)card_3[1]=7;
if(key_val==8)card_3[1]=8;
if(key_val==9)card_3[1]=9;
if(key_val==10)card_3[1]=0;
printf("\r\n %d \r\n",card_3[1]);
if(card_3[1]==0|card_3[1]==1|card_3[1]==2|card_3[1]==3|card_3[1]==4|card_3[1]==5|card_3[1]==6|card_3[1]==7|card_3[1]==8|card_3[1]==9)break;
}
}
delay_ms(10000);
while(1)
{
key_val = Matrix_Key_Scan();
if(key_val > 0 && key_val < 17)// Personal information ranks third
{
if(key_val==1)card_3[2]=1;
if(key_val==2)card_3[2]=2;
if(key_val==3)card_3[2]=3;
if(key_val==4)card_3[2]=4;
if(key_val==5)card_3[2]=5;
if(key_val==6)card_3[2]=6;
if(key_val==7)card_3[2]=7;
if(key_val==8)card_3[2]=8;
if(key_val==9)card_3[2]=9;
if(key_val==10)card_3[2]=0;
printf("\r\n %d \r\n",card_3[2]);
if(card_3[2]==0|card_3[2]==1|card_3[2]==2|card_3[2]==3|card_3[2]==4|card_3[2]==5|card_3[2]==6|card_3[2]==7|card_3[2]==8|card_3[2]==9)break;
}
}
delay_ms(10000);
while(1)
{
key_val = Matrix_Key_Scan();
if(key_val > 0 && key_val < 17)// Personal information ranks fourth
{
if(key_val==1)card_3[3]=1;
if(key_val==2)card_3[3]=2;
if(key_val==3)card_3[3]=3;
if(key_val==4)card_3[3]=4;
if(key_val==5)card_3[3]=5;
if(key_val==6)card_3[3]=6;
if(key_val==7)card_3[3]=7;
if(key_val==8)card_3[3]=8;
if(key_val==9)card_3[3]=9;
if(key_val==10)card_3[3]=0;
printf("\r\n %d \r\n",card_3[3]);
if(card_3[3]==0|card_3[3]==1|card_3[3]==2|card_3[3]==3|card_3[3]==4|card_3[3]==5|card_3[3]==6|card_3[3]==7|card_3[3]==8|card_3[3]==9)break;
}
}
delay_ms(10000);
if(((card_3[0]==card[4])&&(card_3[1]==card[5])&&(card_3[2]==card[6])&&(card_3[3]==card[7])))// If it is the information of ordinary card
{// Create a temporary array to temporarily save the card number of ordinary cards , Then initialize the card number to 0
card_4[0]=card[0];card[0]=0;
card_4[1]=card[1];card[1]=0;
card_4[2]=card[2];card[2]=0;
card_4[3]=card[3];card[3]=0;
printf("\r\n The loss of ordinary card is reported successfully \r\n");
printf("\r\n Press down S16 sign out \r\n");
}
else if(((card_3[0]==card[12])&&(card_3[1]==card[13])&&(card_3[2]==card[14])&&(card_3[3]==card[15])))// If it is student card information
{// Create a temporary array to temporarily save the student card number , Then initialize the card number to 0
card_5[0]=card[8];card[8]=0;
card_5[1]=card[9];card[9]=0;
card_5[2]=card[10];card[10]=0;
card_5[3]=card[11];card[11]=0;
printf("\r\n Student card lost successfully \r\n");
printf("\r\n Press down S16 sign out \r\n");
}
else if(((card_3[0]==card[20])&&(card_3[1]==card[21])&&(card_3[2]==card[22])&&(card_3[3]==card[23])))// If it is the information of the senior citizen card
{// Create a temporary array to temporarily save the card number of the elderly card , Then initialize the card number to 0
card_6[0]=card[16];card[16]=0;
card_6[1]=card[17];card[17]=0;
card_6[2]=card[18];card[18]=0;
card_6[3]=card[19];card[19]=0;
printf("\r\n The loss of the senior citizen card has been reported successfully \r\n");
printf("\r\n Press down S16 sign out \r\n");
}
else
{
printf("\r\n The information is not bound to the bus card \r\n ");
}
}
}
key_val = Matrix_Key_Scan();
if(key_val > 0 && key_val < 17)
{
if(key_val==2)// Enter the release loss reporting mode
{
printf("\r\n Enter the release loss reporting mode \r\n");
printf("\r\n Please enter 4 For personal information \r\n");
while(1)
{
key_val = Matrix_Key_Scan();
if(key_val > 0 && key_val < 17)// Personal information comes first
{
if(key_val==1)card_3[0]=1;
if(key_val==2)card_3[0]=2;
if(key_val==3)card_3[0]=3;
if(key_val==4)card_3[0]=4;
if(key_val==5)card_3[0]=5;
if(key_val==6)card_3[0]=6;
if(key_val==7)card_3[0]=7;
if(key_val==8)card_3[0]=8;
if(key_val==9)card_3[0]=9;
if(key_val==10)card_3[0]=0;
printf("\r\n %d \r\n",card_3[0]);
if(card_3[0]==0|card_3[0]==1|card_3[0]==2|card_3[0]==3|card_3[0]==4|card_3[0]==5|card_3[0]==6|card_3[0]==7|card_3[0]==8|card_3[0]==9)break;
}
}
delay_ms(10000);
while(1)
{
key_val = Matrix_Key_Scan();
if(key_val > 0 && key_val < 17)// Personal information comes second
{
if(key_val==1)card_3[1]=1;
if(key_val==2)card_3[1]=2;
if(key_val==3)card_3[1]=3;
if(key_val==4)card_3[1]=4;
if(key_val==5)card_3[1]=5;
if(key_val==6)card_3[1]=6;
if(key_val==7)card_3[1]=7;
if(key_val==8)card_3[1]=8;
if(key_val==9)card_3[1]=9;
if(key_val==10)card_3[1]=0;
printf("\r\n %d \r\n",card_3[1]);
if(card_3[1]==0|card_3[1]==1|card_3[1]==2|card_3[1]==3|card_3[1]==4|card_3[1]==5|card_3[1]==6|card_3[1]==7|card_3[1]==8|card_3[1]==9)break;
}
}
delay_ms(10000);
while(1)
{
key_val = Matrix_Key_Scan();
if(key_val > 0 && key_val < 17)// Personal information ranks third
{
if(key_val==1)card_3[2]=1;
if(key_val==2)card_3[2]=2;
if(key_val==3)card_3[2]=3;
if(key_val==4)card_3[2]=4;
if(key_val==5)card_3[2]=5;
if(key_val==6)card_3[2]=6;
if(key_val==7)card_3[2]=7;
if(key_val==8)card_3[2]=8;
if(key_val==9)card_3[2]=9;
if(key_val==10)card_3[2]=0;
printf("\r\n %d \r\n",card_3[2]);
if(card_3[2]==0|card_3[2]==1|card_3[2]==2|card_3[2]==3|card_3[2]==4|card_3[2]==5|card_3[2]==6|card_3[2]==7|card_3[2]==8|card_3[2]==9)break;
}
}
delay_ms(10000);
while(1)
{
key_val = Matrix_Key_Scan();
if(key_val > 0 && key_val < 17)// Personal information ranks fourth
{
if(key_val==1)card_3[3]=1;
if(key_val==2)card_3[3]=2;
if(key_val==3)card_3[3]=3;
if(key_val==4)card_3[3]=4;
if(key_val==5)card_3[3]=5;
if(key_val==6)card_3[3]=6;
if(key_val==7)card_3[3]=7;
if(key_val==8)card_3[3]=8;
if(key_val==9)card_3[3]=9;
if(key_val==10)card_3[3]=0;
printf("\r\n %d \r\n",card_3[3]);
if(card_3[3]==0|card_3[3]==1|card_3[3]==2|card_3[3]==3|card_3[3]==4|card_3[3]==5|card_3[3]==6|card_3[3]==7|card_3[3]==8|card_3[3]==9)break;
}
}
delay_ms(10000);
if(((card_3[0]==card[4])&&(card_3[1]==card[5])&&(card_3[2]==card[6])&&(card_3[3]==card[7])))// If it is the personal information of ordinary card
{// Redefine the ordinary card temporarily saved at the time of loss reporting
card[0]=card_4[0];
card[1]=card_4[1];
card[2]=card_4[2];
card[3]=card_4[3];
printf("\r\n The loss report of the ordinary card is cancelled successfully \r\n");
printf("\r\n Press down S16 sign out \r\n");
}
else if(((card_3[0]==card[12])&&(card_3[1]==card[13])&&(card_3[2]==card[14])&&(card_3[3]==card[15])))// If it is the personal information of the student card
{// Redefine the student card temporarily saved when reporting the loss
card[8]=card_5[0];
card[9]=card_5[1];
card[10]=card_5[2];
card[11]=card_5[3];
printf("\r\n Student card cancellation and loss reporting succeeded \r\n");
printf("\r\n Press down S16 sign out \r\n");
}
else if(((card_3[0]==card[20])&&(card_3[1]==card[21])&&(card_3[2]==card[22])&&(card_3[3]==card[23])))// If it is the personal information of the senior citizen card
{// Redefine the old-age card temporarily saved at the time of loss reporting
card[16]=card_6[0];
card[17]=card_6[1];
card[18]=card_6[2];
card[19]=card_6[3];
printf("\r\n The loss of the old age card has been reported successfully \r\n");
printf("\r\n Press down S16 sign out \r\n");
}
else
{
printf("\r\n This personal information is not bound to a bus card \r\n ");
}
}
}
key_val = Matrix_Key_Scan();
if(key_val > 0 && key_val < 17)
{
if(key_val==16)// Press down S16 Exit the loss reporting and release reporting function
{
printf("\r\n Exit the loss reporting and release reporting function \r\n");
break;
}
}
}
}
Other related codes will not be shown in detail here .
Specific function description
The specific functions are , First go to the menu .

Take one at random M50 card . Pay by card , This card does not define , Press down KEY1 Enter card issuing mode

Now press S1 Is defined as ordinary card , Press down S2 Is defined as student card , Press down S3 Is defined as the senior citizen card .

Then enter your personal information , When the card definition is complete , Press down S16 Press the key to exit the card issuing mode .

At this time, the card just defined has no balance , So you need to press KEY0 Recharge , Every press KEY1 Ten yuan at a time . One time debit for ordinary card 1.6 element , One time debit for student card 0.8 element . Elderly card does not need to be recharged and deducted , free .

When a user loses his card , Press down WK_UP Key to enter the card loss reporting and release reporting functions , Then press the S1 Enter the loss reporting function .

At this point, the loss is reported successfully after entering the user's personal information , Input error shows password error , After loss reporting , Press down S16 sign out .


When a user retrieves his card , Press again WK_UP Press the key to enter the loss report and release the loss report function , Press again at this time S2 Enter the function of releasing the loss report , At this point, the user enters his personal information and the loss report is cancelled successfully , If the personal information does not match, the password error will be displayed , Press... After successfully releasing the loss report S16 Key to exit .


You can see , The basic functions have been demonstrated once .(PS: The serial port shows that some words are garbled , So some words are not displayed .)
Conclusion and improvement
In this design , I came to the conclusion that , Want to design a good system , Problems that can not be found at ordinary times can only be found through continuous debugging and improvement , And when writing functions , Be sure to write notes , Otherwise, if you write too many functions in the back, you will find that you have forgotten what you wrote in the front , I know that . Through this design , I have gained a lot , It also made me grow a lot , Learned how to design a system and improve it by yourself . I will continue to improve the system , Add some modules that can be added , Such as display screen and voice module , To improve the system . I will keep updating this blog in the future , Write your ideas and improvements into this blog , For everyone to learn .
If you have a problem, you can send a private letter or add q1743647071, learn from each other , Make progress with each other .
边栏推荐
- mysql中一对多关联,获取多表中最新一条数据
- Gartner focuses on low code development in China how UNIPRO practices "differentiation"
- 各种loam总结(激光slam)
- 使用sqlite3语句后出现省略号 ... 的解决方法
- 雪糕还是雪“高”?
- Typescript learning
- Basic data type and complex data type
- Stunned! The original drawing function of markdown is so powerful!
- Service gateway of microservices
- Ellipsis after SQLite3 statement Solutions for
猜你喜欢

Introduction to MySQL operation (IV) -- data sorting (ascending, descending, and multi field sorting)

渗透学习-靶场篇-pikachu靶场详细攻略(持续更新中-目前只更新sql注入部分)

医美大刀,砍向00后

netERR_ CONNECTION_ Refused solution

average-population-of-each-continent

average-population-of-each-continent

Improving deep neural networks: hyperparametric debugging, regularization and optimization (III) - hyperparametric debugging, batch regularization and program framework

Learn to go concurrent programming in 7 days go language sync Application and implementation of cond

Windwos 8.1系统安装vmware tool插件报错的解决方法

PE买下一家内衣公司
随机推荐
First knowledge of the second bullet of C language
[essay]me53n add button to call URL
Stunned! The original drawing function of markdown is so powerful!
Gartner focuses on low code development in China how UNIPRO practices "differentiation"
【mysql实战】查询语句实战演示
渗透学习-靶场篇-pikachu靶场详细攻略(持续更新中-目前只更新sql注入部分)
月薪3万的狗德培训,是不是一门好生意?
Infiltration learning - problems encountered during SQL injection - explanation of sort=left (version(), 1) - understanding of order by followed by string
Vue+MySQL实现登录注册案例
Transformation from student to engineer
2022年第一季度“广州好人”刘磊峰:具有强烈的诚信意识和食品安全意识
最虚的华人首富更虚了
Livox lidar+ Haikang camera generates color point cloud in real time
Introduction to MySQL operation (IV) -- data sorting (ascending, descending, and multi field sorting)
OpenSSL Programming II: building CA
About the SQL injection of davwa, errors are reported: analysis and verification of the causes of legal mix of settlements for operation 'Union'
Passerelle de service pour les microservices
Teach you how to print your own log -- how to customize log4j2 components
Livox lidar+ Hikvision camera real-time 3D reconstruction based on loam to generate RGB color point cloud
跟着存档教程动手学RNAseq分析(四):使用DESeq2进行DE分析的QC方法
