一、功能描述
①
②
③
二、程序
①/******************СÃÛ·äÀÏʦµÄ51µ¥Æ¬»ú¿ª·¢ÏîÄ¿°¸Àý********************
Ó²¼þ£º XMF05A 51µ¥Æ¬»ú¿ª·¢Ì×¼þ
°¸ÀýÏîÄ¿£ºµ¥¸öÊýÂë¹ÜÏÔʾÊý×Ö
ÊÓƵ½Ì³Ì£º¡¾ÊýÂë¹ÜÏÔʾ02¡¿µ¥¸öÊýÂë¹ÜÏÔʾÊý×Ö£¨´úÂë²»ÍêÈ«Ò»Ö£¬±¾ÖÊÉÏÊÇÒ»Ñù£©
**********************************************************************/
#include "reg52.h"
//¶¨Òå¹²ÑôÊýÂë¹ÜÎÞСÊýµãµÄÊý×Ö¶ÎÂëÖµ
unsigned char SMGNoDot_CA[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
/*=======================¼òµ¥µÄÑÓʱº¯Êý========================*/
void Delay(unsigned int t)
{
while(t--);
}
/*=====================ÊýÂë¹ÜÏÔʾÊý×Öº¯Êý=======================*/
void DisPlaySMG()
{
char i;
P2 = 0x80; //ʹÄÜÊýÂë¹Ü×î×ó±ßµÄһλ
//Öð¶ÎµãÁÁÊýÂë¹Ü
for(i = 0; i <= 8; i++)
{
P0 = 0xff << i;
Delay(40000);
}
//ÒÀ´ÎÏÔʾÊý×Ö0¡«9
for(i = 0; i < 10; i++)
{
P0 = SMGNoDot_CA[i];
Delay(40000);
}
}
/*==========================Ö÷º¯Êý============================*/
void main()
{
while(1)
{
DisPlaySMG();
}
}
②/******************СÃÛ·äÀÏʦµÄ51µ¥Æ¬»ú¿ª·¢ÏîÄ¿°¸Àý********************
*********Å·ºÆÔ´½²¡¶51µ¥Æ¬»úÓ¦Óÿª·¢»ù´¡¡·ÊÓƵ½Ì³ÌµÄÏîÄ¿¹¤³ÌÔ´Âë********
Ó²¼þ£º XMF05A 51µ¥Æ¬»ú¿ª·¢Ì×¼þ
°¸ÀýÏîÄ¿£º¶à¸öÊýÂë¹Ü¾²Ì¬ÏÔʾ
ÊÓƵ½Ì³Ì£º¡¾ÊýÂë¹ÜÏÔʾ04¡¿¶à¸öÊýÂë¹Ü¾²Ì¬ÏÔʾ
**********************************************************************/
#include "reg52.h"
sbit C1 = P2^7;
sbit C2 = P2^6;
sbit C3 = P2^5;
sbit C4 = P2^4;
//¶¨Òå¹²ÑôÊýÂë¹ÜÎÞСÊýµãµÄÊý×Ö¶ÎÂëÖµ
unsigned char SMGNoDot_CA[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
/*=======================¼òµ¥µÄÑÓʱº¯Êý========================*/
void Delay(unsigned int t)
{
while(t--);
}
/*=====================ÊýÂë¹ÜÏÔʾÊý×Öº¯Êý=======================*/
void DisPlaySMG()
{
char i;
P2 = 0x00; //P2µÄ8¸öÒý½ÅÊä³öµãµçƽ
//×îÓÒ±ß1λÊýÂë¹Ü£¬ÒÀ´ÎÏÔʾÊý×Ö0¡«9
for(i = 0; i < 10; i++)
{
C4 = 1;
P0 = SMGNoDot_CA[i];
Delay(40000);
}
//×îÓÒ±ß2λÊýÂë¹Ü£¬ÒÀ´ÎÏÔʾÊý×Ö0¡«9
for(i = 0; i < 10; i++)
{
C4 = 1;
C3 = 1;
P0 = SMGNoDot_CA[i];
Delay(40000);
}
//3λÊýÂë¹Ü£¬ÒÀ´ÎÏÔʾÊý×Ö0¡«9
for(i = 0; i < 10; i++)
{
C4 = 1;
C3 = 1;
C2 = 1;
P0 = SMGNoDot_CA[i];
Delay(40000);
}
//4λÊýÂë¹Ü£¬ÒÀ´ÎÏÔʾÊý×Ö0¡«9
for(i = 0; i < 10; i++)
{
C4 = 1;
C3 = 1;
C2 = 1;
C1 = 1;
P0 = SMGNoDot_CA[i];
Delay(40000);
}
}
/*==========================Ö÷º¯Êý============================*/
void main()
{
while(1)
{
DisPlaySMG();
}
}
③/******************СÃÛ·äÀÏʦµÄ51µ¥Æ¬»ú¿ª·¢ÏîÄ¿°¸Àý********************
СÃÛ·äµÄ¿ª·¢Ì×¼þ¹ºÂòÁ´½Ó£ºxmfkj.taobao.com
**********************************************************************/
#include "reg52.h"
sbit C1 = P2^7;
sbit C2 = P2^6;
sbit C3 = P2^5;
sbit C4 = P2^4;
//¶¨Òå¹²ÑôÊýÂë¹ÜÎÞСÊýµãµÄÊý×Ö¶ÎÂëÖµ
unsigned char SMGNoDot_CA[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
unsigned int count = 1523;
/*==================ÊýÂë¹Ü¶¯Ì¬ÏÔʾרÓÃÑÓʱº¯Êý==================*/
void DelaySMG(unsigned int t)
{
while(t--);
}
/*=====================µ¥¸öÊýÂë¹ÜÏÔʾº¯Êý=======================*/
void DisPlaySMG_Bit(unsigned char pos, unsigned char dat)
{
P0 = 0xff; //ÏûÒþ
switch(pos) //Ñ¡ÔñÊýÂë¹ÜλÖÃ
{
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; //Êä³öÊýÂë¹ÜÏÔʾµÄÄÚÈÝ
}
/*====================4¸öÊýÂë¹Ü¶¯Ì¬ÏÔʾº¯Êý======================*/
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¸öÊýÂë¹ÜÒÀ´ÎÏÔʾ0¡«9º¯Êý====================*/
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);
}
}
/*=================´øÊýÂë¹ÜˢеÄÑÓʱº¯Êý======================*/
void Delay(unsigned int t)
{
while(t--)
{
DisPlaySMG_4Bit(count);
}
}
/*==========================Ö÷º¯Êý============================*/
void main()
{
DisPlaySMG_zero_nine();
while(1)
{
DisPlaySMG_4Bit(count);
Delay(100);
count++;
if(count == 1600)
{
count = 0;
}
}
}
四、小结