#include #include #include <1602.h> #define CLR_DIR_1WIRE DDRC&=~BIT(1) //只要修改这里的参数就可以了!呵呵! #define SET_DIR_1WIRE DDRC|=BIT(1) //里面什么都不用该! #define CLR_OP_1WIRE PORTC&=~BIT(1) #define SET_OP_1WIRE PORTC|=BIT(1) #define CHECK_IP_1WIRE (PINC & 0x02) //检测 unsigned char table[]={'0','1','2','3','4','5','6','7','8','9'}; unsigned char wmh,wmm,wml; unsigned int temp,temp0,temp1,temp2; void init_1820() { SET_DIR_1WIRE; //设置PC2 为输出 SET_OP_1WIRE; CLR_OP_1WIRE; delay_nus(480); //480us以上 SET_OP_1WIRE; CLR_DIR_1WIRE; delay_nus(20); //15~60us while(CHECK_IP_1WIRE); SET_DIR_1WIRE; SET_OP_1WIRE; delay_nus(140); //60~240us } void write_1820(unsigned char x) { unsigned char m; for(m=0;m<8;m++) { CLR_OP_1WIRE; if(x&(1<>4); //整数位 temp2=(temh>>3)&0x1F; //正负温度 wmh=temp1/100; //一百以上输出百位字 wmm=(temp1%100)/10; //出口参数了!wmh是显示的高位,wml使显示的低位 wml=(temp1%100)%10; temp=temp0*625; //小数值 } void main(void) { DDRC=0XFF; PORTC=0X00; DDRA=0XFF; PORTA=0X00; LCD_init(); while (1) { gettemp(); LCD_write_string(0,0,"Now the temp is"); LCD_write_char(1,1,table[wmh]); LCD_write_char(2,1,table[wmm]); LCD_write_char(3,1,table[wml]); LCD_write_char(4,1,'.'); LCD_write_char(5,1,table[temp/1000]); LCD_write_char(6,1,table[(temp%1000)/100]); LCD_write_char(7,1,table[(temp%100)/10]); LCD_write_char(8,1,table[temp%10]); if(temp2)//负温度 { LCD_write_char(0,1,'-'); } if(!temp2)//正温度 { LCD_write_char(0,1,'+'); } } }