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 CCS Technical Support

Example for a TC77?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Birdasaur



Joined: 07 Oct 2003
Posts: 29

View user's profile Send private message

Example for a TC77?
PostPosted: Fri Dec 12, 2003 6:38 am     Reply with quote

Does anyone out there have a bitbang or SPI_READ() example for a TC77? I've tried the CCS spi_read() calls, but they clock 8 bits, whereas the TC77 temperature register is a 13 bit register. Needless to say a simple read isn't helping me. I've also tried to do a simple bit bang, but its not working. In fact, I can't seem to get the TC77 to even respond using the bit bang. I've posted this question in another thread but it is not getting viewed. I thought maybe it deserved its own thread.

here's some code that DOES NOT WORK Confused
//to try to bit bang the 13 bits
output_low(PIN_B1); //select the TC77
for(i=13; i>0; i--)
{
delay_us(10);
output_high(PIN_B2);
delay_us(10);
if (input(PIN_B3))
bit_set(data,i);
delay_us(10);
output_low(PIN_B2);
delay_us(10);
}
output_high(PIN_B1); //deselect the TC77


This code also fails Confused

//To use the spi_read() function

output_low(PIN_B1); //select the TC77

temp1 = spi_read(0x00); //Read the 8 MSB of the data
temp2 = spi_read(0x00);

output_high(PIN_B1); //deselect the TC77

For the SPI_READ() code I've tried all manner of combinations of reads and writes and all return goofy results. I must be missing something simple, could somebody out there just point me back in the right direction?
Birdasaur



Joined: 07 Oct 2003
Posts: 29

View user's profile Send private message

:grin: The Solution
PostPosted: Fri Dec 12, 2003 8:35 am     Reply with quote

Here's the code that works like a dream. Turns out I had a couple jumpers interfering with my bitbang lines. (duh Embarassed )

Also I had the clock order wrong, gotta lower the clock, than raise the clock BEFORE the data bit is clocked out.

I don't know how much of each delay is needed.

while(1)
{
delay_ms(1000);
data = 0;
F = 0;

output_low(PIN_B1); //select the TC77
for(i=13; i>0; i--)
{
output_high(PIN_B2); //clock
delay_us(10);
output_low(PIN_B2);
delay_us(10);
if (input(PIN_B3))
bit_set(data,i);
}
output_high(PIN_B1); //deselect the TC77

data >>= 6; //to get rid of the fraction of a degree

F = (unsigned int16) (1.8 * data) +32;
printf("\r\nThe temperature is: %lu C/%lu F \r\n",data,F);
}

Good luck to everyone, I hope this helps someone.
wedilo



Joined: 16 Sep 2003
Posts: 71
Location: Moers, Germany

View user's profile Send private message

PostPosted: Mon Dec 15, 2003 2:58 am     Reply with quote

Hi Birdasaur,
fine code snippet. Thank you...

BUT, in your first post you ask for some code and in your second post you give the answer yourself? Amazing... Laughing

73 Sven
Birdasaur



Joined: 07 Oct 2003
Posts: 29

View user's profile Send private message

well....
PostPosted: Mon Dec 15, 2003 10:17 am     Reply with quote

I try to contribute to the forum whenever I can. I've asked for a lot of help in the past and I want to be the "helper" too.

Also, noone answered me so I figured it was a mystery.

It was easier than I thought too.

Good luck everyone.

Cool
wedilo



Joined: 16 Sep 2003
Posts: 71
Location: Moers, Germany

View user's profile Send private message

PostPosted: Tue Dec 16, 2003 1:50 am     Reply with quote

Hello Birdasaur,
that's a great attitude.

Thank you and all the best
73 Sven
>>TechDesign
Guest







tc77
PostPosted: Sun Jun 20, 2004 7:38 am     Reply with quote

this one works too! (on a 16f877)
i took these non-standard pins, cause i need RC3 & RC4 for i?c routines..

Code:
#bit TC77_CS  =pb.7   // RB7 pin40,TC77 !CS
#bit TC77_SIO =pb.6   // RB6 pin39,TC77 S I/O
#bit TC77_SCK=pb.5   // RB5 pin38,TC77 SCK
...
...
void tc77_read(void);
int16 t_in;
...
...
void main(){
tris_pb=0x51;      // oiox xxxx   
   
TC77_CS=1;       //

while(1)
{

tc77_read();   

lcd_gotoxy(90,0);                        // my own routines to display t_in
printf(lcd_text,"%lx",t_in);            // id.

delay_ms(100);
   

} //end while

      } //end main




void tc77_read(){

char b;

t_in=3;
TC77_SCK=1;
TC77_CS=0;

for(b=16;b!=2;b--){
     TC77_SCK=0;
     TC77_SCK=1;
     if (TC77_SIO){
         bit_set(t_in,b-1);
     }
  }

TC77_SCK=0;
TC77_CS=1;
}

// so there's no need for long delays at all!! But please do put an elco of 10?F/16V AFTER the voltage regulator. The AD-conversion inside the TC77 needs it!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion 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