求助会keil和51单片机的大神,写一段数
答案:2 悬赏:80 手机版
解决时间 2021-12-15 21:54
- 提问者网友:人海浩瀚
- 2021-12-15 17:38
求助会keil和51单片机的大神,写一段数
最佳答案
- 五星知识达人网友:轻狂的绅士
- 2021-12-15 19:09
写一段数码管显示的程序吗?这一段就可以给你参考:
#include
#define uchar unsigned char;
uchar distab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; //0到f
uchar number,dat;
void t0isr() interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
number++;
if(number>1)number=0;
switch(number)
{
case 0:P2=0x02;P0=distab[dat/10];
break;
case 1:P2=0x01;P0=distab[dat%10];
break;
default:break;
}
}
void t1isr() interrupt 3
{
dat++;
dat%=100;
}
main()
{
TMOD=0x61;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=0xff;
TL1=0xff;
TR1=1;
ET1=1;
TR0=1;
ET0=1;
EA=1;
while(1);
}
#include
#define uchar unsigned char;
uchar distab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; //0到f
uchar number,dat;
void t0isr() interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
number++;
if(number>1)number=0;
switch(number)
{
case 0:P2=0x02;P0=distab[dat/10];
break;
case 1:P2=0x01;P0=distab[dat%10];
break;
default:break;
}
}
void t1isr() interrupt 3
{
dat++;
dat%=100;
}
main()
{
TMOD=0x61;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=0xff;
TL1=0xff;
TR1=1;
ET1=1;
TR0=1;
ET0=1;
EA=1;
while(1);
}
全部回答
- 1楼网友:少女适俗韵
- 2021-12-15 19:40
#include "reg51.h"
#define uchar unsigned char
uchar display_code[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
sbit key3=p1^0;//引脚你自己修改
sbit key3=p1^1;
uchar time=0;//计数值
void delay(void)
{
uchar i;
for(i=250;i>0;i--);
}
void display()
{
p2=0x01;
p0=display_code[time/10]; //数码管的引脚自行修改
delay();
p2=0x00;
p2=0x02;
p0=display_code[time%10];
delay();
p2=0x00;
}
void main(void)
{
while(1)
{
display();
if(key3==0) {while(key3==0);time++;if(time>20) time=0;}
if(key4==0) {while(key4==0);time--;if(time<0) time=20;}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