You are currently viewing How to Interface Sensor with dsPIC30F4011 – dsPIC Evaluation Board

How to Interface Sensor with dsPIC30F4011 – dsPIC Evaluation Board

Spread the love

The dsPIC30F4011 Evaluation board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through USB port.

Microchip’s dsPIC30F ( dsPIC30F4011), Evaluation board Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 16-bit Microcontrollers.

Temperature Sensor

DS1820 is a temperature sensor which is small sensor. The output of sensor converted to digital that easy connecting with microcontroller.

Interfacing ds1820

Fig. 1 shows how to interface the ds1820 to microcontroller. As you can see the first pin is connected to GND, the third pin is connected to VCC & the second pin is connected to the Microcontroller. So when the temperature is sensing, it give the sensor reading to controller.

 Interfacing Sensor with dsPIC30F4011
Fig. 1 Interfacing ds1820 to Microcontroller

Interfacing ds1820 with dsPIC30F4011

We now want to read the temperature in dsPIC30F4011 Evaluation board from temperature sensor ds1820. The dsPIC30F4011 Evaluation board uses the ADC pin for reading temperature from temperature sensor ds1820. The reading output is displayed into PC through UART1.

The 10 bit ADC used to read temperature. Basic clocking for the A/D converters is provided by the VPB clock. A programmable divider is included in each converter, to scale this clock to the 4.5 MHz (max) clock needed by the successive approximation process. A fully accurate conversion requires 11 of these clocks.

Pin Assignment with dsPIC30F4011

pin assignment for Interfacing Sensor with dsPIC30F4011

Circuit Diagram to Interface ds1820 with dsPIC30F4011

circuit diagram for Interfacing Sensor with dsPIC30F4011

Source Code

The Interfacing ds1820 with dsPIC30F4011 program is very simple and straight forward, that reading temperature from temperature sensor ds1820 and it display into PC through serial port.

C Program to read temperature using dsPIC30F4011

Title : Program to read temperature

#include "p30f4011.h"
#define XTFREQ 10000000
#define FOSC XTFREQ/4
#define BAUDRATE 9600
#define BRGVAL ((FOSC/BAUDRATE)/16)-1
#define DQ PORTBbits.RB0
#define DQ_DIR TRISBbits.TRISB0 void DelayMs(unsigned char);
void DelayUs(unsigned char);
unsigned char i=0;
float Temerature=0;
void ds1820_init(void);
void Reset(void);
void write(unsigned char);
unsigned char Read(void);
void Serial_init(void);
void main()
unsigned char Temp[9];
//Clear the Hypherterminal;
printf("DS1820 Demo");
DQ_DIR = 1;
// will be raised after finishing conversion Reset();
for(i=0;i<9;i++) Temp[i] = Read();
//Read 9 bytes for(i=0;i<9;i++) printf("%d ",Temp[i]);
void ds1820_init()
DQ = 1;
DQ_DIR = 1;
//pull up
void Reset(void)
DQ_DIR = 0;
DQ = 0;
//500us DQ_DIR = 1;
//40us while(DQ==1);
//wait until presence pulse DelayMs(1);
void write(unsigned char cmd)
DQ_DIR = 0;
//pull down DQ = 0;
//10us DQ = (cmd & 0x01)?1:0;
//Send bit cmd = cmd >> 1;
//>45us DQ_DIR = 1;
unsigned char Read(void)
unsigned char temp=0,RecDat=0;
DQ_DIR = 0;
DQ = 0;
//pull down DelayUs(25);
//10us DQ_DIR = 1;
//release DelayUs(25)
//10us temp = DQ;
//read bit temp = temp<<i;
RecDat |= temp;
return RecDat;
void Serial_init(void)
U1MODE= 0x8000;
U1STA = 0x8400;
IFS0bits.U1TXIF = 0;
void putch(unsigned int SendDat)
void DelayUs(unsigned char x)
while(--x != 0);
void DelayMs(unsigned char cnt)
i = 4;

To compile the above C code you need the MPLAB software & Microchip C30 Compiler. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In Mplab, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without Evaluation board.

The PICKIT2 software is used to download the hex file into your dsPIC30F4011 Evaluation board through USB.

Testing the ds1820 with dsPIC30F4011

Give +9V power supply to dsPIC30F4011 Evaluation board; the serial cable is connected between the controller and PC. Open the Hyper Terminal screen, select which port you are using and set the default settings. Now the screen should show the current temperature readings.

Bring a Hot soldering iron tip near the ds1820’s pins, don’t touch it keep it 1 or 2mm away. The screen should update with the rising temperature. Now finally touch the pins of ds1820 with the tip of iron, the temperature should rise quickly. Keep it there until temperature rise to 80 degrees, and then remove the iron.

General Information

☞For proper working use the components of exact values as shown in Circuit file. Wherever possible use new components.

☞Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.

☞Use the exact value crystal shown in schematic.

☞More instructions are available in following articles,

dSPIC Evaluation Board

How to Interface UART with dsPIC Evaluation Board

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.