PDA

View Full Version : Sensor temperature MCP9800-1-2-3



steneor
- 14th August 2006, 18:25
Hi!

I'm using PIC BASIC with a PIC18F4680. I'm wondering whether there's anyone who could tell me how to connect MCP9800 to the PIC and get the PIC to display the temperatue on a serial or LCD.

Thanks!

Ernesto

mister_e
- 14th August 2006, 18:31
MCP9800 connection? =>PBP I2CWRITE section

Serial lcd: HSEROUT, SEROUT, SEROUT2, DEBUG

steneor
- 15th August 2006, 08:06
Hi!
This is my first solution.


'************************************************* ***************
'* Name : MCP9803.BAS *
'* Author : Ernesto *
'* Notice : test MCP9803 with pic18f2680 *
'* : *
'* Date : 30/07/2006 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
define LOADER_USED 1 ' utilisation du Bootloader Tinybld 1.91
define OSC 40 ' Quartz à 10MHz * 4
DEFINE HSER_BAUD 19200 ' set baud rate to 19200


FLOAT VAR WORD '

SDA var PORTC.4
SCL var PORTC.3

T_MSB var byte 'Température MSB Signe + 7 Bit
T_LSB var byte 'Temperature lsb decimal

;MCP9800 DATASHEET
adr_R con %10010001 ;adr mpc9803 read
adr_W CON %10010000 ;adr mpc9803 write
MCP9800_TEMPERATURE CON 0 ; Register pointer
MCP9800_CONFIGURATION CON 1
MCP9800_HYSTERESIS CON 2
MCP9800_LIMITSET CON 3

ONESHOT_OFF CON %00000000 ;bit for register configuration
ONESHOT_ON CON %10000000
RESOLUTION_9bit CON %00000000
RESOLUTION_10bit CON %00100000
RESOLUTION_11bit CON %01000000
RESOLUTION_12bit CON %01100000
FAULT_QUEUE_0 CON %00000000
FAULT_QUEUE_2 CON %00001000
FAULT_QUEUE_4 CON %00010000
FAULT_QUEUE_6 CON %00011000
ALERT_ACTIVE_LOW CON %00000000
ALERT_ACTIVE_HIGH CON %00000100
COMP_MODE CON %00000000
INT_MODE CON %00000010
SHUTDOWN_OFF CON %00000000
SHUTDOWN_ON CON %00000001

MCP9800_CONFIG con oneshot_off | Resolution_11bit |Fault_queue_0 | ALERT_active_low | Comp_mode | shutdown_off


debut:

hserout [$D,$A]
hserout ["*************************************************",$D,$A]
hserout ["* Test du capteur de température MCP9803 *",$D,$A]
hserout ["*************************************************",$D,$A]
hserout [$D,$A]



init_MCP9800:
i2cwrite SDA,SCL,adr_W,[mcp9800_configuration,mcp9800_config]
i2cwrite SDA,SCL,adr_W,[mcp9800_temperature]

loop:
i2cread SDA,SCL,adr_R,[T_msb,T_lsb]

;float = (T_lsb >>7 ) * 5 ; resolution 9 bit
;float = (T_lsb >>6 ) * 25 ; resolution 10 bit
float = (T_lsb >>5 ) * 125 ; resolution 11 bit

hserout ["T_msb=",BIN8 T_msb," T_lsb=",BIN8 T_lsb, " Température =",SDEC T_msb,",",dec float,"C" ,$D,$A]
pause 200

goto loop

END

ius01
- 4th September 2006, 07:11
Not bad, I tried this one and it worked, had problems with the LCD grounding but the code was good, this code is also suitable for many other temp sensors.

mazlan
- 21st September 2007, 16:27
It's possible to pull the i2c bus and put the mcp9803 temp sensor far away from controller ?(Around 2 meters by using shielded cable)

Thanks.

Omalik
- 15th June 2008, 21:17
Hello *

I connect MCP9801 to the PIC and i put the 3 Adressline to VCC (A0,A1,A2)
So i change onliy the 2 Lines of the Programm above:

adr_R con %10011111 ;adr mpc9803 read Adresse 111
adr_W CON %10011110 ;adr mpc9803 write Adresse 111

I get always 16.0 C on the display.

Thank for feedback.

Rolf

skimask
- 16th June 2008, 01:01
I get always 16.0 C on the display.

The sensor is 16C?