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.
105 lines
1.4 KiB
105 lines
1.4 KiB
#include "IRIN.h" |
|
#include "i2c.h" |
|
|
|
uint mileage = 0; |
|
|
|
uint count=0; |
|
|
|
uchar ms=0; |
|
uint speed=0; |
|
uint r_s=0; |
|
|
|
extern uint model; |
|
extern uchar set; |
|
|
|
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() |
|
{ |
|
LcdSetCursor(0,0); |
|
LcdShowStr(0,0,""); |
|
Lcd1602_Write_Data(0x30+speed/100%10); |
|
Lcd1602_Write_Data(0x30+speed/10%10); |
|
Lcd1602_Write_Data(0x30+speed%10); |
|
LcdShowStr(3,0,"KM/h "); |
|
|
|
LcdShowStr(8,0,""); |
|
Lcd1602_Write_Data(0x30+mileage/100%10); |
|
Lcd1602_Write_Data(0x30+mileage/10%10); |
|
Lcd1602_Write_Data(0x30+mileage%10); |
|
LcdShowStr(11,0,"m "); |
|
|
|
if(model == 0) LcdShowStr(13,0," "); |
|
else if(model == 1) LcdShowStr(13, 0, "L"); |
|
else if(model == 2) LcdShowStr(13, 0, "M"); |
|
else LcdShowStr(13, 0, "H"); |
|
} |
|
|
|
|
|
void Key_scan(){ |
|
if(k1==0) |
|
{ |
|
delay11(1000); //Ïû¶¶´¦Àí |
|
if(k1==0){ |
|
model++; |
|
if(model >= 4) model = 0; |
|
} |
|
while(!k1); |
|
} |
|
|
|
if(k2==0) |
|
{ |
|
delay11(1000); //Ïû¶¶´¦Àí |
|
if(k2==0){ |
|
set = 1; |
|
} |
|
while(!k2); |
|
} |
|
|
|
} |
|
|
|
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; |
|
count=0; |
|
EX1=1; |
|
speed=speed*0.5+(r_s*6)*0.5; |
|
speed=(0.15*speed); |
|
mileage = mileage+(r_s*2.5/20); |
|
} |
|
} |
|
|
|
void int1() interrupt 2 |
|
{ |
|
count++; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|