1、电路设计:
p0实现段选,p2实现位选,74hc04是反相器,有反向和放大的双重作用。
2、程序设计:
#include<reg52.h> code unsigned char seven_seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff}; sbit P2_0 = P2^0; sbit P2_1 = P2^1; sbit P2_2 = P2^2; sbit P2_3 = P2^3; sbit P2_4 = P2^4; sbit P2_5 = P2^5; void delay(unsigned int x){ while(x--); } int main(){ while(1){ P2 = 0x01;P0 = seven_seg[0];delay(300); P2 = 0x02;P0 = seven_seg[1];delay(300); P2 = 0x04;P0 = seven_seg[2];delay(300); P2 = 0x08;P0 = seven_seg[3];delay(300); P2 = 0x10;P0 = seven_seg[4];delay(300); P2 = 0x20;P0 = seven_seg[5];delay(300); P2 = 0x40;P0 = seven_seg[6];delay(300); P2 = 0x80;P0 = seven_seg[7];delay(300); } }
3、运行结果:
静态显示虽然具有亮度高(有持续电压)的优点,但是浪费引脚。动态显示虽然节省了引脚但是亮度较低,完成基本的显示功能还是没问题的。
本实验通过p2口实现循环段选,每一位数字实现轮流显示。
原文地址:https://www.cnblogs.com/zhai1997/p/11623497.html
时间: 2024-10-11 07:03:50