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.

Temperature Sensing Using Thermocouple, PIC microcontroller and LCD

Status
Not open for further replies.
okay so guys, I tried the following code under the assumption that using the lcd should be relatively the same between the microcontrollers. I just changed the first P1 to PORTC which is the identifier for the pic microcontroller. I also used the port assumptions of connecting PORT C bits 0-3 to data bits 4-7 and the enable and rs bits as according to hussain. However, I still got the same result of all black boxes, no words. Is this not correct for the pic? I will also post another code that I tried, with the same result

// 4 bit example

#include<htc.h>

#define LCD PORTC //port 1
#define LCD_EN 0x80
#define LCD_RS 0x20

//LCD Commands

#define LCD_SETMODE 0x04
#define LCD_SETVISIBLE 0x08
#define LCD_SETFUNCTION 0x28
#define LCD_SETDDADDR 0x80

void delayms(unsigned char);
void delayus(unsigned char);
void lcd_init();
void lcd_reset();
void lcd_cmd (char);
void lcd_data(unsigned char);
void lcd_str (unsigned char*);


void main (void)
{
lcd_init();
lcd_cmd(0x80); // ist line address
lcd_str(" i love ");
lcd_cmd(0xC0); // 2nd line address
lcd_str("romel");
while(1);
}

void delayus(unsigned char delay){
while(delay--);
}

void delayms(unsigned char delay){
while(delay--)
delayus(149);
}

void lcd_reset() //reset LCD
{
LCD = 0xFF;
delayms(40);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(40);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(5);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(5);
LCD = 0x02+LCD_EN;
LCD = 0x02;
delayms(5);
}


void lcd_init () //initialize LCD
{
lcd_reset();
lcd_cmd(LCD_SETFUNCTION); // 4-bit mode - 1 line - 5x7 font.
lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor - no blink.
lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment - No Display shift.
lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h.
}

void lcd_cmd (char cmd)
{
LCD = ((cmd >> 4) & 0x0F)|LCD_EN;
LCD = ((cmd >> 4) & 0x0F);

LCD = (cmd & 0x0F)|LCD_EN;
LCD = (cmd & 0x0F);

delayus(250);
delayus(250);
}

void lcd_data (unsigned char dat)
{
LCD = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
LCD = (((dat >> 4) & 0x0F)|LCD_RS);

LCD = ((dat & 0x0F)|LCD_EN|LCD_RS);
LCD = ((dat & 0x0F)|LCD_RS);

delayus(250);
delayus(250);
}

void lcd_str (unsigned char *str) //display string to LCD
{
while(*str){
lcd_data(*str++);
}
}

---------- Post added at 22:26 ---------- Previous post was at 22:22 ----------

This is the other code that I tried. First listed is my lcd.c and lcd.h files. Then listed is the main file. I tried this code and received the same result, all black boxes no changes. However, I was able to read 5 volts at each of the outputs. This also happened with the other code. Let me know if there's anything or if it is possible just an lcd problem or something.

lcd.c file (sample from hi-tech c) I just commented out the analog pin disable since I am using pic16f887 and this code is not necessary. I also tried both initializing with 0x3 and 0x2

/*
* LCD interface example
* Uses routines from delay.c
* This code will interface to a standard LCD controller
* like the Hitachi HD44780. It uses it in 4 bit mode, with
* the hardware connected as follows (the standard 14 pin
* LCD connector is used):
*
* PORTD bits 0-3 are connected to the LCD data bits 4-7 (high nibble)
* PORTA bit 3 is connected to the LCD RS input (register select)
* PORTA bit 1 is connected to the LCD EN bit (enable)
*
* To use these routines, set up the port I/O (TRISA, TRISD) then
* call lcd_init(), then other routines as required.
*
*/

#ifndef _XTAL_FREQ
// Unless specified elsewhere, 4MHz system frequency is assumed
#define _XTAL_FREQ 4000000
#endif


#include <htc.h>
#include "lcd.h"

#define LCD_RS RA3
#define LCD_RW RA2
#define LCD_EN RA1

#define LCD_DATA PORTD

#define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))

/* write a byte to the LCD in 4 bit mode */

