本文介绍了基于STC89C51单片机为核心的,以AD0809数模转换芯片作为采样,以四位八段数码管作为显示的具有测量功能的具有一定精度的数字电压表。在实现基础功能的情况下,另外还可以扩展串行口通信,时钟,等其他一系列功能,使系统达到了良好的设计效果和要求。本课题主要解决A/D转换,数据处理及显示控制等三个模块。
主要系统:STC89C51;数字电压表;模数转换;数字信号
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #define TLC2543_GLOBAL
- #include "TLC2543.h"
- uint read_TLC2543(uchar channel)
- {
- register uchar i;
- uint tempAD = 0;
- while(!TLC2543GetEoc()); //wait TLC2543 free
- _delay_us(3);
- channel <<= 4;
- TLC2543Clk(TLC2543_CLR);
- TLC2543_Cs(TLC2543_SET);
- TLC2543_Cs(TLC2543_CLR); //_CS TLC2543 select
- _delay_us(3);
- for( i = 0; i < 12; i ++ )
- {
- tempAD <<= 1;
- if( TLC2543GetDo() ) //read value
- {
- tempAD |= 0x01;
- }
- if( channel&0x80 )
- {
- TLC2543Di(TLC2543_SET);
- }
- else
- {
- TLC2543Di(TLC2543_CLR);
- }
- channel <<= 1;
- TLC2543Clk(TLC2543_SET);
- nop();
- TLC2543Clk(TLC2543_CLR);
- }
- TLC2543_Cs(TLC2543_SET); //TLC2543 close
- _delay_us(1);
- return tempAD;
- }
- void _delay_us(uint us)
- {
- uchar delayi;
- while(--us)
- {
- for(delayi=0;delayi<10;delayi++);
- }
- }
复制代码- #include "led.h"
- #include "TLC2543.h"
- const uchar code displayMode=0x0f;
- uchar displayBuff[4]={0x7e,0x7e,0x7e,0x7e}; //数码管显示缓冲区,低两位为时间,最高位为抢答号
- const uchar code digitalNumber[10]={0x7e,0x06,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x73};
- void main()
- {
- uint voltageReadTemp;
- uint voltageRead;
- uchar temp;
- uchar i,j;
- init_led();
- while(1)
- {
- ledSweepDisplay(displayBuff,displayMode,4);
- voltageRead=read_TLC2543(0x05);
- voltageRead=voltageRead*0x05;
- for(i=4;i>0;i--)
- {
- temp=(uchar)(voltageRead/0x0fff);
- if(i==4)
- displayBuff[i-1]=digitalNumber[temp]|0x80;
- else
- displayBuff[i-1]=digitalNumber[temp];
- voltageRead=voltageRead%0x0fff;
- voltageReadTemp=voltageRead<<1;
- voltageRead=0x0000;
- for(j=0;j<5;j++)
- voltageRead+=voltageReadTemp;//voltageRead=voltageRead*10
-
- }
- }
-
- }
复制代码
所有资料51hei提供下载:
数字电压表.zip
(25.75 KB, 下载次数: 66)
|