用STC12C2052AD單片機(jī)寫一個(gè)數(shù)碼管顯示程序
數(shù)碼管型號(hào)是:ARKLED 1810 SR420361N
單片機(jī)的P1口接數(shù)碼管的A,B,C,D,E,F,G,DP
單片機(jī)的P3口接數(shù)碼管的位選擇
#include <STC12C2052AD.H>
sbit S1=P3^7; //第一位數(shù)碼管
sbit S2=P3^5; //第二位數(shù)碼管
sbit S3=P3^4; //第三位數(shù)碼管
sbit S4=P3^3; //第四位數(shù)碼管
//段顯示
unsigned char code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
unsigned char j,k,m;
//延時(shí)函數(shù)
void delay(unsigned int t)
{
unsigned int a,b;
for(a=t;a>0;a--)
for(b=1000;b>0;b--);
}
//顯示函數(shù)
void Display(unsigned int shu)
{
P1=table[shu/1000];
S1=0;
S2=1;
S3=1;
S4=1;
delay(2);
P1=table[shu/100%10];
S1=1;
S2=0;
S3=1;
S4=1;
delay(2);
P1=table[shu/10%10];
S1=1;
S2=1;
S3=1;
S4=0;
delay(2);
P1=table[shu%10];
S1=1;
S2=1;
S3=0;
S4=1;
delay(2);
}
//主函數(shù)
void main()
{
while(1)
{
{
Display(1234);
}
}
}
|