# include "reg52.h"
void delay(unsigned char i)
{
while(i--);
}
void showseg();
void maindelay(unsigned char t)
{
while(t--)
{
showseg();
}
}
unsigned char yu = 1;
unsigned char code table[] =
{
0xc0,//0
0xf9,//1
0xa4,//2
0xb0,//3
0x99,//4
0x92,//5
0x82,//6
0xf8,//7
0x80,//8
0x90,//9
0x88,//A
0x83,//B
0xc6,//C
0xa1,//D
0x86,//E
0x8e,//F
0xbf,//-
0x7f//.
};
void HC138(unsigned char n)
{
switch(n)
{
case 4:
P2 = (P2 & 0x1f) | 0x80;
break;
case 5:
P2 = (P2 & 0x1f) | 0xa0;
break;
case 6:
P2 = (P2 & 0x1f) | 0xc0;
break;
case 7:
P2 = (P2 & 0x1f) | 0xe0;
break;
}
}
void show(unsigned char pos,unsigned char dat)
{
HC138(7);//数码管的内容
P0 = table[dat];
HC138(6);//数码管的位置
P0 = 0x01 << pos;
}
void showseg()
{
show(0,2);//2018
delay(500);
show(1,0);
delay(500);
show(2,1);
delay(500);
show(3,8);
delay(500);
show(4,16);//--
delay(500);
show(5,16);
delay(500);
show(6,yu/10);//月份
delay(500);
show(7,yu%10);
delay(500);
}
void main()
{
while(1)
{
showseg();
yu++;
if(yu > 12)
yu = 1;
maindelay(1000);
}
}
标签:P2,动态显示,04,void,unsigned,char,数码管,0x1f From: https://www.cnblogs.com/Unclesundada/p/17000250.html