0616期末考试

一、功能介绍

按动开关1和开关2分别进行1-10计数

二、结构图

三、程序

#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 = 1, s2 = 1;

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;

}

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()

if(SW1 == 0)

{

DelaySMG(200);

if(SW1 == 0)

{

while(SW1 == 0)

{

DisPlaySMG();

}

s1++;

if(s1 == 10)

{

s1 = 0;

}

}

}

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();

}

}

四、流程图

版权声明:
作者:主机优惠
链接:https://www.techfm.club/p/42719.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>