赞
踩
#include<public.h>
#include<LCD12864.h>
#include<DS1302.h>
#include<key.h>
#include<XPT2046.h>
sbit PWM=P2^4;
u1 code a[]={"CZCJJQ"};
u1 code b[]={"0302"} ;
u1 code c[]={"mile"};
u1 code d[]={"cost"};
u1 code e[]={"delay:"};
u1 gduty;
u2 miao;
u2 miao1,miao2;
u2 money,mile;
u1 flag;
u1 mode1,wait_time;
u1 key_value,time_cnt,time_mode,money_mode=1;
u1 qi_money;
void ad_data()
{
u2 adc_value;
float adc_vol;
adc_value=xpt2046_read_adc_value(0x94);
adc_vol=5.0*adc_value/4096;
adc_value=adc_vol*10;
gduty=adc_value*2;
LCD12864_write_com(0x80);
LCD12864_write_dat(gduty/10+0x30);
LCD12864_write_dat(gduty%10+0x30);
LCD12864_write_dat('%');
}
void LCD12864_XS()
{
u1 i;
if(mode1==1)
{
if(mile<=30)
{
if(wait_time<5)
{
money=qi_money*100;
}
else
{
money=qi_money*100+wait_time/5*100;
}
}
else
{
if(wait_time<5)
{
money=qi_money*100+(mile-30)/10*100+(mile-30)%10*12;
}
else
{
money=qi_money*100+(mile-30)/10*100+(mile-30)%10*12+wait_time/5*100;
}
}
}
if(mode1==3)
{
money=0;
mile=0;
wait_time=0;
}
if(time_cnt==1)
{
ds1302_inti();
if(key_value==6)
{
time_mode++;
if(time_mode==3)
{
time_mode=0;
}
}
if(time_mode==0||time_mode==1||time_mode==2)
{
if(key_value==7)
{
TIME[time_mode]++;
if((TIME[time_mode]&0x0f)>9)
{
TIME[time_mode]=TIME[time_mode]+6;
}
if(TIME[time_mode]>=0x60&&time_mode<2)
{
TIME[time_mode]=0;
}
if(TIME[time_mode]>=0x24&&time_mode==2)
{
TIME[time_mode]=0;
}
}
if(key_value==8)
{
TIME[time_mode]--;
if((TIME[time_mode]&0x0f)>9)
{
TIME[time_mode]=TIME[time_mode]+6;
}
if(TIME[time_mode]<=0x00&&time_mode<2)
{
TIME[time_mode]=0x59;
}
if(TIME[time_mode]<=0x00&&time_mode==2)
{
TIME[time_mode]=0x24;
}
}
}
}
LCD12864_write_com(0x98+7);
LCD12864_write_dat(time_mode%10+0x30);
if(time_cnt==0)
{
ds1302_read_time();
}
LCD12864_write_com(0x80+2);
LCD12864_write_dat(TIME[2]/16+0x30);
LCD12864_write_dat(TIME[2]%16+0x30);
LCD12864_write_dat('-');
LCD12864_write_dat(TIME[1]/16+0x30);
LCD12864_write_dat(TIME[1]%16+0x30);
LCD12864_write_dat('-');
LCD12864_write_dat(TIME[0]/16+0x30);
LCD12864_write_dat(TIME[0]%16+0x30);
LCD12864_write_com(0x90);
for(i=0;i<4;i++)
{
LCD12864_write_dat(c[i]);
}
LCD12864_write_dat(':');
LCD12864_write_dat(mile/1000+0x30);
LCD12864_write_dat(mile%1000/100+0x30);
LCD12864_write_dat(mile%1000%100/10+0x30);
LCD12864_write_dat('.');
LCD12864_write_dat(mile%10+0x30);
LCD12864_write_dat('k');
LCD12864_write_dat('m');
LCD12864_write_com(0x88);
for(i=0;i<4;i++)
{
LCD12864_write_dat(d[i]);
}
LCD12864_write_dat(':');
LCD12864_write_dat(money/1000+0x30);
LCD12864_write_dat(money%1000/100+0x30);
LCD12864_write_dat('.');
LCD12864_write_dat(money%1000%100/10+0x30);
LCD12864_write_dat(money%10+0x30);
LCD12864_write_dat('y');
LCD12864_write_dat('u');
LCD12864_write_dat('a');
LCD12864_write_dat('n');
LCD12864_write_com(0x98);
for(i=0;i<6;i++)
{
LCD12864_write_dat(e[i]);
}
LCD12864_write_dat(wait_time/100+0x30);
LCD12864_write_dat(wait_time%100/10+0x30);
LCD12864_write_dat(wait_time%10+0x30);
LCD12864_write_dat('m');
LCD12864_write_dat('i');
LCD12864_write_dat('n');
}
void time_pro()
{
key_value=key_scan();
if(key_value==1)
{
mode1++;
if(mode1==4)
mode1=1;
}
if(mode1==1)
{
TR0=1;
}
else if(mode1==2)
{
TR0=0;
flag=0;
}
if(key_value==2)
{
flag++;
if(flag==2)
flag=0;
}
if(flag==1)
{
TR0=0;
}
else if(flag==0&&mode1==1)
{
TR0=1;
}
if(key_value==5)
{
time_cnt++;
if(time_cnt==2)
time_cnt=0;
}
if(key_value==4)
{
money_mode++;
if(money_mode==3)
money_mode=1;
}
if(money_mode==1)
{
qi_money=6;
}
if(money_mode==2)
{
qi_money=7;
}
LCD12864_write_com(0x80+7);
LCD12864_write_dat(money_mode+0x30);
}
void main()
{
u1 i;
LCD12864_inti();
time0_inti();
time1_inti();
ds1302_inti();
while(miao<=3)
{
LCD12864_write_com(0x1c);
LCD12864_write_com(0x80);
for(i=0;i<6;i++)
{
LCD12864_write_dat(a[i]);
}
LCD12864_write_com(0x90);
for(i=0;i<4;i++)
{
LCD12864_write_dat(b[i]);
}
delay1ms(600);
}
LCD12864_write_com(0x01);
while(1)
{
time_pro();
LCD12864_XS();
ad_data();
temp_data();
}
}
void inti0() interrupt 1
{
static u2 i;
TH0=0xfc;
TL0=0x18;
i++;
if(i==1000)
{
i=0;
mile++;
}
}
void inti1() interrupt 3
{
static u2 i;
static u2 time;
TH1=0xfc;
TL1=0x18;
i++;
time++;
if(i==1000)
{
i=0;
miao++;
if(miao>=3)
{
miao=4;
}
if(flag==1)
{
wait_time++;
}
}
if(time>100)
time=0;
if(time<=gduty)
PWM=1;
else
PWM=0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。