標(biāo)題:
想實(shí)現(xiàn)0-59循環(huán)的單片機(jī)秒表,以下主程序該怎么改呢?
[打印本頁(yè)]
作者:
飛魚(yú)seraet
時(shí)間:
2020-5-5 21:10
標(biāo)題:
想實(shí)現(xiàn)0-59循環(huán)的單片機(jī)秒表,以下主程序該怎么改呢?
#include<reg52.h>
#include <intrins.h>
typedef unsigned int a1;
typedef unsigned char b2;
unsigned char code DuanMa[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char Dis_dat[];
unsigned char sec=00;
void delay(a1 i)
{
while(i--);
}
void DisplaySMGwei(b2 pos)
{
P2=(P2&0x1f)|0xc0;
P0=0x01<<pos;
}
void DisplaySMGdat(b2 dat)
{
P2=(P2&0x1f)|0xe0;
P0=dat;
}
void datapros()
{
if(sec<60)
{
sec++;
}
else
{
sec=00;
}
Dis_dat[0]=DuanMa[sec/10];
Dis_dat[1]=DuanMa[sec%10];
}
void SMG_Dynamic()
{
b2 i;
for(i=0;i<2;i++)
{
switch(i)
{
case 0:DisplaySMGwei(0);break;
case 1:DisplaySMGwei(1);break;
}
DisplaySMGdat(Dis_dat[i]);
delay(500);
}
}
void Delay100ms() //@12.000MHz
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 5;
j = 144;
k = 71;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void main()
{
a1 x=50;
while(1)
{
datapros();
Delay100ms();
while(x--)
{
SMG_Dynamic();
}
}
}
復(fù)制代碼
212335lral9g19br7779dy.png
(132.59 KB, 下載次數(shù): 67)
下載附件
2020-5-5 21:10 上傳
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1