求助会keil和51单片机的大神,写一段数码管程序
发布网友
发布时间:2022-05-18 21:27
我来回答
共1个回答
热心网友
时间:2023-11-05 20:24
#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;}
}
}追问能用百度私信聊一下么,有些关于单片机的问题想请教下