《温湿度采集控制电路及C51程序复习进程.ppt》由会员分享,可在线阅读,更多相关《温湿度采集控制电路及C51程序复习进程.ppt(74页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、温湿度采集控制电路及C51程序23456三、集中显示电路控制温湿度采集控制电路1、键盘和数码管显示72792、单片机主控控制电路3、485通信7891011一、温度湿度采集控制电路程序main.c主程序,含继电器控制rs232.c(rs232.h)485通信程序ds18b20.c(ds18b20.h)温度湿度采集程序第二节 器件介绍和C51编程12#include void relay_control(void);extern void delay(unsigned char);extern void read_tmp(void);extern void read_tmp_1(void);ex
2、tern void read_tmp_2(void);extern void read_tmp_3(void);sbit r_control=P35;sbit led=P33;sbit ptt=P14;void rev_ptt(void);void send_ptt(void);extern unsigned char datamain.c13extern unsigned char data senddata16;extern unsigned char data revdata8;extern unsigned char data*psenddata;extern unsigned cha
3、r data*prevdata;extern unsigned char data tmp_l4;extern unsigned char data tmp_h4;unsigned char code me_address=0 x81;unsigned char code temp_table_l21=33,31,30,28,28,28,28,25,25,25,25,25,25,25,21,21,21,21,21,21,21;unsigned char code temp_table_h21=35,33,32,30,30,30,30,28,28,28,28,28,28,28,27,27,27,
4、27,27,27,27;unsigned char data temp_time=20;unsigned int tmp_v;unsigned int test_time=0;extern bit rev_ok;14main()ptt=0;TMOD=0 x20;TL1=0 xf4;TH1=0 xf4;SCON=0 x50;PCON=0 x00;TR1=1;ES=1;EA=1;led=0;prevdata=revdata;psenddata=senddata;15 while(1)read_tmp();read_tmp_1();read_tmp_2();read_tmp_3();senddata
5、4=(me_address&0 x0f);senddata5=tmp_h0;senddata6=tmp_l0;senddata7=tmp_h1;senddata8=tmp_l1;senddata9=tmp_h2;senddata10=tmp_l2;senddata11=tmp_h3;senddata12=tmp_l3;16 relay_control();if(!r_control)senddata13=0 xaa;else senddata13=0 x00;if(rev_ok)rev_ok=0;delay(1);ptt=1;delay(1);TI=1;17void relay_control
6、(void)tmp_v=(tmp_h0&0 x03)*16+(tmp_l0*.0625)+0.5);if(tmp_v=(temp_table_htemp_time-1)r_control=1;return;18二、集中显示电路控制程序main.c主程序rs232.c(rs232.h)485通信程序7279.C(7279.h)键盘程序ds1302.c(ds1302.h)时钟程序24c64.c (24c64.h)EEROM程序utility.htemp.h19#include#include#include#include main(void)main_init();I_init();ttt2=e
7、_read_block();/ttt1=e_write_block();if(eromimager0=0 xff)senddata5=20;else store_true=1;senddata5=eromimager7;delay(20);main.c20 while(1)v_get1302();time_precess();if(cur_minute!=curtime1)if(number1!=0)|(number2!=0)|(key_press1!=0)key_numcancel();f2_precess();delay(20);f3_precess();delay(20);f4_prec
8、ess();delay(9000);21void main_init(void)hd7279_rst=0;delay(1500);hd7279_rst=1;led=0;psenddata=senddata;prevdata=revdata;send_byte(cmd_reset);pctime=settime;/v_set1302(pctime);TMOD=0 x20;TL1=0 xf4;TH1=0 xf4;SCON=0 x50;PCON=0 x00;PS=1;EX0=1;TR1=1;ES=1;EA=1;ptt=1;TI=1;key_press=0;v_setcharge();v_get130
9、2();cur_second=curtime0;cur_minute=curtime1;cur_hour=curtime2;cur_date=curtime3;cur_month=curtime4;cur_year=curtime7;delay(10000);key_press3=1;22unsigned char h_compute(unsigned char n_w_h,unsigned char n_w_l,unsigned char w_h,unsigned char w_l)unsigned int t1,t2;unsigned char sub_val,temp_val;t1=(i
10、nt)(n_w_h*16+n_w_l*.0625)+0.5)*10);t2=(int)(w_h*16+w_l*0.0625)+0.5)*10);sub_val=(unsigned char)(t1-t2)/5+0.5);temp_val=(unsigned char)(t1/10);if(sub_val!=0)return(t_htemp_val-1sub_val-1);else return(0);23三、HD7279A器件介绍及C51编程24252627282930313233343536/pin definesbit cs=P15;sbit clk=P16;sbit dat=P17;sb
11、it key=P32;void send_byte(unsigned char out_byte)unsigned char i;cs=0;long_delay();for(i=0;i8;i+)if(out_byte&0 x80)dat=1;elsedat=0;clk=1;short_delay();clk=0;short_delay();out_byte=out_byte*2;dat=0;unsigned char receive_byte(void)unsigned char i,in_byte;dat=1;long_delay();for(i=0;i8;i+)clk=1;short_de
12、lay();in_byte=in_byte*2;if(dat)in_byte=in_byte|0 x01;clk=0;short_delay();dat=0;return(in_byte);37void write7279(unsigned char cmd,unsigned char dta)send_byte(cmd);send_byte(dta);unsigned char read7279(unsigned char command)send_byte(command);return(receive_byte();void long_delay(void)unsigned char i
13、;for(i=0;i0 x10;i+);void short_delay(void)unsigned char i;for(i=0;i4;i+);38void display_uh_tmp(unsigned char s,unsigned char r)int a,b,c;unsigned char s1;c=(int)(s*16+r*0.0625+0.5)*10);a=(int)(c/100);b=(int)(c-a*100)/10);s1=c-a*100-b*10;b=b|0 x80;write7279(0 x88,0 xff);write7279(0 xcc,0 x0c);write72
14、79(0 x87,s1);write7279(0 x86,b);write7279(0 x85,a);39void display_d_tmp(unsigned char s,unsigned char r)int a,b,c;unsigned char s1;c=(s*16+r*0.0625+0.5)*10;a=(int)(c/100);b=(int)(c-a*100)/10);s1=c-a*100-b*10;b=b|0 x80;write7279(0 xc8,0 x0b);write7279(0 x83,s1);write7279(0 x82,b);write7279(0 x81,a);4
15、0void service_int0(void)interrupt 0 /键盘中断 readkey_board();41void readkey_board(void)/按键程序 unsigned char key_r_number;if(!key)key_r_number=read7279(cmd_read);while(!key);cur_minute=curtime1;switch(key_r_number)case 6:/f1 key_f1();break;case 38:/f2 key_f2();break;case 7:/f3 key_f3();break;case 39:/f4
16、key_f4();break;case 14:/1 key_num0_9(1);break;case 22:/2 key_num0_9(2);break;case 30:/3 key_num0_9(3);break;case 46:/4 key_num0_9(4);break;case 54:/5 key_num0_9(5);break;case 62:/6 key_num0_9(6);break;case 15:/7 key_num0_9(7);break;case 23:/8 key_num0_9(8);break;case 31:/9 key_num0_9(9);break;case 5
17、5:/0 key_num0_9(1);break;case 63:/ok key_numok();break;case 47:/cancel key_numcancel();break case 255:break;default:break;return;42四、18b20及C51编程434445464748495051ds18b20.c#include#include#include void delay(unsigned char time)unsigned char s;for(s=0;stime;s+);52/first 18b20void write_bit(unsigned ch
18、ar bitval)EA=0;DQ=0;_nop_();_nop_();if(bitval=1)DQ=1;EA=1;delay(5);DQ=1;53unsigned char ow_reset(void)unsigned char presence;DQ=0;delay(120);DQ=1;delay(10);presence=DQ;delay(20);return(presence);54unsigned char read_byte(void)unsigned char i;unsigned char ii=0;unsigned char value=0;for(i=0;i8;i+)if(
19、read_bit()ii=0 x01i;value|=ii;delay(5);return(value);55bit read_bit(void)bit dat;EA=0;DQ=0;_nop_();_nop_();_nop_();DQ=1;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();dat=DQ;EA=1;delay(5);return(dat);56void write_byte(unsigned char val)unsigned char i;unsigned char temp;for(i=0;ii;temp&=0 x
20、01;write_bit(temp);57void read_tmp(void)/unsigned int a,b;temp=ow_reset();write_byte(0 xcc);write_byte(0 x44);delay(20);temp=ow_reset();write_byte(0 xcc);write_byte(0 xbe);delay(20);tmp_l0=read_byte();tmp_h0=read_byte();58#include/function definevoid delay(unsigned char);/first 18b20void write_bit(u
21、nsigned char);unsigned char ow_reset(void);unsigned char read_byte(void);bit read_bit(void);void write_byte(unsigned char);void read_tmp(void);sbit DQ=P10;ds18b20.h59unsigned char data tmp_l4;unsigned char data tmp_h4;unsigned char data temp;unsigned char data tmp=0;unsigned char data z8;sbit led=P3
22、3;sbit z1=P15;60第三节 12864M介绍和GAL逻辑了解12864M液晶;理解单片机总线时序及12864M液晶接口时序学会使用GAL 进行接口逻辑的编程及应用61module wstitle ADDRESS ENCODEdesigner:YXM VER 1.00 2003,9,01 ws device P22V10;ALE,WR,RD,A8,A9,A10,A11,A12,A13,A14,A15 pin 1,2,3,4,5,6,7,8,9,10,11;EOC,CSRAM,CS0,CS1,CS2,CS3,CS4,CS5,ADALE,ADOE,INT0 pin 13,14,15,16
23、,17,18,19,20,21,22,23;equations CSRAM=A15;CS0=WR#A14#A13#A12#!A15;CS1=WR#A14#A13#!A12#!A15;CS2=WR#A14#!A13#A12#!A15;CS3=WR#A14#!A13#!A12#!A15;CS4=RD#!A14#A13#A12#!A15;CS5=RD#!A14#A13#!A12#!A15;ADALE=!WR&A14&A13&!A12&A15;ADOE=!RD&A14&A13&A12&A15;INT0=!EOC;end ws62636465液晶显示模块概述液晶显示模块概述12864M汉字图形点阵液晶显
24、示模块,可显示汉字及图形,内置8192个中文汉字(16X16点阵)、128个字符(8X16点阵)及64X256点阵显示RAM(GDRAM)。主要技术参数和显示特性:电源:VDD 3.3V+5V(内置升压电路,无需负压);显示内容:128列 64行显示颜色:黄绿显示角度:6:00钟直视LCD类型:STN与MCU接口:8位或4位并行/3位串行配置LED背光多种软件功能:光标显示、画面移位、自定义字符、睡眠模式等 66引脚号引脚名称方向功能说明1VSS-模块的电源地2VDD-模块的电源正端3V0-LCD驱动电压输入端4RS(CS)H/L并行的指令并行的指令/数据选择信号;串行的片选信号数据选择信号;
25、串行的片选信号5R/W(SID)H/L并行的读写选择信号;串行的数据口并行的读写选择信号;串行的数据口6E(CLK)H/L并行的使能信号;串行的同步时钟并行的使能信号;串行的同步时钟7DB0H/L数据08DB1H/L数据19DB2H/L数据210DB3H/L数据311DB4H/L数据412DB5H/L数据513DB6H/L数据614DB7H/L数据715PSBH/L并/串行接口选择:H-并行;L-串行16NC空脚17/RETH/L复位 低电平有效18NC空脚19LED_A(LED+5V)背光源正极20LED_K(LED-OV)背光源负极6712864M写6812864M读697071modul
26、e decodertitle ADDRESS ENCODEdesigner:Litao VER 1.12 2006,8,23decoder device P22V10;ALE,WR,RD,A15,A14,A13,A12,A11,A10,A9,A8PIN 1,2,3,4,5,6,7,8,9,10,11;DCS,DRW,CS1,CS2,CS3,DACS,EA,RS,PSB,RWPIN 14,15,16,17,18,19,20,21,22,23;equations EA=(WR$RD)&A15&!A14&!A13&!A12&!A11&!A10;RS=A15&!A14&!A13&!A12&!A11&!
27、A10&A9;RW=A15&!A14&!A13&!A12&!A11&!A10&A8;PSB=1;end decoder液晶写命令 0 x8000液晶读命令 0 x8100液晶写数据 0 x8200液晶读数据 0 x83007212864时序原理图GAL管脚ABEL程序RSD/I(L/H)v2(21)RSR/WR/W(H/L)v4(23)RWEEEA(20)EAWR$RD当为写时,为WR的反;当为读时,为RD的反。这样EA在对和写的时候都有效,(A15&!A14&!A13&!A12&!A11&!A10)其地址范围为80XX83XXRS=A15&!A14&!A13&!A12&!A11&!A10&A9为高时地址为82XX或83XX,即数据,80XX或81XX为命令RW=A15&!A14&!A13&!A12&!A11&!A10&A8为高时地址为81XX或83XX,即读操作,80XX或82XX为写操作写命令 0 x80 xx;读命令 0 x81xx;写数据 0 x82xx;读数据 0 x83xx73此课件下载可自行编辑修改,仅供参考!此课件下载可自行编辑修改,仅供参考!感谢您的支持,我们努力做得更好!谢谢感谢您的支持,我们努力做得更好!谢谢