CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

TC74 Demo Code.

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

TC74 Demo Code.
PostPosted: Thu Aug 18, 2005 4:14 pm     Reply with quote

this code works directly on a PICDEM-2 Plus with a TC74 temperature sensor. It is an endless loop that continuously prints out the temperature in Fahrenheit every several hundred milliseconds.

Code:

#include <16F876.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000) /* one instruction=1us? */
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use I2C(master, SCL=PIN_C3, SDA=PIN_C4)

void main(void)

{
            int data;
            int ack;
            long int fahr;

    printf ("\r\n\r\n\r\n");
    while (1)

    {     
        i2c_start();
        ack = i2c_write(0x9A);
        ack = i2c_write(0x00);

        /* send start again */
        i2c_start();
        ack = i2c_write(0x9b);
        data = i2c_read(0);
        i2c_stop();

        // Convert the A/D value to fahrenheit
        fahr = (9 * (long)data);
        fahr = fahr/5;
        fahr = fahr + 32;
        printf ("Temp: %ld\r\n", fahr);       
        delay_ms(200);
    }
}


Last edited by MikeValencia on Wed Aug 24, 2005 6:27 pm; edited 1 time in total
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Tue Aug 23, 2005 6:50 am     Reply with quote

I have a mistake in the code. "i2c_stop()" should be "i2c_stop(0);"

Without the (0), the TC74 probably wouldn't relinquish the session. My original code works probably because, in my example, the TC74 is the only chip the PIC talks to.

Thanks to "PCM Programmer" for bringing this to my attention.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 23, 2005 7:04 am     Reply with quote

I believe that you mean i2c_read(0). i2c_stop() doesn't take parameters.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 23, 2005 1:26 pm     Reply with quote

In my PM, I did say it should be i2c_read(0).
(I also suggested editing the original post)
hfelton



Joined: 07 Sep 2006
Posts: 2

View user's profile Send private message

link to newer-thread and code
PostPosted: Fri Oct 06, 2006 2:19 am     Reply with quote

howdee - i was just testing a PICDEM HPC demo board and stumbled here (on my TC74 search) in the forums. im going to include a link to another thread which makes the important distinction that the variables should be labelled 'signed' for ccs-c. the linked-code works perfectly on my demo board with the 'standard' addresses given. Smile

http://www.ccsinfo.com/forum/viewtopic.php?t=28089

good luck, h.
new2ccs



Joined: 29 Oct 2006
Posts: 10

View user's profile Send private message

PostPosted: Thu Nov 16, 2006 1:06 pm     Reply with quote

why is he sending twice before he reads it ?. Also, on the picdem 2+ the eeprom(24lc256) is also connected to the SDA , SCL. with the code above, the pic just reads it from tc74 and doesn't do anything with eeprom. am i right?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 16, 2006 3:26 pm     Reply with quote

Quote:
why is he sending twice before he reads it

Download the TC74 data sheet and look at the "Read Byte" diagram
on page 7. His code matches the diagram.
http://ww1.microchip.com/downloads/en/DeviceDoc/21462c.pdf

Quote:

Also, on the picdem 2+ the eeprom(24lc256) is also connected to the
SDA , SCL. with the code above, the pic just reads it from tc74 and
doesn't do anything with eeprom. am i right?

The TC74 and the 24LC256 have different i2c addresses.
Therefore, they can be on the same bus without conflicting with each
other.
new2ccs



Joined: 29 Oct 2006
Posts: 10

View user's profile Send private message

PostPosted: Thu Nov 16, 2006 4:20 pm     Reply with quote

ok, now i kind of got it. I used one of the examples in the manual and didn't work for me and I also read the data sheet too, but still got confused. now it is some what clear.

another question PCM, so that only the communication between the pic and the TC74(sensor) right?. if my understanding is correct then, if i want to write to the eeprom(24LC256). i would do something like that but with the 24LC256' address right?

thanks PCM, you are the great help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 16, 2006 4:39 pm     Reply with quote

To use the 25LC256 eeprom, just #include the 24256.c driver in your
C program. The driver is located in this folder:

c:\Program Files\Picc\Drivers\24256.c

If you have questions about that driver, please post them in the main
forum. (not the Code library)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group