内容来自小蜜蜂老师~
静态显示
题目要求:
代码
#include"reg52.h"
unsigned char code SMG_Duan[] = {0xC0,0xF9,0xA4,0xB0,0x99,
0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
void Delay(unsigned int t)
{
while(t--);
while(t--);
}
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 SMG_bit(unsigned char pos,unsigned char dat)
{
HC138(6);
P0=0x01<<pos;
HC138(7);
P0=dat;
}
void SMG_static()
{
unsigned i=0,j=0;
for(i=0;i<8;i++)
{
for(j=0;j<10;j++)
{
SMG_bit(i,SMG_Duan[j]);
Delay(600);
Delay(600);
}
}
HC138(6);
P0=0xff;
HC138(7);
for(j=0;j<15;j++)
{
P0=SMG_Duan[j];
Delay(600);
Delay(600);
}
}
void Initsystem()
{
HC138(4);
P0=0xff;
HC138(5);
P0=0x00;
}
void main()
{
Initsystem();
while(1)
{
SMG_static();
}
}
动态显示
题目要求:
这里显示2022啦~
代码:
#include "reg52.h"
unsigned char code SMG_Duan[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,
0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xbf};
unsigned char month = 0;
void delay(unsigned int t)
{
while(t--);
}
void HC138(unsigned char n)
{
switch(n)
{
case 4: P2 = P2 | 0x1f; P2 = 0x80; break;
case 5: P2 = P2 | 0x1f; P2 = 0xa0; break;
case 6: P2 = P2 | 0x1f; P2 = 0xc0; break;
case 7: P2 = P2 | 0x1f; P2 = 0xe0; break;
}
}
void InitSystem()
{
HC138(4);
P0 = 0xff;
HC138(5);
P0 = 0x00;
}
void SMGBit(unsigned char pos ,unsigned char dat)
{
HC138(6);
P0 = 0x01 << pos;
HC138(7);
P0 = dat;
}
void SMG_Dynamic()
{
SMGBit(0,SMG_Duan[2]);
delay(1000);
SMGBit(1,SMG_Duan[0]);
delay(1000);
SMGBit(2,SMG_Duan[2]);
delay(1000);
SMGBit(3,SMG_Duan[2]);
delay(1000);
SMGBit(4,SMG_Duan[16]);
delay(1000);
SMGBit(5,SMG_Duan[16]);
delay(1000);
SMGBit(6,SMG_Duan[month/10]);
delay(1000);
SMGBit(7,SMG_Duan[month%10]);
delay(1000);
}
void delay_SMG(unsigned int t)
{
while(t--)
{
SMG_Dynamic();
}
}
void main(void)
{
InitSystem();
while(1)
{
SMG_Dynamic();
month++;
if(month>12)
{
month = 0;
}
delay_SMG(100);
}
}