一 但指、功能顯示
按下SW1控制C1寡痰,數(shù)碼管1從0到9依次顯示,按下SW2控制C4棋凳,數(shù)碼管4從0到9依次顯示
二拦坠,程序
/******************D???·?à?ê|μ?51μ¥???ú?a·¢????°?ày********************
SW1????×ó±?μúò???êy£???°′SW1ò?′?êy??1üò???ê?0μ?9£?SW2????×ó±?μúò???êy£???°′SW2ò?′?êy??1üò???ê?0μ?9.
**********************************************************************/
#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;
//?¨ò?12??êy??1ü?TD?êyμ?μ?êy×??????μ
unsigned char SMGNoDot_CA[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90};
unsigned char s1 = 0, s2 = 0;
/*==================ê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()
{
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);
}
/*======================°′?üé¨?è′|àíoˉêy=======================*/
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;
}
}
}
}
/*==========================?÷oˉêy============================*/
void main()
{
while(1)
{
DisPlaySMG();
Scan_Keys();
}
}
三、結(jié)構(gòu)圖
四剩岳、流程圖
五贞滨、小結(jié)
通過(guò)這次考試,我深刻認(rèn)識(shí)到讀懂程序的重要性拍棕,還有流程圖的繪制晓铆。讀懂了程序就輕松很多。