void
lcd_write(unsigned char c)
{
__delay_us(40);
LCD_DATA = ( ( c >> 4 ) & 0x0F );
LCD_STROBE();
LCD_DATA = ( c & 0x0F );
LCD_STROBE();
}

/*
* Clear and home the LCD
*/

void
lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
__delay_ms(2);
}

/* write a string of chars to the LCD */

void
lcd_puts(const char * s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}

/* write one character to the LCD */

void
lcd_putch(char c)
{
LCD_RS = 1; // write characters
lcd_write( c );
}


/*
* Go to the specified position
*/

void
lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos);
}

/* initialise the LCD - put into 4 bit mode */
void
lcd_init()
{
char init_value;

//ADCON1 = 0x06; // Disable analog pins on PORTA

init_value = 0x3;
TRISA=0;
TRISD=0;
LCD_RS = 0;
LCD_EN = 0;
LCD_RW = 0;

__delay_ms(15); // wait 15mSec after power applied,
LCD_DATA = init_value;
LCD_STROBE();
__delay_ms(5);
LCD_STROBE();
__delay_us(200);
LCD_STROBE();
__delay_us(200);
LCD_DATA = 2; // Four bit mode
LCD_STROBE();

lcd_write(0x28); // Set interface length
lcd_write(0xF); // Display On, Cursor On, Cursor Blink
lcd_clear(); // Clear screen
lcd_write(0x6); // Set entry Mode
}

lcd.h


/*
* LCD interface header file
* See lcd.c for more info
*/

/* write a byte to the LCD in 4 bit mode */

extern void lcd_write(unsigned char);

/* Clear and home the LCD */

extern void lcd_clear(void);

/* write a string of characters to the LCD */

extern void lcd_puts(const char * s);

/* Go to the specified position */

extern void lcd_goto(unsigned char pos);

/* intialize the LCD - call before anything else */

extern void lcd_init(void);

extern void lcd_putch(char);

/* Set the cursor position */

#define lcd_cursor(x) lcd_write(((x)&0x7F)|0x80)

main


#include <htc.h>
#include "lcd.h"

void
main(void)
{
lcd_init();
lcd_goto(0); // select first line
lcd_puts("12345678");
lcd_goto(0x40); // Select second line
lcd_puts("Hello world");

for(;;);
}
 

#include<htc.h>

#define LCD PORTC //port 1
#define LCD_EN 0x80
#define LCD_RS 0x20

//LCD Commands

#define LCD_SETMODE 0x04
#define LCD_SETVISIBLE 0x08
#define LCD_SETFUNCTION 0x28
#define LCD_SETDDADDR 0x80

void delayms(unsigned char);
void delayus(unsigned char);
void lcd_init();
void lcd_reset();
void lcd_cmd (char);
void lcd_data(unsigned char);
void lcd_str (unsigned char*);


void main (void)
{
lcd_init();
lcd_cmd(0x80); // ist line address
lcd_str(" i love ");
lcd_cmd(0xC0); // 2nd line address
lcd_str("romel");
while(1);
}

void delayus(unsigned char delay){
while(delay--);
}

void delayms(unsigned char delay){
while(delay--)
delayus(149);
}

void lcd_reset() //reset LCD
{
LCD = 0xFF;
delayms(40);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(40);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(5);
LCD = 0x03+LCD_EN;
LCD = 0x03;
delayms(5);
LCD = 0x02+LCD_EN;
LCD = 0x02;
delayms(5);
}


void lcd_init () //initialize LCD
{
lcd_reset();
lcd_cmd(LCD_SETFUNCTION); // 4-bit mode - 1 line - 5x7 font.
lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor - no blink.
lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment - No Display shift.
lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h.
}

void lcd_cmd (char cmd)
{
LCD = ((cmd >> 4) & 0x0F)|LCD_EN;
LCD = ((cmd >> 4) & 0x0F);

LCD = (cmd & 0x0F)|LCD_EN;
LCD = (cmd & 0x0F);

delayus(250);
delayus(250);
}

void lcd_data (unsigned char dat)
{
LCD = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
LCD = (((dat >> 4) & 0x0F)|LCD_RS);

LCD = ((dat & 0x0F)|LCD_EN|LCD_RS);
LCD = ((dat & 0x0F)|LCD_RS);

delayus(250);
delayus(250);
}

