// **********ds1620.c // Jonathan W. Valvano 1/15/02 // Interface between MC68HC812 and DS1620 // Copyright 2002 by Jonathan W. Valvano, valvano@uts.cc.utexas.edu // You may use, edit, run or distribute this file // as long as the above copyright notice remains // See Valvano, Embedded Microcomputer Systems, Chap 3 // bit status Configuration/Status Register meaning // 7 DONE 1=Conversion done, 0=conversion in progress // 6 THF 1=temperature above TH, 0=temperature below TH // 5 TLF 1=temperature below TL, 0=temperature above TL // 1 CPU 1=CPU control, 0=stand alone operation // 0 1SHOT 1=one conversion and stop, 0=continuous conversions // temperature digital value (binary) digital value (hex) // +125.0 C 011111010 $0FA // +64.0 C 010000000 $080 // +1.0 C 000000010 $002 // +0.5 C 000000001 $001 // 0 C 000000000 $000 // -0.5 C 111111111 $1FF // -16.0 C 111100000 $1E0 // -55.0 C 110010010 $192 // DS1620 MC68HC812A4 // 1 DQ PS5 // 2 CLK PS6 // 3 RST PS7 // 4 GND ground // 5 TCOM not connected // 6 TLOW not connected // 7 THIGH not connected // 8 Vcc +5 V with bypass cap to ground void DS1620_Init(void){ // PS7=RST=0 DDRS = 0xE0; // PS6=CLK=1 PORTS = 0x60; // PS5=DQ=1 } void static out8(char code){ int n; for(n=0;n<8;n++){ PORTS &= 0xBF; // PS6=CLK=0 if(code&0x01){ PORTS |= 0x20; // PS5=DQ=1 } else{ PORTS &= 0xDF; // PS5=DQ=0 } PORTS |= 0x40; // PS6=CLK=1 code = code>>1; } } void DS1620_Start(void){ PORTS |= 0x80; // PS7=RST=1 out8(0xEE); PORTS &= 0x7F; // PS7=RST=0 } void DS1620_Stop(void){ PORTS |= 0x80; // PS7=RST=1 out8(0x22); PORTS &= 0x7F; // PS7=RST=0 } void DS1620_WriteConfig(char data){ PORTS |= 0x80; // PS7=RST=1 out8(0x0C); out8(data); PORTS &= 0x7F; // PS7=RST=0 } void static out9(int code){ int n; for(n=0;n<9;n++){ PORTS &= 0xBF; // PS6=CLK=0 if(code&0x01){ PORTS |= 0x20; // PS5=DQ=1 } else{ PORTS &= 0xDF; // PS5=DQ=0 } PORTS |= 0x40; // PS6=CLK=1 code = code>>1; } } void DS1620_WriteTH(int data){ PORTS |= 0x80; // PS7=RST=1 out8(0x01); out9(data); PORTS &= 0x7F; // PS7=RST=0 } void DS1620_WriteTL(int data){ PORTS |= 0x80; // PS7=RST=1 out8(0x02); out9(data); PORTS &= 0x7F; // PS7=RST=0 } unsigned char static in8(void){ int n; unsigned int result=0; DDRS &= 0xDF; // PS5=DQ input for(n=0;n<8;n++){ PORTS &= 0xBF; // PS6=CLK=0 result = result>>1; if(PORTS&0x20){ result |= 0x80; // PS5=DQ=1 } PORTS |= 0x40; // PS6=CLK=1 } DDRS |= 0x20; // PS5=DQ output return result; } unsigned char DS1620_ReadConfig(void){ unsigned char value; PORTS |= 0x80; // PS7=RST=1 out8(0xAC); value = in8(); PORTS &= 0x7F; // PS7=RST=0 return value; } unsigned int static in9(void){ int n; unsigned int result=0; DDRS &= 0xDF; // PS5=DQ input for(n=0;n<9;n++){ PORTS &= 0xBF; // PS6=CLK=0 result = result>>1; if(PORTS&0x20){ result |= 0x0100; // PS5=DQ=1 } PORTS |= 0x40; // PS6=CLK=1 } DDRS |= 0x20; // PS5=DQ output if(result&0x0100){ result |= 0xFE00; } return result; } unsigned int DS1620_ReadTH(void){ unsigned int value; PORTS |= 0x80; // PS7=RST=1 out8(0xA1); value = in9(); PORTS &= 0x7F; // PS7=RST=0 return value; } unsigned int DS1620_ReadTL(void){ unsigned int value; PORTS |= 0x80; // PS7=RST=1 out8(0xA2); value = in9(); PORTS &= 0x7F; // PS7=RST=0 return value; } unsigned int DS1620_ReadT(void){ unsigned int value; PORTS |= 0x80; // PS7=RST=1 out8(0xAA); value = in9(); PORTS &= 0x7F; // PS7=RST=0 return value; }