单片机6位数码管计数器程序问题
答案:2 悬赏:0 手机版
解决时间 2021-11-22 23:25
- 提问者网友:王者佥
- 2021-11-22 12:01
单片机6位数码管计数器程序问题
最佳答案
- 五星知识达人网友:你哪知我潦倒为你
- 2021-11-22 13:38
#include //STC头文件
#define uchar unsigned char
#define uint unsigned int
#define timewe 3
sbit we = P2^7;
sbit du = P2^6;
unsigned long temp;
uint jsms=0;
uchar code duan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
uchar code wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay (uint a) // 1ms延时程序(12MHz 10倍于51单片机速度时)
{
uint i;
while( --a != 0)
{
for(i = 0; i < 600; i++);
}
}
uchar disbuf[6];
void display()
{ uchar code wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
static uchar a;
if(a>=6)a=0;
we=1;
P0=0xff;
we=0;
du=1;
P0=duan[disbuf[a]];
du=0;
we=1;
P0=wei[a];
we=0;
a++;
}
void main(void)
{
temp=0;
while(1)
{
if(++jsms>=1000){
if(++temp == 999999)
temp = 0;
}
disbuf[0] = temp/100000;
disbuf[1] = temp%100000/10000;
disbuf[2] = temp%10000/1000;
disbuf[3] = temp%1000/100;
disbuf[4] = temp%100/10;
disbuf[5] = temp%10;
display();
delay(1);
}
}追问这个编译不通过啊。
#define uchar unsigned char
#define uint unsigned int
#define timewe 3
sbit we = P2^7;
sbit du = P2^6;
unsigned long temp;
uint jsms=0;
uchar code duan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
uchar code wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay (uint a) // 1ms延时程序(12MHz 10倍于51单片机速度时)
{
uint i;
while( --a != 0)
{
for(i = 0; i < 600; i++);
}
}
uchar disbuf[6];
void display()
{ uchar code wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
static uchar a;
if(a>=6)a=0;
we=1;
P0=0xff;
we=0;
du=1;
P0=duan[disbuf[a]];
du=0;
we=1;
P0=wei[a];
we=0;
a++;
}
void main(void)
{
temp=0;
while(1)
{
if(++jsms>=1000){
if(++temp == 999999)
temp = 0;
}
disbuf[0] = temp/100000;
disbuf[1] = temp%100000/10000;
disbuf[2] = temp%10000/1000;
disbuf[3] = temp%1000/100;
disbuf[4] = temp%100/10;
disbuf[5] = temp%10;
display();
delay(1);
}
}追问这个编译不通过啊。
全部回答
- 1楼网友:怙棘
- 2021-11-22 15:07
仿真实例
这个可以参考一下,可以用按键 输入所需 显示 的数字。
这个可以参考一下,可以用按键 输入所需 显示 的数字。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