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.

[PIC] PIC18F46K22 with tc74 temperature sensor. How to read it in?

Status
Not open for further replies.

jag15924

Newbie level 3
Joined
May 5, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
42
Hi,
I have a pic18f46k22 on a picdem 2 board. I'm having a hard time reading in the temperature and displaying it on the screen? Any ideas on how to do this?
 

What problem are you having? Are the wires not long enough? Is it too dark in the room to read the display? Is the power turned on?

Maybe you could give us at least a HINT as to what is or isn't working. Have you set up your I2C interface properly? Have you looked at signals with a scope? Do you have a debugger?
There are an infinite number of things that could make this not work: bad hardware, bad software, bad display routine, bad I2C routine, incorrect port settings, incorrect oscillator settings...
 
//here is my code. The LCD display works but i just do not know how to get the data from the temperature sensor and display it on the screen. Do you have any idea on how to approach this problem. I have tried multiple ways, but I'm having issue getting anything to out put from the temperature sensor.


Code C - [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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include "Helper.h"
#include<xc.h> //everything you need for all pics. no need for specific one.
typedef unsigned char BYTE;
void LCDInit(void );    //Initialize the LCD module per Ocular specifications
void Delay(void);
void Delay750us(void);
void LongDelay(void);
void LCDbusy(void);     // NOTE:  Busy bit does not work, this routine is just a time delay
void LCDWriteNibble(BYTE,BYTE);
// 1st BYTE is nibble to write with nibble in upper four bits
// 2nd BYTE is 0x0 for instruction register, 0x1 for data register
void LCDWrite(BYTE);    // Write characters to the LCD panel
void TextDisplay(unsigned char*, int);  // Write a constant string to the LCD
void LCDLine1(void);    // Set LCD to Line 1
void LCDLine2(void);    // Set LCD to Line 2
void ShiftCursor(void); // Shift cursor right by 1 location
void CursorOn(void);    // Turn on cursor and have it blink
void DisplayClr(void);  // Clear LCD display
 
#define LCD_PWR     LATDbits.LATD7      // LCD power pin
#define LCD_EN      LATDbits.LATD6      // LCD enable
#define LCD_RW      LATDbits.LATD5      // LCD read/write line
#define LCD_RS      LATDbits.LATD4      // LCD register select line
 
#define LCD_EN_DIR  TRISDbits.TRISD6    // 6
#define LCD_RW_DIR  TRISDbits.TRISD5    // 5
#define LCD_RS_DIR  TRISDbits.TRISD4    // 4
 
 
void main()
{
   //Let the LCD Module start up
//   Wait(100);
    Delay();
   //Initialize the LCD Module
   LCDInit();
 
   //Initialize the ADC Module
 
int   ADCInit();
 
   //Clear the Module
   DisplayClr();
 
   //Write a string at current cursor pos
   TextDisplay("LM35 Test",9);
   //LCDWriteStringXY(4,1,"Degree Celcius");
 
   while(1)
   {
      int val; //ADC Value
 
      int t;      //Temperature
 
 
      val=ADCRead(0);   //Read Channel 0
 
     t=(val*0.48876);//Convert to Degree Celcius
 
      LCDWrite(t);//Prit IT!
 
 
      Wait();
   }
 
}
 
////////////////////////////////////////////////////
//Function to send initialization information to LCD
////////////////////////////////////////////////////
void LCDInit()
{
    TRISD = 0x00;
    LCD_PWR=1;   // to power up the LCD
 
//  These values were obtained from Ocular tech support to properly
//  initialize the LCD module
    Delay();
    LCDWriteNibble(0x20,0x0);   //#1 control sequence (?)
    Delay750us();
    LCDWriteNibble(0x20,0x0);   //#2 control sequence (function set 4-bit mode,
    LCDWriteNibble(0x80,0x0);   //#2 control sequence   2-line display with 5x7 dots)
    Delay750us();
    LCDWriteNibble(0x00,0x0);   //#3 control sequence (turn display on)
    LCDWriteNibble(0xC0,0x0);   //#3 control sequence
    Delay750us();
    LCDWriteNibble(0x00,0x0);   //#4 control sequence (clear display)
    LCDWriteNibble(0x10,0x0);   //#4 control sequence
    Delay750us();
    LongDelay();
    LCDWriteNibble(0x00,0x0);   //#5 control sequence (return cursor to home position)
    LCDWriteNibble(0x20,0x0);   //#5 control sequence
}

 
Last edited by a moderator:

I didn't look that closely at your code, but you don't seem to have any I2C function there...
 

Can you explain please?

the TC74 has an I2C interface so your program needs to communicate with the PIC I2C interface to read the temperature - there appears to be no I2C instructions in your code

there is some PIC18 I2C example code on the Microchip site
**broken link removed**
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top