单片机期末测验--数码管表现按键触发次数

分享
程序员 2024-9-6 12:23:03 29 0 来自 中国
一  结构图


二  步伐
/******************СÃÛ·äÀÏʦµÄ51µ¥Æ¬»ú¿ª·¢ÏîÄ¿°¸Àý********************
°´¼üSW1¿ØÖÆÊýÂë¹Ü×î×ó±ßÊýλ£¬Ã¿°´Ò»ÏÂÊý×Ö´Ó0µ½9ÒÀ´ÎÏÔʾ¡£°´¼üSW2¿ØÖÆÊýÂë¹Ü×îÓÒ±ßÊýλ£¬Ã¿°´Ò»´ÎÊý×Ö´Ó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;
//¶¨Òå¹²ÑôÊýÂë¹ÜÎÞСÊýµãµÄÊý×Ö¶ÎÂëÖµ
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();
        }
}
三  流程图


2.png 四  小结
本次测验学习了数码管表现按键触发次数,在流程图上用的时间比力多,本学期的单片机课让我劳绩了一门技能,在这过程中碰到过许多困难,但幸亏在老师和同学的资助下也都办理了,在以后的学习中我信赖会有更多劳绩,本身的技能也会更好。
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-19 13:22, Processed in 0.153788 second(s), 35 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表