一? 功能描述
數(shù)碼管循環(huán)顯示1000-3000
數(shù)碼管顯示數(shù)字0劲弦,顯示帶小數(shù)點(diǎn)的 7
二? 程序
#include "reg52.h"
sbit C1 = P2^7;
sbit C2 = P2^6;
sbit C3 = P2^5;
sbit C4 = P2^4;
//?¨ò?12??êy??1ü?TD?êyμ?μ?êy×??????μ
unsigned char SMGNoDot_CA[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
unsigned int count = 1523;
/*==================êy??1ü?ˉì???ê?רó??óê±oˉêy==================*/
void DelaySMG(unsigned int t)
{
while(t--);
}
/*=====================μ¥??êy??1ü??ê?oˉêy=======================*/
void DisPlaySMG_Bit(unsigned char pos, unsigned char dat)
{
P0 = 0xff; //??òt
switch(pos) //????êy??1ü????
{
case 1:
C1 = 1; C2 = 0; C3 = 0; C4 = 0;
break;
case 2:
C1 = 0; C2 = 1; C3 = 0; C4 = 0;
break;
case 3:
C1 = 0; C2 = 0; C3 = 1; C4 = 0;
break;
case 4:
C1 = 0; C2 = 0; C3 = 0; C4 = 1;
break;
}
P0 = dat; //ê?3?êy??1ü??ê?μ??úèY
}
/*====================4??êy??1ü?ˉì???ê?oˉêy======================*/
void DisPlaySMG_4Bit(unsigned int dat)
{
DisPlaySMG_Bit(1, SMGNoDot_CA[dat / 1000]); //?§??
DelaySMG(100);
DisPlaySMG_Bit(2, SMGNoDot_CA[(dat % 1000) / 100]); //°ù??
DelaySMG(100);
DisPlaySMG_Bit(3, SMGNoDot_CA[(dat % 100) / 10]); //ê???
DelaySMG(100);
DisPlaySMG_Bit(4, SMGNoDot_CA[(dat % 10)]); //????
DelaySMG(100);
}
/*===================4??êy??1üòà′???ê?0??9oˉêy====================*/
void DisPlaySMG_zero_nine()
{
char i;
C1 = 1;
C2 = 1;
C3 = 1;
C4 = 1;
for(i = 0; i < 10; i++)
{
P0 = SMGNoDot_CA[i];
DelaySMG(40000);
}
}
/*=================′?êy??1ü?¢D?μ??óê±oˉêy======================*/
void Delay(unsigned int t)
{
while(t--)
{
DisPlaySMG_4Bit(count);
}
}
/*==========================?÷oˉêy============================*/
void main()
{
DisPlaySMG_zero_nine();
while(1)
{
DisPlaySMG_4Bit(count);
Delay(100);
count++;
if(count == 1600)
{
count = 0;
}
}
}
? 程序(顯示0)
#include?
#define uchar unsigned char
uchar code SEG[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void main(void)
{
while(1)
{
P1=SEG[0];
}
}
?程序(顯示7)
#include?
#define uchar unsigned char
uchar code SEG[1]={0x78};
void main(void)
{
while(1)
{
P1=SEG[0];
}
}
三? 電路圖
四? 小結(jié)
本次學(xué)習(xí)學(xué)會(huì)了在數(shù)碼管上顯示數(shù)字售担,程序和電路圖還是很簡(jiǎn)單的,程序里有一些小錯(cuò)誤自己也檢查出來了伏社,數(shù)碼管循環(huán)顯示1000-3000還是有難度的评矩。