|
第一个问题:数码管前四位 ? 前四位怎么接的 接在哪里 ?第二个问题: 0.1 S 的速度 ! 看了半天 我是看不清 0.5 S 的你看看吧
第三个问题: 数码管还要做其他用途吗 ?
0.5 S 循环 0 - F 定时器 0 启动 - P32 停止 - P33
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
sbit LSD=P2^5;
sbit key_k1=P3^1;
sbit key_k2=P3^0;
sbit key_k3=P3^2;
sbit key_k4=P3^3;
unsigned int time_ms = 0;
unsigned int time_s = 0;
uchar smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void Display_All(unsigned char val);
void Display(unsigned char val) ;
void delayms(uint z);
void delayms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
TMOD=0x1;
TH0=0xfc;
TL0=0x18; // 1ms
TF0 = 0;
TR0=1;//启动定时器0
ET0=1;
IT0=1;
EX0=1;
IT1=1;
EX1=1;
EA=1;
while(1)
{
Display( time_s ); //扫描模式
// Display_All(time_s);//直接赋值
}
}
void Display_All(unsigned char val)
{
P0=smgduan[val];
LSA=0;LSB=0;LSC=0;LSD=0;
}
void Display(unsigned char val)
{
P0=smgduan[val];
LSA=0;
delayms(1);
P0=0x00;
LSA=1;
P0=smgduan[val];
LSB=0;
delayms(1);
P0=0x00;
LSB=1;
P0=smgduan[val];
LSC=0;
delayms(1);
P0=0x00;
LSC=1;
P0=smgduan[val];
LSD=0;
delayms(1);
P0=0x00;
LSD=1;
}
void timer0(void) interrupt 1
{
TH0=0xfc;
TL0=0x18;
if( ++time_ms >= 500) // 0.5 s
{
time_ms = 0;
if(++time_s >= 16)time_s = 0;
}
}
void int0(void) interrupt 0
{
delayms(5);
if(key_k3==0)
{
TR0=1; //启动定时器0
}
while(!key_k1);
}
void int1(void) interrupt 2
{
delayms(5);
if(key_k4==0)
{
TR0=0; //停止定时器0
}
while(!key_k2);
}
|
|