| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5125 人关注过本帖
标题:单片机和proteus
只看楼主 加入收藏
祝你前程似锦
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2020-2-6
结帖率:70%
收藏
已结贴  问题点数:12 回复次数:3 
单片机和proteus
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1 = P3^4;
sbit key2 = P3^5;
sbit key3 = P3^6;
sbit key4 = P3^7;
sbit dula = P2^6;
sbit wela = P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
void delay(uint);
uchar numt0,num;
void display(uchar numdis)
{
    uchar shi,ge;
    shi = numdis/10;
    ge = numdis%10;
    dula = 1;
    P0 = table[shi];
    dula = 0;
    P0 = 0xff;
    wela = 1;
    P0 = 0xfe;
    wela = 0;
    delay(5);

    dula = 1;
    P0 = table[ge];
    dula = 0;
    P0 = 0xff;
    wela = 1;
    P0 = 0xfd;
    wela = 0;
    delay(5);
   

}
void delay(uint z)
{
    uint i,j;
    for(i = z;i > 0;i--)
    for(j = 110;j > 0;j--);
}               
void init()
{
TMOD = 0x01;
TH0 = (65536 - 50000)/256;
TL0 = (65536 - 50000)%256;
EA = 1;
ET0 = 1;
}
void keyscan()
{
    if(key1 == 0)
    {
        delay(10);
        if(key1 == 0)
        {
            num++;
            if(num == 60)
                num = 0;
                while(!key1);
        }
    }
    if(key2 == 0)
    {
        delay(10);
        if(key2 == 0)
        {
            if(num == 0)
                num = 60;
                num--;
                while(!key2);
        }
    }
    if(key3 == 0)
    {
        delay(10);
        if(key3 == 0)
        {
            num = 0;
            while(!key3);
        }
    }
    if(key4 == 0)
    {
        delay(10);
        if(key4 == 0)
        {
            while(!key4);
            TR0 = ~TR0;
        }
    }

}
void main()
{
     init();
    while(1)
    {
        keyscan();
        display(num);
    }

}                           
void T0_time()interrupt 1
{
    TH0 = (65536 - 50000)/256;
    TL0 = (65536 - 50000)%256;
    numt0++;
   
    if(numt0 == 20)
    {
        numt0 = 0;
        num++;
        if(num == 60)
        num = 0;
    }
}
这是我程序 下面是Proteus
图片附件: 游客没有浏览图片的权限,请 登录注册

搜索更多相关主题的帖子: while num 65536 delay void 
2020-11-03 19:46
祝你前程似锦
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2020-2-6
收藏
得分:0 
他一仿真就出现这样的问题
图片附件: 游客没有浏览图片的权限,请 登录注册
2020-11-03 19:47
xianfajushi
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:8
帖 子:527
专家分:690
注 册:2007-9-8
收藏
得分:6 
P0 = !table[shi];试看
2020-11-04 09:04
nosnoy
Rank: 9Rank: 9Rank: 9
来 自:mcu
等 级:贵宾
威 望:14
帖 子:541
专家分:1178
注 册:2016-9-17
收藏
得分:6 
void keyscan()
{
    if(key1 == 0)
    {
        delay(10);
        if(key1 == 0)
        {
            num++;
            if(num == 60)
                num = 0;
                while(!key1);
        }
    }
    if(key2 == 0)
    {
        delay(10);
        if(key2 == 0)
        {
            if(num == 0)
                num = 60;
                num--;
                while(!key2);
        }
    }
    if(key3 == 0)
    {
        delay(10);
        if(key3 == 0)
        {
            num = 0;
            while(!key3);
        }
    }
    if(key4 == 0)
    {
        delay(10);
        if(key4 == 0)
        {
            while(!key4);
            TR0 = ~TR0;
        }
    }

}
你的按键扫描程序有大问题

穷举是最暴力的美学
2020-11-07 11:40
快速回复:单片机和proteus
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.060161 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved