Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

programm for displaying temperature on lcd using PIC24F

Status
Not open for further replies.

vinay shabad

Junior Member level 3
Joined
Dec 13, 2010
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,769
hii guys i am very new to PIC microcontroller, i want to read temperature from temperature sensors and display it on lcd.It would be very helpfull if you suggest me how can i proceed it nd if u have any code please help me.
 

do you already have a development board or are you planning to build your own system?
for example, the Microchip Explorer 16
**broken link removed**

has a LCD display and a temperature sensor
 
do you already have a development board or are you planning to build your own system?
for example, the Microchip Explorer 16
**broken link removed**

has a LCD display and a temperature sensor

yes board is ready now i need to writed a programme for it
 

what are the devices (version number) and how are they connected (digital IO pins, SPI, I2C, etc)
 

Hi vinay shabad,

To begin, use LM35 temperature sensor, it's the most common and easy to use temperature sensor.

You can see nice project with LM35 & a PIC here,
12F675 tutorial 4: Making an LM35 temperature recorder.
LM35 with 16F876A;
Welcome to Cytron Technologies - Robot . Head to Toe : PIC Training Malaysia, PIC Microcontroller

---------- Post added at 18:39 ---------- Previous post was at 18:34 ----------

since you new to uC, don't try with PIC24F. First try with 8bit uC which has relatively simpler structure. For PIC most people begin with PIC16F series.
 

i am using PIC24F16KA102 with ADC 10 BITS can you suggest me how can i start code for reading temperature from sensor and display on lcd
 

for a start read section 22.0 of the PIC24F16KA102 manual
https://ww1.microchip.com/downloads/en/DeviceDoc/PIC24F16KA102_Family_datasheet_39927b.pdf

to give you some ideas here is some example code for reading ADC channel 1 on a PIC24FJ256GB110
Code:
    AD1CON1=0;			         // clear config
    AD1CHS = 1;			         // setup ADC channel
    AD1PCFGLbits.PCFG1 = 0;          //Disable digital input on AN1
    AD1CSSL = 0;		                //No scanned inputs
    AD1CON1 = 0x0E4;		        //auto sample start, auto-convert
    AD1CON2 = 0;		                //AVdd, AVss, int every conversion, MUXA only
    AD1CON3 = 0x1F05;		        //31 Tad auto-sample, Tad = 5*Tcy
    AD1CON1bits.ADON=1;		 // switch ON ADC
    while(!AD1CON1bits.DONE);        // Wait for conversion to complete
    int adc=ADC1BUF0;		        // read ADC value
once you can read the temperature you can then look at displying on the LCD

as an alternative you can use functions from the Microchip header file <adc.h>
this is Microchip example code for a PIC24HJ64GP502 on a microstick development board
Code:
#include<adc.h>	//utilize adc peripheral library

void initAdc1(void)
{

	//Using the adc peripheral library, configure ADC1 as follows:
		// 12-bit
		// sample off of AN0
		// Use dedicated ADC RC oscillator
		// Automatically start new conversion after previous
		// Use Avdd and Avss as reference levels

	OpenADC1(
				ADC_MODULE_OFF & ADC_AD12B_12BIT & ADC_FORMAT_INTG & ADC_CLK_AUTO & ADC_AUTO_SAMPLING_ON,
				ADC_VREF_AVDD_AVSS & ADC_SCAN_OFF,
				ADC_SAMPLE_TIME_31 & ADC_CONV_CLK_INTERNAL_RC,
				ADC_DMA_BUF_LOC_1,
				ENABLE_AN0_ANA,
				ENABLE_ALL_DIG_16_31,
				0,
				0);

	AD1CON1bits.ADON = 1;	//Turn on ADC
}

void calc_Vout(void)
{

	//Using a 5Vdd and the ADC in 12-bit mode, gives us a 3.3/4096 = around 806uV/step
	Vout = ReadADC1(0)*0.0008056640625;

}
 
Last edited:


this code is for the Explorer 16 with a PIC24FJ256GB110
Code:
// LCD display ports etc
#define LCDdata LATE					// data port
#define LCDdataEnable	TRISE
#define RS LATBbits.LATB15				// RS bit in LCDstatus
#define RW LATDbits.LATD5				// read/write bit in LCDstatus
#define E  LATDbits.LATD4   			// enable bit in LCDstatus
#define Eenable TRISDbits.TRISD4
#define ERSenable TRISDbits.TRISD5
#define RWenable TRISBbits.TRISB15

void lcd_delay() { mSecDelay(2); }  // if LCD does not work make this longer

// Write a nibble to the LCD
// may have to adjust delays to suit the processor and clock
void lcdNibble(int n)
{
    int lcd=LCDdata;
	lcd_delay();
    LCDdata=n;
	lcd_delay();
    E=1;					// take clock E high 
	lcd_delay();
    E=0;
	lcd_delay();
 }

// Write a Control Command to the LCD
// This is written as two nibbles
void lcdCmd(int c)
{
 	RS=0;			        // Take RS pin low for command
	lcdNibble(c);			        // Makeup Lower Nibble
}

// write a data byte to LCD
int lcdPutchar(int d)
{
//    printf("%c", d);
	RS=1; 				// Take RS pin high for data
	lcdNibble(d);		            // Makeup Lower Nibble
    return 1;
}

// Initialise the LCD in 4bit Mode
void lcdInit()
{
	E=0;				// take E low
 	RS=0;				// Take RS pin low for command
 	RW=0;				// Take RS pin low for command
    // set RS, RW and E bits as output
	Eenable =0;
	ERSenable =0;
	RWenable =0;
    LCDdataEnable &= 0x0;          // set bits 0-3 output for data
	lcdNibble(0x3);		// This put the LCD into Soft Reset 
	lcdNibble(0x3);
	lcdNibble(0x3);
	lcdNibble(0x2);
	lcd_delay();
//	lcdCmd(0x28);			// 2 line, 4 bit mode 
	lcdCmd(0x38);			// 2 line, 8 bit mode 
	lcd_delay();
    lcdCmd(0x6);			// increment cursor after each write
	lcd_delay();
    lcdCmd(0x1);			// clear display
	lcd_delay();
    lcdCmd(0x2);			// home
	lcd_delay();
    lcdCmd(0xF);			// turn disply on
	lcd_delay();
}
should work with other PIC24 but you may have to change the delays
 
  • Like
Reactions: etf988

    etf988

    Points: 2
    Helpful Answer Positive Rating
    V

    Points: 2
    Helpful Answer Positive Rating
thanks a lot... but actually, i need this done in Simulink, using block diagram.. so I am not sure that this is helpfull in my situation..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top