#include <reg52.h>
unsigned char segcode[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned char shiwei[6] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D};
unsigned char bitcode[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //??
// 0-9
#define Dataport P0
sbit Latch_seg = P2^2;
sbit Latch_bit = P2^3;
void delay_1s()
{
unsigned char i;
for(i = 0; i < 20; i++)
{
while(!TF0);
TF0 = 0; //???
TH0 = 0x3c;
TL0 = 0xb0;
}
}
void delay_10s()
{
unsigned char i,j;
for(j = 0; j < 10; j++)
{
for(i = 0; i < 20; i++)
{
while(!TF0);
TF0 = 0;
TH0 = 0x3c;
TL0 = 0xb0;
}
}
}
void displaygewei(unsigned char firstbit,unsigned char num) //从第几个数开始显示,控制几个数码管
{
unsigned char i;
while(1)
{
Dataport = 0;
Latch_seg = 1;
Latch_seg = 0;
Dataport = segcode[i];
Latch_seg = 1;
Latch_seg = 0;
// Dataport = ~w;
Dataport = bitcode[i + firstbit];
Latch_bit = 1;
Latch_bit = 0;
delay_1s();
// w <<= 1;
i++;
if(i == num)
{
i = 0;
// w = 0x01;
}
}
}
/*void displayshiwei(unsigned char firstbit,unsigned char num) //从第几个数开始显示,控制几个数码管
{
unsigned char i;
while(1)
{
Dataport = 0;
Latch_seg = 1;
Latch_seg = 0;
Dataport = shiwei[i];
Latch_seg = 1;
Latch_seg = 0;
// Dataport = ~w;
Dataport = bitcode[i + firstbit];
Latch_bit = 1;
Latch_bit = 0;
delay_1s();
// w <<= 1;
i++;
if(i == num)
{
i = 0;
// w = 0x01;
}
}
}*/
void main()
{
unsigned char i,firstbit,num,w;
firstbit = 0,num = 2;
w = 0x01;
TMOD = 0x01; //方式1
TH0 = 0x3c;
TL0 = 0xb0;
TR0 = 1;
while(1)
{
for(i = 0; i < 10; i++)
{
w = 0x01;
Dataport = segcode[i];
Latch_seg = 1;
Latch_seg = 0;
Dataport = ~w;
Latch_bit = 1;
Latch_bit = 0;
delay_1s();
w <<= 1;
i++;
if(i == 8)
{
i = 0;
w = 0x01;
}
}
for(i = 0; i < 6; i++)
{
w = 0x01;
Dataport = segcode[i];
Latch_seg = 1;
Latch_seg = 0;
Dataport = ~w;
Latch_bit = 1;
Latch_bit = 0;
delay_10s();
w <<= 1;
i++;
if(i == 8)
{
i = 0;
w = 0x01;
}
}
}
}
共阴极数码管60秒表显示
最新推荐文章于 2022-12-31 16:52:20 发布