覺得不錯贊一個
0.png (57.03 KB, 下載次數: 57)
下載附件
2017-6-7 02:39 上傳
單片機源程序如下:
- #include<reg52.h>
- #include<12864.h>
- #include<1302.h>
- #include <DS18B20.h>
- #include <CSB.h>
- unsigned char table1[]=" ";
- unsigned char table2[]=" ";
- unsigned char table3[]="室內溫度:";
- unsigned char table4[]="測距:";
- unsigned char time_buf[8]={40,14,2,16,23,59,50,7};//空年月日時分秒周
- unsigned char time_buf1[8];
- unsigned char num, bai,shi,ge,i;
- unsigned int temp1;
-
- long int distance=0;
- unsigned char count;
- void init_parameter(void)//初始化
- {
- echo=0;
- trig=0;
- count=0;
- distance=0;
- }
- void measure_distance(void)//計算距離
- {
- uchar I;
- uint h,y;
- TR0=1;
- while(echo)
- {
- ;
- }
- TR0=0;
- I=TL0;
- h=TH0;
- y=(h<<8)+I;
- y=y-0xfc66;
- distance=y+1000*count;
- TL0=0X66;
- TH0=0XFC;
-
- distance=0.17*distance;
- }
- void display(long int num)
- {
- unsigned int qian,bai,shi,ge;
- if((num>5000)||(num==0))
- {
- qian=15;
- bai=15;
- shi=10;
- ge=15;
- }
- else
- {
- qian=num/1000;
- bai=(num/100)%10;
- shi=(num/10)%10;
- ge=num%10;
- LCD_Write_String(4,1,table4);
- write_data(qian+0x30);
- write_data(bai+0x30);
- write_data(shi+0x30);
- write_data('.');
- write_data(ge+0x30);
- write_data('C');
- write_data('M');
- }
- }
- void disp(void)
- {
- table1[3]='2';
- table1[4]='0';
- table1[5]='0'+time_buf1[1]/10;//顯示年月日
- table1[6]='0'+time_buf1[1]%10;
- table1[7]='-';
- table1[8]='0'+time_buf1[2]/10;
- table1[9]='0'+time_buf1[2]%10;
- table1[10]='-';
- table1[11]='0'+time_buf1[3]/10;
- table1[12]='0'+time_buf1[3]%10;
- LCD_Write_String(1,1,table1);
-
- table2[0]='0'+time_buf1[4]/10;//顯示時分秒
- table2[1]='0'+time_buf1[4]%10;
- table2[2]='-';
- table2[3]='0'+time_buf1[5]/10;
- table2[4]='0'+time_buf1[5]%10;
- table2[5]='-';
- table2[6]='0'+time_buf1[6]/10;
- table2[7]='0'+time_buf1[6]%10;
- table2[11]='w';
- table2[12]='e';
- table2[13]='e';
- table2[14]='k';
- table2[15]='0'+time_buf1[7]%10;
- LCD_Write_String(2,1,table2);
- }
-
- void main(void)
- {
- P0=0X00;
- dula=0;
- wela=0;
-
- lcdinit();
- init_parameter();
- init_timer();
- delayms(15);
- ds1302_init();
- ds1302_write_time();
-
- while(1)
- {
- ds1302_read_time();
- disp();
-
- temp1=tmp();
- bai=temp1/100;
- shi=temp1%100/10;
- ge=temp1%10;
- LCD_Write_String(3,1,table3);
- write_data('+');
- write_data(bai+0x30);
- write_data(shi+0x30);
- write_data('.');
- write_data(ge+0x30);
- write_data('C');
- tmpchange();
-
- trig_supersonic();
- while(echo==0)
- {
- ;
- }
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
綜合程序.zip
(60.95 KB, 下載次數: 38)
2017-6-6 19:14 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|