⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 LED动态数码管显示
💻 C
字号:
/*************************************************************************************
五.数码管动态显示
****************************************************************************************/
#include <AT89X52.H>
sbit qian=P1^0;
sbit bai=P1^1;
sbit shi=P1^2;
sbit ge=P1^3;
code unsigned char seg7code[10]={0x3f,0x06,0x5b,0x4f,0x66,
								0x6d,0x7d,0x07,0x7f,0x6f}; //显示段码
void Delay(unsigned int tc)     //延时程序
{
	while( tc != 0 )			//如果tc为0则终止延时
	{
		unsigned int i;			//局部正整数变量 i
		for(i=0; i<100; i++);	//执行400次将耗时1毫秒
		tc--;					//tc计数减一
	}
}
void Led(int date)           //显示函数
{
	qian=0;             //P1.0输出低电平,选通千位数
	P0=seg7code[0]; //取出千位数,查表,输出。
	Delay(10);              //延时
	qian=1;           //销隐
	bai=0;                //P1.1输出低电平,选通百位数
	P0=seg7code[1]; //取出百位数,查表,输出。
	Delay(10);                 //延时
	bai=1;                //销隐
	shi=0;                //P1.2输出低电平,选通十位数
	P0=seg7code[3];    //取出十位数,查表,输出。
	Delay(10);                 //延时
	shi=1;               //销隐
	ge=0;				//P1.3输出低电平,选通十位数
	P0=seg7code[4];        //取出个位数,查表,输出。
	Delay(10);
	ge=1;
}
main()
{  
  int display_date=4; //定义并赋值要显示的数据
  while(1)
  {
   Led(display_date);//调用显示函数显示数据display_date
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -