基于51单片机的DS1302+LCD12864+DS18B20小综合 下载本文

delay_us(4); }

return temp; }

uchar DS18B20_Init(void) {

uchar init_18B20_flag; DQ=1;

delay_us(8); DQ=0;

delay_us(80); DQ=1;

delay_us(10); init_18B20_flag=DQ; delay_us(5);

//while(init_fail);

return init_18B20_flag; }

uint read_temperature(void) {

uchar a; uint b,t;

DS18B20_Init();

DS18B20_write_byte(0xcc); DS18B20_write_byte(0x44); delay_us(200);

DS18B20_Init();

DS18B20_write_byte(0xcc); DS18B20_write_byte(0xBE);

a=DS18B20_read_byte(); b=DS18B20_read_byte();

b<<=8; t=a+b; return t; }

void write_temp(uchar temp_h) {

uchar i;

write_symbol(sbl_addr_pos,symbol);

write_command(third_line+Tep_addr_pos); delay_ms(5);

write_data(0x30+temp_h/10); delay_ms(5);

write_data(0x30+temp_h); delay_ms(5);

write_command(third_line+Tmp_addr_pos); delay_ms(5);

for(i=14;i<16;i++){

write_data(str_wek[i]); } }

void write_symbol(uchar addr,uchar symbol) {

write_command(third_line+addr); delay_ms(5);

write_data(symbol); }

void display_18B20_err(void) {

uchar i;

uchar str[]=\错误\

write_command(third_line+sbl_addr_pos); for(i=0;i<6;i++){

write_data(str[i]); delay_ms(5); } }