新手入门
- 积分
- 6
- 金钱
- 6
- 注册时间
- 2019-9-27
- 在线时间
- 1 小时
|
1金钱
Qrcoder.c
#include "config.h"
#include "lcd12864.h"
#include "QRcoder.h"
#include "stdio.h"
#include "string.h"
#include "uart.h"
#include "delay.h"
//商品信息
ProductDef code productInfo[]=
{
{"8641983220190001","冰红茶",3},
{"8641983220190002","面包",3},
{"8641983220190003","纸巾",1},
{"8641983220190004","牙刷",5},
{"8641983220190005","洗发水",15},
};
void LcdDiplay_MainWindow()
{
Lcd_Clear(0); //清除显示,并且设定地址指针为00H
LcdShow_string(0,0,"====欢迎使用====");
LcdShow_string(1,1,"智能扫码设备");
LcdShow_string(0,2,"----请扫码----");
LcdShow_string(0,3,"Design By YXD");
}
//显示商品信息
void LcdDispy_productInfo(ProductDef* proInfo)
{
unsigned char dest[12];
Lcd_Clear(0); //清除显示,并且设定地址指针为00H
strncpy(dest,proInfo->QR,12);
LcdShow_string(0,0,"QR:");
LcdShow_string(2,0,dest);//第一行显示二维码
LcdShow_string(0,1,"品名:");
LcdShow_string(3,1,proInfo->name);//第二行显示商品名称
LcdShow_string(0,2,"价格:");
LcdShow_number(3,2,proInfo->price);//第三行显示商品价格
LcdShow_string(5,2,"元");
//LcdShow_string(0,3,"----请支付----");
}
void LcdDiplay_PayWindow()
{
Lcd_Clear(0); //清除显示
LcdShow_string(2,2,"支付成功!");//第二行显示商品名称
LcdShow_string(2,1,"总价");//第二行显示商品名称
LcdShow_number(4,1,7);//第三行显示商品价格这里总价7元是错的,想在这里加上扫描的商品价格总和加在这里
LcdShow_string(5,1,"元");//第二行显示商品名称
LcdShow_string(0,3,"3 秒后自动返回");//第二行显示商品名称
delay_ms(3000);
LcdDiplay_MainWindow();
}
void LcdDiplay_CancelWindow()
{
Lcd_Clear(0); //清除显示
LcdShow_string(2,1,"取消支付");//第二行显示商品名称
LcdShow_string(0,3,"2 秒后自动返回");//第二行显示商品名称
delay_ms(2000);
LcdDiplay_MainWindow();
}
main.c
#include "config.h"
#include "stdio.h"
#include "string.h"
#include "uart.h"
#include "intrins.h"
#include "delay.h"
#include "lcd12864.h"
#include "timer.h"
#include "QRcoder.h"
#include "key.h"
unsigned char rxlengh = 0;//串口接收数据长度
unsigned char flag_waitPay = 0;//等待支付才可以按键操作
unsigned char keyValue = 0;//键值
unsigned char table_head[9]={0x1b,0x1b,0x40,0x1d ,0x21,0x00,0x1b ,0x61,0x01 };
unsigned char table_chaoshi[10]={0xB4, 0xF3, 0xC8, 0xF3,0xB7, 0xA2, 0xB3, 0xAC, 0xCA, 0xD0};
//unsigned char table_head[]={0xC9, 0xCC ,0xC6 ,0xB7, 0x20,0x20
//B5 A5 BC 0xDB,0x20 ,0x20
//0xCA ,0xFD ,0x20 0x20,
//0xD7 0xDC 0xB6,0xEE };
//unsigned char table_head[]={};
//unsigned char table_head[]={};
//语音播放控制脚
sbit Voice = P1^1;
sbit key_print=P3^7;
void Voice_player(void);
void main()
{
unsigned char i = 0;
unsigned char shangpin[5];
unsigned char shangpin_num[5];
unsigned char money_num[5];
USART2_Init();//串口2 115200 二维码模块串口
Timer0Init();//定时器初始化
LCD12864_init();//LCD12864 初始化
LcdDiplay_MainWindow();
while(1)
{
Is_Receive_Ok(&rxlengh);//判断串口是否接收完成
if(rxlengh !=0)
{
if(strstr(Receive_Data,"0001")!=NULL)
{ shangpin[0]=0x55;
shangpin_num[0]++;
LcdDispy_productInfo(&productInfo[0]);
}
else if(strstr(Receive_Data,"0002")!=NULL)
{ shangpin[1]=0x55;
shangpin_num[1]++;
LcdDispy_productInfo(&productInfo[1]);
}
else if(strstr(Receive_Data,"0003")!=NULL)
{ shangpin[2]=0x55;
shangpin_num[2]++;
LcdDispy_productInfo(&productInfo[2]);
}
else if(strstr(Receive_Data,"0004")!=NULL)
{ shangpin[3]=0x55;
shangpin_num[3]++;
LcdDispy_productInfo(&productInfo[3]);
}
else if(strstr(Receive_Data,"0005")!=NULL)
{ shangpin[4]=0x55;
shangpin_num[4]++;
LcdDispy_productInfo(&productInfo[4]);
}
// Voice_player();
flag_waitPay = 1;//进入等待支付状态
receive_ok = 0;
memset(Receive_Data,0,sizeof(Receive_Data));
uart_len = 0;//标志位清0 开启下一次接收
}
keyValue = GetKey();
if(keyValue == 1 && flag_waitPay==1)//支付键按下 S4
{ Voice_player();
LcdDiplay_PayWindow();
flag_waitPay = 0;
keyValue = 0;
}
else if(keyValue == 4 && flag_waitPay==1)//取消支付键按下 s1
{
LcdDiplay_CancelWindow();//取消支付
flag_waitPay = 0;
keyValue = 0;
}
if(key_print==0)//打印程序有问题,不能够打印出来,想实现扫什么商品打印什么商品还有价格累加。
{ USART1_Init();
// SendData(0x89);
Send_string(table_head,9);//
Send_string("大润发超市\r\n",14);//
Send_string(table_head,9);//
Send_string("商品 单价 量 总额\r\n ",22);//
// send_num(1234);
for(i=0;i<5;i++)
{
//printf("i=%d num=%d",i,shangpin);
if(shangpin==0x55)
{
Send_string("进来一次",8);
send_num(shangpin);
if(i==0)
{
//money_num=3*shangpin_num;
printf("冰红茶 3 %d, %d\r\n",shangpin_num,money_num);
//Send_string("冰红茶 3 ",14);//
}
if(i==1)
{Send_string("面包 ",8);//
money_num=3*shangpin_num;
printf("3 ");
}
if(i==2)
{Send_string("纸巾 ",8);
money_num=1*shangpin_num;
printf("%d ",1);
}
if(i==3)
{ Send_string("牙刷 ",8);
money_num=5*shangpin_num;
printf("%d ",5);
}
if(i==4)
{Send_string("洗发水 ",8);
money_num=15*shangpin_num;
printf("%d ",15);
}
printf("%d,%d,\r\n",shangpin_num,money_num);
Send_string(table_head,9);//
Send_string(" 欢迎再次光临 \r\n ",22);
while(!key_print);
// USART2_Init();//串口2 115200 二维码模块串口
}
}
}
}
}
//语音播放
void Voice_player()
{
Voice = 0;
delay_us(10);
Voice = 1;
}
|
|