含代码,仿真图
单片机源程序如下:
- #include<reg52.h>
- #include"delay.h"
- #include"tlc2543.h"
- //****************************端口定义******
- sbit WX1 = P2^4;
- sbit WX2 = P2^5;
- sbit WX3 = P2^6;
- sbit WX4 = P2^7;
- //**************数组定义*******************
- uchar code tab_D[] = {
- 0x3f, //0
- 0x06, //1
- 0x5b, //2
- 0x4f, //3
- 0x66, //4
- 0x6d, //5
- 0x7d, //6
- 0x07, //7
- 0x7f, //8
- 0x6f, //9
- 0x77, //a
- 0x7c, //b
- 0x39, //c
- 0x5e, //d
- 0x79, //e
- 0x71, //f
- 0xbf //-
- }; //共阴极数码管段码
- /*******************变量定义********************/
- double dianya1;
- uint dianya_1;
- /*******************主函数********************/
- void main()
- {
- while(1)
- {
- dianya1=read(0x00)*5.0/4095*100;
- dianya_1=(uint)(dianya1);
- /*数码管显示*/
- WX1 = 0; WX2 = 1; WX3 = 1; WX4 = 1;
- P1=tab_D[dianya_1/1000];
- delayxms(3);
- P1=0x00;
- WX1 = 1; WX2 = 0; WX3 = 1; WX4 = 1;
- P1=tab_D[dianya_1%1000/100] + 0x80;
- delayxms(3);
- P1=0x00;
- WX1 = 1; WX2 = 1; WX3 = 0; WX4 = 1;
- P1=tab_D[dianya_1%1000%100/10];
- delayxms(3);
- P1=0x00;
- WX1 = 1; WX2 = 1; WX3 = 1; WX4 = 0;
- P1=tab_D[dianya_1%10];
- delayxms(3);
- P1=0x00;
- }
- }
复制代码
所有资料51hei提供下载:
共阴极数码管显示-电压表.rar
(81.2 KB, 下载次数: 68)
|