仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机main程序
#include <intrins.h>
#include <reg51.h>
#include <stdlib.h>
#include "HDM32GS12.h"
#include "ReadADC.h"
#define uchar unsigned char
#define uint unsigned int
#define port P0
/*参数的定义*/
double adc;
double qiya;
long qiya_1;
double haiba;
long haiba_1;
int ge_q,ge_h;
int shi_q,shi_h;
int bai_q,bai_h;
int qian_h;
int shu1_q;
int shu2_q;
/*延时*/
void delay(uchar z)
{
int x;
for(x=z;x>0;x--);
}
void main()
{
lcdini();//初始化
clrscr();//清屏
while(1)
{
adc=ReadADC();//ADC值获取
qiya=(adc+345.618)/36.855;//气压
haiba=9002.2-89.245*qiya;//海拔
if(haiba<0){haiba=0;}
haiba_1=haiba;//取整
qiya_1=qiya*100;//左移2位取整
/*海拔的显示*/
// qian_h=haiba_1/1000;
// bai_h=haiba_1/100%10;
// shi_h=haiba_1/10%10;
// ge_h=haiba_1/1%10;
/*ADC的显示*/
qian_h=(int)adc/1000;
bai_h=(int)adc/100%10;
shi_h=(int)adc/10%10;
ge_h=(int)adc/1%10;
/*气压的显示*/
bai_q=qiya_1/10000%10;
shi_q=qiya_1/1000%10;
ge_q=qiya_1/100%10;
shu1_q=qiya_1/10%10;
shu2_q=qiya_1%10;
/*显示函数*/
Draw_wordh(0,0,0,16);
Draw_wordh(1,16,0,16);
Draw_wordh(2,32,0,16);
Draw_wordh(10,48,2,8);
Draw_wordh(bai_q,56,2,8);
Draw_wordh(shi_q,64,2,8);
Draw_wordh(ge_q,72,2,8);
Draw_wordh(11,80,2,8);
Draw_wordh(shu1_q,88,2,8);
Draw_wordh(shu2_q,96,2,8);
Draw_wordh(3,0,3,16);
Draw_wordh(4,16,3,16);
Draw_wordh(10,32,1,8);
Draw_wordh(qian_h,40,1,8);
Draw_wordh(bai_h,48,1,8);
Draw_wordh(shi_h,56,1,8);
Draw_wordh(ge_h,64,1,8);
Draw_wordx(0,0,0,16);
Draw_wordx(1,16,0,16);
Draw_wordx(2,32,0,16);
Draw_wordx(10,48,2,8);
Draw_wordx(bai_q,56,2,8);
Draw_wordx(shi_q,64,2,8);
Draw_wordx(ge_q,72,2,8);
Draw_wordx(11,80,2,8);
Draw_wordx(shu1_q,88,2,8);
Draw_wordx(shu2_q,96,2,8);
Draw_wordx(3,0,3,16);
Draw_wordx(4,16,3,16);
Draw_wordx(10,32,1,8);
Draw_wordx(qian_h,40,1,8);
Draw_wordx(bai_h,48,1,8);
Draw_wordx(shi_h,56,1,8);
Draw_wordx(ge_h,64,1,8);
}
}
Keil代码与Proteus8.8仿真下载:
仿真和程序.7z
(107.26 KB, 下载次数: 39)
|