void lcd_str (unsigned char *str) //display string to LCD
{
while(*str){
lcd_data(*str++);
}
}

int the above code you are doing LCD reset first then LCD initialize and in lcd reset you are sending 0x03.....
you should first call lcd initialize first as romel_emperado did in his code.....
 

What do you mean? I did not change the order in code. It appears to be in correct order as far as calling goes. Can you clarify?
 

oh sorry it mixed up with your previous code....
ok try this

void lcd_reset() //reset LCD
{
LCD = 0x02+LCD_EN;
LCD = 0x02;
delayms(5);
}

void lcd_init () //initialize LCD
{
lcd_reset();
lcd_cmd(LCD_SETFUNCTION); // 4-bit mode - 1 line - 5x7 font.
lcd_cmd(0x01);
lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor - no blink.
lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment - No Display shift.
lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h.
}
tell me if this works....
 

One question:

Would the port connections remain the same? I will be connecting PORT c bits 0-3 to databits 4-7 and the enable and rs bits according to what you previously posted.
 

Yeah, actually I tried it on proteus and I cannot get the microcontroller pic16f887 to simulate correctly. However, the microcontroller pic16f877 works on the simulator. I will try and obtain that microcontroller and give it a go with that.
 

dear friends:
A Thermocouple use to differnt metal for sensore . It is important to use special wire to connect thermocuple to your board.
I you use Copper wire ,you add another sensore!!!

copper-metal1-matal2-copper
 

I think, swapnilnagare's idea is worth a try. It's the RV1 pot in the schematic.
 

I haven't checked the post in a while. At any rate, it appears to me that the problem is strictly hardware since the proteus simulation works perfectly. I will be getting a demo board and trying that since most of the connections are readily available with those.
 

hi friends...

can any1 here help me to design a temperature control system using thermocouple,LCD with PIC....??

Proteous design also help lot.
 

hello,

hi friends...

can any1 here help me to design a temperature control system using thermocouple,LCD with PIC....??

At first you need to build level adapter
Thermocouple deliver somme µV / °C so you need tto use an amplifier before the PIC ADC
example: Monolithic Thermocouple Amplifiers with Cold Junction Compensation
AD595 for thermocouple type K
for using a pt100, you need a resistor bridge an AOP amplifier
Maybe you can use also PT1000 more easy to handle , less probleme with cable lenght to the sensor.
 

Attachments

  • Pt100_docu.pdf
    162.8 KB · Views: 127

This helps?

https://www.edaboard.com/threads/294824/


Code Pascal - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
program jtherm;
 
// Lcd module connections
var LCD_RS : sbit at RD0_bit;
var LCD_EN : sbit at RD1_bit;
var LCD_D4 : sbit at RD4_bit;
var LCD_D5 : sbit at RD5_bit;
var LCD_D6 : sbit at RD6_bit;
var LCD_D7 : sbit at RD7_bit;
 
var LCD_RS_Direction : sbit at TRISD0_bit;
var LCD_EN_Direction : sbit at TRISD1_bit;
var LCD_D4_Direction : sbit at TRISD4_bit;
var LCD_D5_Direction : sbit at TRISD5_bit;
var LCD_D6_Direction : sbit at TRISD6_bit;
var LCD_D7_Direction : sbit at TRISD7_bit;
// End Lcd module connections
 
{ Declarations section }
var temperature : real;
    strTemp     : string[23];
    len         : Integer;
 
begin
  { Main program }
  TRISA := 0x01;
  PORTA := 0x00;
  TRISD := 0x00;
  PORTD := 0x00;
  ADCON1 := 0x80;
  CM1CON0 := 0x00;
  CM2CON0 := 0x00;
  
  temperature := 0.0;
  
  LCD_Init();
  LCD_Cmd(_LCD_CLEAR);
  LCD_Cmd(_LCD_CURSOR_OFF);
  
  
  while 1 Do
        begin
        
             temperature := ADC_Read(0);
             temperature := temperature * 0.097752;
             FloatToStr(temperature, strTemp);
             len := strlen(strTemp);
             strTemp[len-1] := 0;
             LCD_Out(1,1,strTemp);
        
        end;
end.



96122d1379080675-jtherm.png
 

Attachments

  • jTherm.png
    jTherm.png
    67.7 KB · Views: 136
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top