兼职项目 智能自行车
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

114 lines
2.1 KiB

#include "IRIN.h"
#include "i2c.h"
uint mileage = 0;
uint count=0;
uchar ms=0;
uint speed=0;
uint r_s=0;
extern uchar play;
extern uint Seep_model;
extern struct UserInfo usr;
extern uchar model;
void delay11(int i)
{
while(i--);
}
void IRIN_Init(void)
{
TMOD=0x01 | 0x20;
TH0=0XFc;
TL0=0X18;
ET0=1;
TR0=1;
EA=1;
EX1=1;
IT1=1;
}
void display()
{
// 显示速度
LcdWriteCom(0x80 + 2);
LcdWriteData(0x30+speed/100%10);
LcdWriteData(0x30+speed/10%10);
LcdWriteData(0x30+speed%10);
// 显示里程
LcdWriteCom(0x80 + 8);
LcdWriteData(0x30+mileage/1000%10);
LcdWriteData(0x30+mileage/100%10);
LcdWriteData(0x30+mileage/10%10);
LcdWriteData(0x30+mileage%10);
LcdWriteData('m');
LcdWriteCom(0x80 + 14);
if(Seep_model == 0) LcdWriteData('N');
else if(Seep_model == 1) LcdWriteData('L');
else if(Seep_model == 2) LcdWriteData('M');
else if(Seep_model == 3) LcdWriteData('H');
// 显示目标里程
LcdWriteCom(0x80 + 0x40);
LcdWriteData(0x30+usr.target_mileage/1000%10);
LcdWriteData(0x30+usr.target_mileage/100%10);
LcdWriteData(0x30+usr.target_mileage/10%10);
LcdWriteData(0x30+usr.target_mileage%10);
LcdWriteData('m');
LcdWriteCom(0x80 + 0x40 + 8);
LcdWriteData(0x30+usr.Remaining_mileage/1000%10);
LcdWriteData(0x30+usr.Remaining_mileage/100%10);
LcdWriteData(0x30+usr.Remaining_mileage/10%10);
LcdWriteData(0x30+usr.Remaining_mileage%10);
LcdWriteData('m');
LcdWriteCom(0x80 + 0x40 + 14);
if(model == 0) LcdWriteData('D');
else LcdWriteData('S');
}
void Key_scan(){
if(k1==0){
delay11(1000);
if(k1==0){
Seep_model++;
if(Seep_model >= 4) Seep_model = 0;
}
while(!k1);
}
}
void time0() interrupt 1
{
static int time = 0;
TH0=0XFc;
TL0=0X18;
time++;
pwm_out_right_moto();
if(time >= 500){
EX1=0;
time = 0;
r_s = count * 3 / 20; // 500ms计算一次 求每秒钟的圈数,珊格数为20 r_s = count * 2 / 20
speed= (r_s * 6) * 2;
mileage = mileage + (count / 20 * 3);
if(mileage > 9999) mileage = 9999;
count=0;
EX1 = 1;
}
}
void int1() interrupt 2
{
count++;
}