利用74ls245驱动和74ls138位选。
#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
void delay(uint t)//延时函数
{
while(t--);
}
void main()//主函数
{
uint i;
//采用共阴极数码管
uint code zixing[8]={0x5b,0x3f,0x3f,0x4f,0x3f,0x07,0x4f,0x3f};//数组对应显示字符20030730
uint code weixuan[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
while(1)
{
for(i=0;i<8;i++)
{
P0=zixing[i];
P2=weixuan[i];
delay(10);
P0=0x00;//消除残影
}
}
}
proteus所需器件
实际运行图
更改学号显示请更改数组内容,如下
//此数组表示的是字符
//可与共阴极数码管数组相对应
//0-0x3f,//1-0x06,//2-0x5b,//3-0x4f,//4-0x66,//5-0x6d,
//6-0x7d,//7-0x07,//8-0x7f,//9-0x6f,//A-0x77,//B-0x7c,
//C-0x39,//D-0x5e,//E-0x79,//F-0x71.
可按需互换
下面以20030730的数组为例。
uint code zixing[8]={0x5b,0x3f,0x3f,0x4f,0x3f,0x07,0x4f,0x3f};
// 2 0 0 3 0 7 3 0