完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
如下,这是程序。,恳请有经验的人帮我改改,谢谢
#include #include #define uchar unsigned char #define uint unsigned int ***it SCL = P1^1; ***it SDA = P1^0; ***it lcdrs=P2^6; ***it lcdwr=P2^5; ***it lcden_1602=P2^7; uchar MSB; uchar LSB; unsigned long T; long X1; long X2; long B5; signed short AC1; signed short AC2; signed short AC3; unsigned short AC4; unsigned short AC5; unsigned short AC6; signed short B1; signed short B2; signed short MB; signed short MC; signed short MD; long UT; uchar num; uchar ge,shi,bai,qian,wan,shiwan,baiwan,qianwan,wanwan; void delay(uchar t) { uchar b; for(t;t>0;t--) for(b=50;b>0;b--); } void write_com_1602(uchar command)//写命令 { lcdrs=0; lcdwr=0; P0=command; delay(2); lcden_1602=1; delay(2); lcden_1602=0; delay(2); lcden_1602=1; } void write_data_1602(uchar in_data)//写数据 { lcdrs=1; lcdwr=0; P0=in_data; delay(2); lcden_1602 = 1; delay(2); lcden_1602 = 0; delay(2); lcden_1602 = 1; } void init_1602()//初始化 { lcden_1602=0; write_com_1602(0x01); //清屏 write_com_1602(0x06); //AC自动加一,画面不移动 write_com_1602(0x0c); //开显示,显示光标,光标闪 write_com_1602(0x38); //8位数据接口,2行显示5×7点阵 } void delay_ms(uchar del_ms)//2ms { uint a; for(del_ms;del_ms>0;del_ms--) { for(a=260;a>0;a--); } } void IIC_start() { SDA=1; delay(1); SCL=1; delay(1); SDA=0; delay(1); SCL=0; } void IIC_end() { SCL=0; delay(1); SDA=0; delay(1); SCL=1; delay(1); SDA=1; delay(1); } void IIC_check_respons() { uchar num_0=250; SCL=0; delay(1); SDA=1; delay(1); SCL=1; delay(1); while((SDA==1)&&(num_0>0))num_0--; SCL=0; } void IIC_receive_respons() { SCL=0; delay(1); SDA=0; delay(1); SCL=1; delay(3); SCL=0; } void write_IIC(uchar iic_data) { uchar a; for(a=0;a<8;a++) { SCL=0; iic_data=iic_data<<1; SDA=CY; delay(1); SCL=1; delay(1); } IIC_check_respons(); } unsigned char read_IIC() { uchar IIC_receive; uchar c; SDA=1; for(c=0;c<8;c++) { SCL=1; delay(1); IIC_receive=IIC_receive<<1; IIC_receive=SDA|IIC_receive; SCL=0; delay(1); } IIC_receive_respons(); return IIC_receive; } short read_EEPROM_BMP085(uchar reg_EEPROM_addr) // { uchar m***,l***; short ut; IIC_start(); //开始 write_IIC(0xee);//085地址写操作 write_IIC(reg_EEPROM_addr); IIC_start(); //重新开始 write_IIC(0xef);// m***=read_IIC(); IIC_receive_respons(); /* IIC_start(); //开始 write_IIC(0xee);//085地址写操作 write_IIC(reg_EEPROM_addr); IIC_start(); //重新开始 write_IIC(0xef);//读操作 */ l***=read_IIC(); IIC_end(); ut=(m***<<8)+l***; return ut; } void init_BMP085() { AC1 = read_EEPROM_BMP085(0xAA); AC2 = read_EEPROM_BMP085(0xAC); AC3 = read_EEPROM_BMP085(0xAE); AC4= read_EEPROM_BMP085(0xB0); AC5= read_EEPROM_BMP085(0xB2); AC6= read_EEPROM_BMP085(0xB4); B1= read_EEPROM_BMP085(0xB6); B2= read_EEPROM_BMP085(0xB8); MB = read_EEPROM_BMP085(0xBA); MC = read_EEPROM_BMP085(0xBC); MD = read_EEPROM_BMP085(0xBE); } /* void write_BMP085(uchar BMP085_data) { write_IIC(BMP085_data); } */ uchar read_BMP085(uchar reg_addr) { uchar value; IIC_start(); write_IIC(0xee);//085地址写操作 write_IIC(reg_addr); IIC_start(); write_IIC(0xef);//读 value = read_IIC(); return value; } void measure(uchar measure_BMP085) { IIC_start(); write_IIC(0xee);//085地址写操作 write_IIC(0xf4);//085固定寄存器地址 ,表示要进行测量。 write_IIC(measure_BMP085);//如(0x2e),温度测量; //寄存器数据,进行温度或者压力测试 IIC_end(); } signed long calculate_temperature() { long t; //temperature,温度 X1=(UT-AC6)*AC5; X1=X1/pow(2,15); X2=(MC*pow(2,11))/(X1+MD) ; B5=(X1+X2); t=(B5+8)/pow(2,4); //真实温度 return t; } void main() { init_1602(); delay_ms(100); //上电延时 init_BMP085();//初始化并读取EEPROM write_com_1602(0x80+15); //命令 write_data_1602('>'); //写数据 //!****如果在此函数中循环代表数据读取出错*****!/ while((AC1==0)||(AC1==0xffff)||(AC2==0)||(AC2==0xffff)||(AC3==0)||(AC3==0xffff)||(AC4==0)||(AC4==0xffff)||(AC5==0)||(AC5==0xffff)||(AC6==0)||(AC6==0xffff)||(B1==0)||(B1==0xffff)||(B2==0)||(B2==0xffff)||(MB==0)||(MB==0xffff)||(MC==0)||(MC==0xffff)||(MD==0)||(MD==0xffff)) { init_BMP085(); } //~*******提示初始化完毕********~// write_com_1602(0x80+0x40); //命令 write_data_1602('T'); //写数据 /*****************************************/ /***************主执行函数****************/ /*****************************************/ while(1) { measure(0x2e); delay_ms(7); MSB=read_BMP085(0xF6);//MSB IIC_receive_respons(); LSB=read_BMP085(0xF7);//MSB IIC_end(); UT = MSB<<8+LSB; T=calculate_temperature(); ge = T%10; shi = T%100/10; bai = T%1000/100; qian= T%10000/1000; wan = T%100000/10000; shiwan= T%1000000/100000; baiwan= T%10000000/1000000; qianwan= T%100000000/10000000; //wanwan = T%1000000000/100000000;//千万位用于测试 //write_com_1602(0x82); //命令 //write_data_1602(qianwan+0x30); //写数据 write_com_1602(0x83); //命令 write_data_1602(wanwan+0x30); //写数据 write_com_1602(0x84); //命令 write_data_1602(baiwan+0x30); //写数据 write_com_1602(0x85); //命令 write_data_1602(shiwan+0x30); //写数据 write_com_1602(0x86); //命令 write_data_1602(wan+0x30); //写数据 write_com_1602(0x87); //命令 write_data_1602(qian+0x30); //写数据 write_com_1602(0x88); //命令 write_data_1602(bai+0x30); //写数据 write_com_1602(0x89); //命令 write_data_1602(shi+0x30); //写数据 write_com_1602(0x90); //命令 write_data_1602(ge+0x30); //写数据 } } |
|
相关推荐
3个回答
|
|
老规矩,抓波形分析
|
|
|
|
|
|
|
|
没时间帮你看。程序太冗长
|
|
|
|
只有小组成员才能发言,加入小组>>
3309 浏览 9 评论
2988 浏览 16 评论
3490 浏览 1 评论
9050 浏览 16 评论
4084 浏览 18 评论
1168浏览 3评论
601浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
592浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2329浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1892浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-19 12:57 , Processed in 1.161874 second(s), Total 87, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号