找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 7484|回复: 1
打印 上一主题 下一主题
收起左侧

数码管学号滚动显示的单片机程序

[复制链接]
跳转到指定楼层
楼主
源程序
#include <REG51.H>
#define uint unsigned int
#define uchar unsigned char
uchar code DIS_SEG7[]={0xf9,0x92,0xb0,0xf9,0xc0,0xa4,0xf9,0xb0};//设置学号,共阳字形码
uchar code DIS_BIT[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};// 8位数码管位选
sbit k1=P1^0;
sbit k2=P1^1;
void delay1ms(uint i)
{
  uint j;
  while(i--)
     for(j=0;j<110;j++);
}
void main(void)
{
   uchar cnt,ttt;
   uchar DISP[]={0,1,2,3,4,5,6,7};
   while(1)
   {
       for(ttt=0;ttt<100;ttt++)
    for(cnt=0;cnt<8;cnt++)
    {//点亮数码馆0-7
        P2=0;
     P0=DIS_SEG7[DISP[cnt]];
     P2=~DIS_BIT[cnt];
     if(k1==1&&k2==1)
         delay1ms(1);
      else {
       if(k1==0&&k2==1)
                delay1ms(2);
       else{
           if(k1==1&&k2==0)
                      delay1ms(3);
       else{
                           if(k1==0&&k2==0)
                           delay1ms(4);
         }
         }
                       }
  }
ttt=DISP[0];
DISP[0]=DISP[1];
DISP[1]=DISP[2];
DISP[2]=DISP[3];
DISP[3]=DISP[4];
DISP[4]=DISP[5];
  DISP[5]=DISP[6];
   DISP[6]=DISP[7];
DISP[7]=ttt;
}
}


无标题1.png (116.46 KB, 下载次数: 66)

无标题1.png

无标题.png (97.39 KB, 下载次数: 61)

无标题.png
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:738664 发表于 2020-4-26 16:54 | 只看该作者
if(k1==1&&k2==1)
         delay1ms(1);
      else {
       if(k1==0&&k2==1)
                delay1ms(2);
       else{
           if(k1==1&&k2==0)
                      delay1ms(3);
       else{
                           if(k1==0&&k2==0)
                           delay1ms(4);
         }
         }
                       }

这个有什么用啊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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