兼职项目 智能自行车
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.

202 lines
3.5 KiB

3 years ago
#include "IRIN.h"
#include "i2c.h"
uint journey;
uint journey1;
extern uchar pwm_left;
unsigned int b;
unsigned int c;
extern uint time1;
extern uchar pwm_val_left;
unsigned int b2;
unsigned int c2;
uint money=7;
uint sudu=0;
uint count=0; //դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һȦ20<EFBFBD><EFBFBD>
uchar ms=0;
uint speed=0;
uint r_s=0;
bit state=0;
bit s0=0;
bit flas=0;
uchar sec=0;
uchar sec1=0;
/*******************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> : delay
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : <EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>i=1ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD>ʱ10us
*******************************************************************************/
void delay11(int i)
{
while(i--);
}
void IRIN_Init(void)
{
TMOD=0x01 | 0x20 ;//<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ1
3 years ago
TH0=0x3C;
TL0=0xb0;
ET0=1;
TR0=1;
EA=1;
EX1=1;
IT1=1;
}
void display()
{
if(state==0)
{
sudu=At24c02Read(10);
if(money>7)
{
money=At24c02Read(5);
}
LcdSetCursor(0,0);
LcdShowStr(0,0,"Speed:");
Lcd1602_Write_Data(0x30+sudu/100%10);
Lcd1602_Write_Data(0x30+sudu/10%10);
Lcd1602_Write_Data(0x30+sudu%10);
LcdShowStr(10,0,"KM/h");
LcdShowStr(0,1,"L:");
Lcd1602_Write_Data(journey/10000%10+0x30);
Lcd1602_Write_Data(journey/1000%10+0x30);
Lcd1602_Write_Data(journey/100%10+0x30);
Lcd1602_Write_Data(journey/10%10+0x30);
Lcd1602_Write_Data(journey%10+0x30);
LcdShowStr(7,1,"M");
if(journey>1000)
{
money=(journey-1000)*0.002+7;
3 years ago
At24c02Write(5,money);
}
money=money*10;
LcdShowStr(9,1,"Q:");
Lcd1602_Write_Data(money/1000%10+0x30);
Lcd1602_Write_Data(money/100%10+0x30);
Lcd1602_Write_Data(money/10%10+0x30);
LcdShowStr(14,1,".");
Lcd1602_Write_Data(money%10+0x30);
money=money/10;
}
}
void keypros()
{
if(k2==0)
{
delay11(1000); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(k2==0)
{
sudu=At24c02Read(10); //<EFBFBD><EFBFBD>ȡEEPROM<EFBFBD><EFBFBD>ַ1<EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
b2=At24c02Read(1);
c2=At24c02Read(8);
journey=(b2<<8) | c2;
money=At24c02Read(5);
}
while(!k2);
}
if(k1==0)
{
delay11(1000); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(k1==0)
{
flas=1;
}
while(!k1);
}
if(k4==0)
{
delay11(1000); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(k4==0)
{
if(pwm_left>=20)
{
pwm_left=1;
}
else
{
pwm_left++;
}
}
while(!k4);
}
}
void time0() interrupt 1 //<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> 0
{
TH0=0x3C;
TL0=0xb0; //50ms<EFBFBD><EFBFBD>ʱ
ms++; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>50ms<EFBFBD><EFBFBD>һ
if(ms%5==0) s0=~s0;
if(ms%10==0) //500ms<EFBFBD><EFBFBD>ʱ
{
if(sec!=0) sec--;
if(sec1!=0) sec1--;
ms=0; //<EFBFBD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// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>r_s<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>Ȧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>60<EFBFBD>õ<EFBFBD>60<EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>Ȧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> r/min<EFBFBD><EFBFBD> <EFBFBD>ܷ<EFBFBD>ʽ speed=count/10*60; ==>> speed=count*6;
if(flas==0)
{
sudu=(0.15*speed);
At24c02Write(10,sudu);
3 years ago
journey=journey+(r_s*2.5/20);
journey1=journey;
c = journey & 0x00FF;
At24c02Write(8,c);
delay11(1000);
b=journey1>>8;
At24c02Write(1,b);
3 years ago
}
else
{
journey=0;
money=7;
At24c02Write(1,journey);
At24c02Write(8,journey);
At24c02Write(5,money);
flas=0;
3 years ago
}
}
}
void int1() interrupt 2 //<EFBFBD>ⲿ<EFBFBD>ж<EFBFBD> 1
{
count++; //<EFBFBD>ж<EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ
}