一、功能描述
按下SW1控制左侧数码管会从0~9依次变化;按下SW2控制右侧数码管也会从0~9依次变化,然后循环。
二、结构图
三、流程
/******************СÃÛ·äÀÏʦµÄ51µ¥Æ¬»ú¿ª·¢ÏîÄ¿°¸Àý********************
**********************************************************************/
#include "reg52.h"
sbit C1 =P2^7;
sbit C2 =P2^6;
sbit C3 =P2^5;
sbit C4 =P2^4;
sbit SW1 =P3^4;
sbit SW2 =P3^3;
//¶¨Òå¹²ÑôÊýÂë¹ÜÎÞСÊýµãµÄÊý×Ö¶ÎÂëÖµ
unsigned char SMGNoDot_CA[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
unsigned char s1 = 0, s2 = 0;
/*==================ÊýÂë¹Ü¶¯Ì¬ÏÔʾרÓÃÑÓʱº¯Êý==================*/
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()
{
DisPlaySMG_Bit(1, SMGNoDot_CA[s1]);
DelaySMG(100);
DisPlaySMG_Bit(2, 0xbf);
DelaySMG(100);
DisPlaySMG_Bit(3, 0xbf);
DelaySMG(100);
DisPlaySMG_Bit(4, SMGNoDot_CA[s2]);
DelaySMG(100);
}
/*======================°´¼üɨÃè´¦Àíº¯Êý=======================*/
void Scan_Keys()
{
//SW1°´¼üɨÃè´¦Àí
if(SW1 == 0)
{
DelaySMG(200);
if(SW1 == 0)
{
while(SW1 == 0)
{
DisPlaySMG();
}
s1++;
if(s1 == 10)
{
s1 = 0;
}
}
}
//SW2°´¼üɨÃè´¦Àí
if(SW2 == 0)
{
DelaySMG(200);
if(SW2 == 0)
{
while(SW2 == 0)
{
DisPlaySMG();
}
s2++;
if(s2 == 10)
{
s2 = 0;
}
}
}
}
/*==========================Ö÷º¯Êý============================*/
void main()
{
while(1)
{
DisPlaySMG();
Scan_Keys();
}
}
四、流程图
五、小结
本次考试改了一点代码,其他没什么太大问题,要想画好流程图必须读懂代码的意思不然就跟刚开始的我一样无从下手,在和我的同桌不懈努力下终于找到了一点规律,但还是不太正确,但是我们还是没有放弃,毕竟这次是期末考试,不想要再来下次,不过在这枯燥的过程中我也发现了发现错误并改正真的很有成就感,我是抱着真的想学习一门技术的心态,毕竟技多不压身。