要求用单片机控制数码管显示0-f。按一下按键,数码管的显示数字加一。

要求用单片机控制数码管显示0-f。按一下按键,数码管的显示数字加一。需要keil的程序和proteus的仿真图,谢谢了

请你参考:

代码如下:

#include<reg51.h>

sbit Button=P3^0;

unsigned char code segCode[]=
{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};

void Delayms(unsigned int x)
{
  unsigned char t;
while(x--)
for(t=0;t<120;t++);
}

void main()
{
  unsigned  char i;

while(1)
{
  if(!Button)
{
  Delayms(10);
if(!Button)
P0=segCode[i];
i=++i%16;
while(!Button);
}

}

希望对你有所帮助!!!

温馨提示:答案为网友推荐,仅供参考
相似回答