就是实现类似公交卡那种功能刷一下除非拿开否则不能再刷那种功能。
我用延时实现功能,但是系统不稳定,用标志位总觉得哪没考虑全。
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "usb_lib.h"
#include "hw_config.h"
#include "usb_pwr.h"
#include "FM1702.h"
#include "stdio.h"
#include "string.h"
#include "rtc.h"
#include <stdlib.h>
#include <cstdlib>
unsigned char RevBuffer[32]; //RevBuffer½óêÕoí·¢Ëí»o3åÇø
extern uint8_t USB_Received_Flag;
uint8_t data[32]; //USBêy¾Y»o3å
int main(void)
{
unsigned int Money,Hundreds,Decade,Last;
int i=0,j=0;
u8 flag =1,flag1=1;
//unsigned char BuffKey[6] = {0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
unsigned char buf[16],Buff1[16]={0x30,0x30,0x30,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //ÏÂÔØÃØÔ¿Ô¿3×
char shuju[3];
u8 shuju2[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
//unsigned char status;
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//ÖD¶Ï·Ö×ééèÖÃ
uart_init(9600);//′®¿ú3õê¼»ˉÎa9600
LCD_Init();
LED_Init(); //3õê¼»ˉóëLEDᬽóμÄó2¼t½ó¿ú
delay_ms(1800);
USB_Port_Set(0); //USBÏè¶Ï¿a
delay_ms(300);
USB_Port_Set(1); //USBÔù′Îᬽó
//USBÅäÖÃ
USB_Interrupts_Config();
Set_USBClock();
USB_Init();
FM1702_SPI_init();
InitializeSystem();
while(RTC_Init())
{
LCD_ShowString1(60,130,200,16,16,"RTC ERROR! ");
delay_ms(800);
LCD_ShowString1(60,130,200,16,16,"RTC Trying...");
}
TP_Init();//ÏÔê¾3õê¼»ˉ
while(1)
{
LCD_ShowNum(100,220,calendar.w_year,4,16);
LCD_ShowNum(140,220,calendar.w_month,2,16);
LCD_ShowNum(165,220,calendar.w_date,2,16);
LCD_ShowNum(100,242,calendar.hour,2,16);
LCD_ShowNum(130,242,calendar.min,2,16);
LCD_ShowNum(160,242,calendar.sec,2,16);
i++;j++;
if(j==5)
{
TP_Clear();
j=0;
flag1=1;
}
if(i==5)
{
TP_Clear();
i=0;
flag=1;
}
if(RE_SELECT()==TYPE_SUCCESS)//Ѷ¿¨»½DÑ¿¨
{
if(Cmd_ex())//Ñ¡Ôñ¿¨ÑéÖ¤ÃüÂë
{
LED0 = 1;
LED1 = 1;
if( Read(Buff1,13)==TYPE_SUCCESS)
{
shuju[0] = Buff1[0];
shuju[1] = Buff1[1];
shuju[2] = Buff1[2];
Money= atoi(shuju);
if(Money>=2)//×îμí½e¶î
{
if(Buff1[3]==0x01&&flag==1)
{
flag=0;
Money = Money-2;
Hundreds = Money/100%10;
Decade = Money%100/10;
Last = Money%10;
shuju2[0] = Hundreds+'0';
shuju2[1] = Decade+'0';
shuju2[2] = Last + '0';
shuju2[3] = Buff1[3];
memcpy(buf,&shuju2,4);
Write(shuju2,13);
TP_Show(1,Money);
}
else if(Buff1[3]==0x02&&flag1==1)
{
flag1=0;
Money = Money-1;
Hundreds = Money/100%10;
Decade = Money%100/10;
Last = Money%10;
shuju2[0] = Hundreds+'0';
shuju2[1] = Decade+'0';
shuju2[2] = Last + '0';
shuju2[3] = Buff1[3];
memcpy(buf,&shuju2,4);
Write(shuju2,13);
TP_Show(2,Money);
}
delay_ms(300);
}
else
{
LED1 = !LED1;
}
}
}
else
{
LED0 = 0;
delay_ms(200);
LED0 = 0;
}
}
}
}
0x26我休眠了然后还是能寻到卡。。。。
一周热门 更多>