1、电路设计:
LE接P3.0来实现段选或位选,OE接地,当LE为高电平的时候,锁存器为通路。
2、程序设计:
#include<reg52.h> sbit P3_0 = P3^0; code unsigned char seven_seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff}; void delay(unsigned int x){ while(x--); } int main(){ while(1){ P3_0 = 0;P0 = 0x01;P3_0 = 1;P3_0 = 0;P0 = seven_seg[0];delay(150);P0=0xff; P3_0 = 0;P0 = 0x02;P3_0 = 1;P3_0 = 0;P0 = seven_seg[1];delay(150);P0=0xff; P3_0 = 0;P0 = 0x04;P3_0 = 1;P3_0 = 0;P0 = seven_seg[2];delay(150);P0=0xff; P3_0 = 0;P0 = 0x08;P3_0 = 1;P3_0 = 0;P0 = seven_seg[3];delay(150);P0=0xff; P3_0 = 0;P0 = 0x10;P3_0 = 1;P3_0 = 0;P0 = seven_seg[4];delay(150);P0=0xff; P3_0 = 0;P0 = 0x20;P3_0 = 1;P3_0 = 0;P0 = seven_seg[5];delay(150);P0=0xff; P3_0 = 0;P0 = 0x40;P3_0 = 1;P3_0 = 0;P0 = seven_seg[6];delay(150);P0=0xff; P3_0 = 0;P0 = 0x80;P3_0 = 1;P3_0 = 0;P0 = seven_seg[7];delay(150);P0=0xff; } }
3、运行结果:
以前需要两个端口来实现的显示功能,现在只需要一个P0口就可以实现数码管的显示,大大减少了端口的占用,电路的设计更加合理。