|
編程實(shí)現(xiàn)前五位數(shù)碼管顯示固定數(shù)字,后兩位數(shù)碼管循環(huán)顯示數(shù)字0~99
定時(shí)為1ms,前四位一直閃爍
#include<reg51.h>
#include<intrins.h>
#define SEG1 P0//段碼線
#define SEG2 P1//段碼線
#define SEG3 P3//段碼線
sbit S1=P2^0;//第1個(gè)數(shù)碼管公共端 位選線
sbit S2=P2^1;//第2個(gè)數(shù)碼管公共端 位選線
sbit S3=P2^2;//第3個(gè)數(shù)碼管公共端 位選線
sbit S4=P2^3;//第4個(gè)數(shù)碼管公共端 位選線
sbit S5=P2^4;//第5個(gè)數(shù)碼管公共端 位選線
void Delayms(unsigned int c);/*延時(shí)函數(shù)*/
//unsigned char code DIG_CODE[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//顯示0~F的值 共陰極
//0~F段碼 //顯示0~F的值 共陰極
unsigned char code DIG_CODE[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//顯示0~F的值 共陽極
//0~F段碼 //顯示0~F的值 共陽極
void main()
{
int n;
while(1)
for(n=0;n<=99;n++)
{
{
S1= 1;S2= 0;S3= 0;S4= 0;S5=0 ;//第1個(gè)數(shù)碼管工作 第2/3/4/5個(gè)數(shù)碼管不工作
SEG1 = DIG_CODE[0]; //萬位
Delayms(1);
S1= 0;S2= 1;S3= 0;S4= 0;S5=0; //第1/3/4/5個(gè)數(shù)碼管不工作 第2個(gè)數(shù)碼管工作
SEG1 = DIG_CODE[6]; //千位
Delayms(1);
S1= 0;S2= 0;S3= 1;S4= 0;S5=0; //第1/2/4/5個(gè)數(shù)碼管不工作 第3個(gè)數(shù)碼管工作
SEG1 = DIG_CODE[1]; //百位
Delayms(1);
S1= 0;S2= 0;S3= 0;S4= 1;S5=0; //第1/2/3/5個(gè)數(shù)碼管不工作 第4個(gè)數(shù)碼管工作
SEG1 = DIG_CODE[2]; //十位
Delayms(1);
S1= 0;S2= 0;S3= 0;S4= 0;S5=1; //第1/2/3/4個(gè)數(shù)碼管不工作 第5個(gè)數(shù)碼管工作
SEG1 = DIG_CODE[3]; //個(gè)位
Delayms(1);
SEG2= DIG_CODE[n%100/10];
SEG3= DIG_CODE[n%10];
Delayms(50);
}
}
}
void Delayms(unsigned int c) //@12.000MHz
{
unsigned char i, j;
while(c--)
{
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
}
|
|