在阶段二中,已经实现了RFID读写器与主控板的相互通信,发送和接收数据串。这是最核心的一部分。不过,之前金额的改变是固定100,现在开始任意数值的增减和任意数值初始化。这部分主要跟读写器的通信协议有关,不同的读写器可能不一样,但是代码思路都是差不多的。
为了实现任意数字的输入,首先要有一个键盘,在此,我用STM32TFTLCD触屏做了一个触摸键盘(电阻屏,竖屏)。要先引入touch.c ,24cxx.c,myiic.c文件。
触屏代码
#include "delay.h"
#include "sys.h"
#include "lcd.h"
#include "key.h"
#include "touch.h"
int digital=0;//键值
void Load_Drow_Dialog(void)//数字键盘画屏
{
LCD_Clear(WHITE);//清屏
POINT_COLOR=RED;
LCD_ShowString(60,30,120,24,24,"CardID:");
LCD_ShowString(60,60,200,24,24,"money :");
LCD_ShowString(60,90,200,24,24,"count :");
//LCD_ShowString(60,120,200,24,24,"flag :");
POINT_COLOR=BLUE;//设置字体为蓝色
LCD_ShowxNum(30,170,1,1,24,0);
LCD_ShowxNum(90,170,2,1,24,0);
LCD_ShowxNum(150,170,3,1,24,0);
LCD_ShowString(210,170,1,24,24,"C");//充值
LCD_ShowxNum(30,210,4,1,24,0);
LCD_ShowxNum(90,210,5,1,24,0);
LCD_ShowxNum(150,210,6,1,24,0);
LCD_ShowString(210,210,1,24,24,"K");//扣费
LCD_ShowxNum(30,250,7,1,24,0);
LCD_ShowxNum(90,250,8,1,24,0);
LCD_ShowxNum(150,250,9,1,24,0);
LCD_ShowString(210,250,1,24,24,"D");//确定
//LCD_ShowxNum(30,200,1,1,16,0);
LCD_ShowxNum(90,290,0,1,24,0);
//LCD_ShowxNum(150,200,3,1,16,0);
LCD_ShowString(210,290,1,24,24,"J");//校准
// POINT_COLOR=RED;//设置画笔蓝色
LCD_DrawLine(0,315,240,315);
LCD_DrawLine(0,280,240,280);
LCD_DrawLine(0,240,240,240);
LCD_DrawLine(0,200,240,200);
LCD_DrawLine(0,160,240,160);
LCD_DrawLine(60,160,60,315);
LCD_DrawLine(120,160,120,315);
LCD_DrawLine(180,160,180,315);
}
void anjian(void)
{
//......根据键值,编写逻辑功能
}
void rtp_test(void)
{
u8 key;
while(1)
{
Receive_One();
LCD_ShowString(150,35,200,16,16,card_id);
LCD_ShowxNum(152,60,money,4,24,0);
LCD_ShowxNum(152,90,num,4,24,0);
//LCD_ShowxNum(190,120,flag,1,24,0);
delay_ms(10);
key=KEY_Scan(0);//触屏校准键
tp_dev.scan(0); //扫描触摸屏.0,屏幕扫描;1,物理坐标;
if(tp_dev.sta&TP_PRES_DOWN) //触摸屏被按下
{
if(tp_dev.x[0] { if(tp_dev.x[0]>0&&tp_dev.x[0]<60){ if(tp_dev.y[0]>160&&tp_dev.y[0]<200){ digital=1; }else if(tp_dev.y[0]>200&&tp_dev.y[0]<240){digital=4; }else if(tp_dev.y[0]>240&&tp_dev.y[0]<280){digital=7; } //else if(tp_dev.y[0]>280&&tp_dev.y[0]<320){} }else if(tp_dev.x[0]>60&&tp_dev.x[0]<120){ if(tp_dev.y[0]>160&&tp_dev.y[0]<200){ digital=2; }else if(tp_dev.y[0]>200&&tp_dev.y[0]<240){digital=5; }else if(tp_dev.y[0]>240&&tp_dev.y[0]<280){digital=8; }else if(tp_dev.y[0]>280&&tp_dev.y[0]<320){digital=0; } }else if(tp_dev.x[0]>120&&tp_dev.x[0]<180){ if(tp_dev.y[0]>160&&tp_dev.y[0]<200){ digital=3; }else if(tp_dev.y[0]>200&&tp_dev.y[0]<240){digital=6; }else if(tp_dev.y[0]>240&&tp_dev.y[0]<280){digital=9; } //else if(tp_dev.y[0]>280&&tp_dev.y[0]<320){} }else if(tp_dev.x[0]>180&&tp_dev.x[0]<240){ if(tp_dev.y[0]>160&&tp_dev.y[0]<200){ digital=11; }else if(tp_dev.y[0]>200&&tp_dev.y[0]<240){digital=12; }else if(tp_dev.y[0]>240&&tp_dev.y[0]<280){digital=13; }else if(tp_dev.y[0]>280&&tp_dev.y[0]<320){digital=14; } } } anjian(); } delay_ms(50); if(key==WKUP_PRES) //KEY0按下,则执行校准程序 { LCD_Clear(WHITE);//清屏 TP_Adjust(); //屏幕校准 TP_Save_Adjdata(); Load_Drow_Dialog(); } } } int main(void) { delay_init(); //延时函数初始化 LCD_Init(); KEY_Init(); //按键初始化 tp_dev.init(); //触摸屏初始化touch.c Load_Drow_Dialog(); //数字键盘 rtp_test(); //键盘监控 } 以上代码,实现数字键盘输入,键值部分逻辑代码,根据实际需求编写。
上一篇:STM32F103系列实战之DMA控制器
下一篇:STM32(RFID)阶段二(读序列,修改金额)
推荐阅读最新更新时间:2024-03-16 16:24