概述
}
}
//==定时器0中断函数
void time0_interrupt()interrupt 1
{
TL0 = (65536 - 5000) % 256;// 12M晶振,5ms定时
TH0 = (65536 - 5000) / 256;
display_function();
time_counter++;
time_counter8++;
if(time_counter8 >= 1600)//大于8s没切割,车子视为停下了,速度为:0,但里程还记着
{
time_counter8 = 0;
speed = 0;//速度为 0
point1 = 0;
buf1[3] = speed%10;buf1[2] = speed/10%10;
buf1[1] = speed/100%10;buf1[0] = speed/1000%10;
}
}
//==========外部中断0中断函数=
void int0_interrupt()interrupt 0
{
external_counter++;
if(external_counter ==1 )TR0 = ~TR0;//第一次切割打开定时器0
if(external_counter == 65535)external_counter = 0;
time_counter8 = 0; //只要8秒内有切割,车子就任在运行
if(external_counter % 2 == 0)//切割2次 更新下速度
{ //*5是因为中断一次是5MS
if(flag10){speed =((ulong)(36000)*zhouchang)/(time_counter * 5);flag1=1;}
else if(flag11){speed =((ulong)(36000)2zhouchang)/(time_counter * 5);}//速度:单位为 m/h ,*1000的目的是不出现浮点数
if((speed >= 100)&&(speed < 1000)) //100 ---- 1000 3位整数
{
point1 = 1;buf1[3] = speed%10;buf1[2] = speed/10%10;
buf1[1] = speed/100%10;buf1[0] = 0;}
else if((speed >= 1000)&&(speed < 10000)) //1000 ---- 10000 4位整数
{
point1 = 1;speed = (uint)speed;
buf1[3] = speed%10;buf1[2] = speed/10%10;
buf1[1] = speed/100%10;buf1[0] = speed/1000%10;}
else if((speed >= 10000)&&(speed < 100000)) //10000 ----- 100000 5位整数
{
point1 = 2;
buf1[3] = speed/10%10;buf1[2] = speed/100%10;
buf1[1] = speed/1000%10;buf1[0] = speed/10000%10;}
else if((speed >= 100000)&&(speed < 1000000)) //100000 ------ 1000000 6位整数
{
point1 = 3;
buf1[3] = speed/100%10;buf1[2] = speed/1000%10;
buf1[1] = speed/10000%10;buf1[0] = speed/100000%10;}
time_counter = 0;
}
if(external_counter % 8 == 0)//每切割8次 更新下里程
{
s = (ulong)external_counter * zhouchang; //里程:单位为 cm
if((s >= 1000)&&(s < 10000))
{
point2 = 1; // 0.012 001212
buf2[3] = s/100%10;buf2[2] = s/1000%10;
buf2[1] = 0;buf2[0] = 0;}// 4位整数
else if((s >= 10000)&&(s < 100000))
{
point2 = 1;
buf2[3] = s/100%10;buf2[2] = s/1000%10;
buf2[1] = s/10000%10;buf2[0] = 0;}// 5位整数 0.123 012345
else if((s >= 100000)&&(s < 1000000))
{
point2 = 1;
buf2[3] = s/100%10;buf2[2] = s/1000%10;
buf2[1] = s/10000%10;buf2[0] = s/100000%10;} // 6位整数 1.234 1234 56
else if((s >= 1000000)&&(s < 10000000))
{
point2 = 2;
buf2[3] = s/1000%10;buf2[2] = s/10000%10;
buf2[1] = s/100000%10;buf2[0] = s/1000000%10;}// 7位整数 1234 567
else if((s >= 10000000)&&(s < 100000000))
{
point2 = 3;
buf2[3] = s/10000%10;buf2[2] = s/100000%10;
buf2[1] = s/1000000%10;buf2[0] = s/10000000%10;} // 8位整数 1234 5678
}
}
//==========开电源就显示的数据,初始显示速度
void init_display()
{
uchar i;
for(i = 0;i < 4;i++)
{
wei = bitcode[num - 1];
led = display1[buf1[num–]];
delay1m(4);
if(num == 0)num = 4;
}
}
//==显示函数=
void display_function()
{
if(flag == 0)//显示速度
{
switch(point1)
{
case 0:wei = bitcode[num-1];led = display1[buf1[num-1]];num–;break;//速度显示 0
case 1:if(num == 1){ wei = bitcode[num-1];led = 0x7f&display1[buf1[num-1]];num–;}
else { wei = bitcode[num-1];led = display1[buf1[num-1]];num–;}break;//最高位小数点亮
case 2:if(num == 2){ wei = bitcode[num-1];led = 0x7f&display1[buf1[num-1]];num–;}
else { wei = bitcode[num-1];led = display1[buf1[num-1]];num–;}break;//第二高位小数点亮
case 3:if(num == 3){ wei = bitcode[num-1];led = 0x7f&display1[buf1[num-1]];num–;}
else { wei = bitcode[num-1];led = display1[buf1[num-1]];num–;}break;//第三高位小数点亮
default:break;
}
if(num == 0)num = 4;
}
else if(flag == 1)//显示里程
{
switch(point2)
{
case 0:wei = bitcode[num-1];led = display1[buf2[num-1]];num–;break;//里程显示 0
case 1:if(num == 1){ wei = bitcode[num-1];led = 0x7f&display1[buf2[num-1]];num–;}
else { wei = bitcode[num-1];led = display1[buf2[num-1]];num–;}break;//最高位小数点亮
case 2:if(num == 2){ wei = bitcode[num-1];led = 0x7f&display1[buf2[num-1]];num–;}
else { wei = bitcode[num-1];led = display1[buf2[num-1]];num–;}break;//第二高位小数点亮
case 3:if(num == 3){ wei = bitcode[num-1];led = 0x7f&display1[buf2[num-1]];num–;}
else { wei = bitcode[num-1];led = display1[buf2[num-1]];num–;}break;//第三高位小数点亮
default:break;
}
if(num == 0)num = 4;
}
}
//=================定时器0和外部中断0的初始化函数=void time0_int0_init(){TMOD |= 0x01;TMOD &= 0xfd;//定时器0工作于方式1TL0 = (65536 - 5000) % 256;//12M晶振,5ms定时TH0 = (65536 - 5000) / 256;IT0 = 1;//外部中断0,负跳变触发方式TR0 = 0;ET0 = 1;EX0 = 1;EA = 1;}//==========ms 级延时函数=void delay1m(uchar x){uchar i,j;for(i=0;i
最后
以上就是追寻橘子为你收集整理的单片机数码管显示自行车里程c语言,项目实战:51单片机霍尔自行车里程测速仪设计升级版 原理图 程序 制作BOM...的全部内容,希望文章能够帮你解决单片机数码管显示自行车里程c语言,项目实战:51单片机霍尔自行车里程测速仪设计升级版 原理图 程序 制作BOM...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复