找回密码
 立即注册

QQ登录

只需一步,快速开始

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

关于单片机数码管显示程序 如果delay的值调大一点,2和4才能能显示出来?

[复制链接]
跳转到指定楼层
楼主
这个地方数码管显示,如果delay的值调大一点,2和4就能显示出来,如果delay调小,2和4就不会显示,只显示0135,不知道哪里有问题


单片机源程序如下:
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={~0xc0,~0xf9,~0xa4,~0xb0,~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90};//数码管段选
uchar code wela[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};//数码管位选
sbit d1=P1^0;
sbit beep=P2^3;
sbit switch1=P2^6;//段选LE
sbit switch2=P2^7;//位选LE
uchar x,tt;
void delay(uint z)//unit是宏定义
{
        uint x;
        for(x=z;x>0;x--);
            
}
void display()
{
        uchar x,y;
        switch1=0;
        switch2=1;
        for(x=0;x<6;x++)
        {
                P0=wela[x];
                switch2=0;
                switch1=1;
                P0=table[x];
                switch1=0;
                delay(95);
                switch2=1;
        }
        
        
}
void main()
{ tt=0;
        TMOD=0x01;//设置定时器0工作方式
  TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        EA=1;//总中断
        ET0=1;//
        TR0=1;//启动定时器
        beep=0;
        while(1)
        {
                display();
        }
        
}


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

使用道具 举报

沙发
ID:213173 发表于 2022-1-24 20:40 | 只看该作者

  1. #include <reg52.h>
  2. #include <intrins.h>
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. //uchar code table[]={~0xc0,~0xf9,~0xa4,~0xb0,~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90};//数码管段选
  6. uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//共阴数码管段码"0~9"
  7. uchar code wela[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};//数码管位选
  8. //sbit d1=P1^0;
  9. //sbit beep=P2^3;
  10. sbit switch1=P2^6;//段选LE
  11. sbit switch2=P2^7;//位选LE
  12. uchar x;//tt;
  13. /*
  14. void delay(uint z)//unit是宏定义
  15. {
  16.         uint x;
  17.         for(x=z;x>0;x--);      
  18. }*/

  19. void display()
  20. {
  21.         P0=0x00;
  22.         switch1=1;
  23.         switch1=0;

  24.         P0=wela[x];
  25.         switch2=1;
  26.         switch2=0;

  27.         P0=table[x];
  28.         switch1=1;
  29.         switch1=0;

  30.         if(++x>=6)
  31.                 x=0;
  32. }

  33. void main()
  34. {
  35. //        tt=0;
  36.         TMOD=0x01;//设置定时器0工作方式
  37.         TH0=(65536-2000)/256;//2ms
  38.         TL0=(65536-2000)%256;
  39. //        EA=1;//总中断
  40. //        ET0=1;//
  41.         TF0=0;
  42.         TR0=1;//启动定时器
  43. //        beep=0;
  44.         while(1)
  45.         {
  46.                 if(TF0)//查询方式
  47.                 {
  48.                         TF0=0;
  49.                         TH0=(65536-2000)/256;
  50.                         TL0=(65536-2000)%256;
  51.                         display();
  52.                 }
  53.         }
  54. }
复制代码



回复

使用道具 举报

板凳
ID:755966 发表于 2022-1-24 21:46 | 只看该作者
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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