Wire SDA and SDC to your pic (using 4.7k pullups) and ground A0 and A1 (or change the address in the code). For TMP101, A1 is replaced by ALERT which you can wire to an interrupt pin of the PIC.
When powered up, the TMP100 does automatic sampling. The following line can be sent to configure the sensor to 12bit resolution:
SCLpin VAR PORTB.6 SDApin VAR PORTB.4 TempH VAR Byte TempL VAR Byte I2CWRITE SDApin,SCLpin,$90,$01,[%01100100] 'Set continuous sampling at 12bit resolution I2CREAD SDApin,SCLpin,$90,$00,[TempH,TempL] 'Read temperature sample
SCLpin VAR PORTB.6 SDApin VAR PORTB.4 TempH VAR Byte TempL VAR Byte I2CWRITE SDApin,SCLpin,$90,$01,[%01100101] 'Set 12 bit resolution, turn sensor off SamplingLoop: I2CWRITE SDApin,SCLpin,$90,$01,[%11100101] 'one-shot sample PAUSE 350 I2CREAD SDApin,SCLpin,$90,$00,[TempH,TempL] 'Read temperature sample GOTO SamplingLoop
Temperature is read as a 16 bit value (TempH being MSB and TempL LSB). Here is the conversion routine to display the value on LCD (initialize your LCD first!):
TempSign VAR Byte TempDec VAR Word '******************************************************* 'Convert temperature to LCD '******************************************************* ConvertTemp: IF TempH.7 = 1 THEN TempSign = "-" TempL = TempL ^ %11110000 'bitwise invert on the 4 MSB TempL = TempL + 16 'adding 1 temperature unit TempH = TempH ^ %11111111 'bitwise invert IF TempL = 0 THEN TempH = TempH + 1 ENDIF ELSE TempSign = "+" ENDIF TempDec = 0 IF TempL.7 = 1 THEN TempDec = 5000 IF TempL.6 = 1 THEN TempDec = TempDec + 2500 IF TempL.5 = 1 THEN TempDec = TempDec + 1250 IF TempL.4 = 1 THEN TempDec = TempDec + 625 LCDOUT $FE,1, TempSign, #TempH, ".", #TempDec DIG 3, #TempDec DIG 2, #TempDec DIG 1, #TempDec DIG 0, "°C" RETURN
Re: Voltage regulation circuit 12V to 5V in 5A range
The 2A wall adapter was a quick fix to be able to continue testing.
Demon Today, 00:27The 9V 2A is holding up for now.