51单片机数码管显示

#include <reg52.h>
#define duan P0
#define uchar unsigned char

sbit wei0=P2^4;
sbit wei1=P2^5;
sbit wei2=P2^6;
sbit wei3=P2^7;

uchar code sz[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07
,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};	//数码管字符码,从0-9,a-f,0x00(bu不显示),共17个
void delay (unsigned int xms)
{
unsigned int i,j;
for(i=0;i<xms;i++)
  for(j=0;j<112;j++);
}

void main()
{
   while(1)
   {
    wei0=1;
	wei1=0;
	wei2=0;
	wei3=0;
	duan=sz[4];
	delay(1000);

	wei0=0;
	wei1=1;
	wei2=0;
	wei3=0;
	duan=sz[3];
	delay(1000);

	wei0=0;
	wei1=0;
	wei2=1;
	wei3=0;
	duan=sz[2];
	delay(1000);

	wei0=0;
	wei1=0;
	wei2=0;
	wei3=1;
	duan=sz[1];
	delay(1000);
   }
} 

数码管的显示,采用共阴极字码表。

51单片机数码管显示

 

上一篇:Linux用户及权限管理


下一篇:课设 - 基于单片机的简易数字电压表设计(电路+程序)