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

MAX6662 problem

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







MAX6662 problem
PostPosted: Mon Jun 28, 2004 2:32 am     Reply with quote

Hello,
I wrote this MAX6662 routine for a PIC16f876A :
Code:
#include <16F876A.h>


#fuses HS,NOPROTECT,NOWDT,PUT,NOBROWNOUT,NOLVP
#use delay (clock=12000000)   // 12MHz clock
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#use fast_io(a)

// Définition des pins du microcontroleur
#define DQ_PIN    PIN_A2    //donnees du MAX6662
#define CLK_PIN   PIN_C3    //horloge du MAX6662
#define RST_PIN   PIN_A3    //Reset du MAX6662


//
// write_max6662
// Write a byte to the max6662
//
void write_max6662(int cmd)
{
int i;

for(i=128; i>0; i/=2)
{
output_low(CLK_PIN);
if(i & cmd) {output_high(DQ_PIN);}
else {output_low(DQ_PIN);}
output_high(CLK_PIN);
}
//output_low(DQ_PIN);
//delay_us(4);
//output_low(CLK_PIN);


}

//Lecture d'un mot de 16 bits
//
long temp_data;

long read_temp()
{
byte j;
output_low(DQ_PIN);
//set_tris_a(0x04);   // DQ = input

output_low(CLK_PIN);

temp_data = 0x0000;

for(j=0; j<16; j++)
{
temp_data = temp_data << 1;
output_high(CLK_PIN);

if (input(DQ_PIN) )
{
temp_data |=0x0001; // récuperation du i-eme bit
}
output_low(CLK_PIN);

}

set_tris_a(0x00);  // DQ = output

return temp_data;
}

void main(void)
{
long temp;
while(1)
   {
   //init_temp();
   output_low(DQ_PIN);
   output_low(RST_PIN);
   delay_us(1);
   write_max6662(0xC1); // lecture de la temperature

   //set_tris_a(0x04);   // DQ = input

   temp=read_temp();
   output_high(RST_PIN);
   printf("%lu\n\r",temp);
   }
}


I succeed in sending a command to the MAX6662 but when I set the A2 pin as an input, no data come from the MAX6662.
Could someone help me please to correct my mstake.
Thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 28, 2004 4:51 pm     Reply with quote

Your basic problem is this line right here:

#use fast_io(a)

When you use "fast i/o", you must define the i/o port direction
by using a set_tris_x() statement.

You have some set_tris_x() statements at various places in your
program, but in many cases you are using output_low() or output_high()
without first setting up those pins as outputs.

Because the PIC pins are configured as inputs upon power-up,
you must configure the pins as outputs before using those functions.
(This is only true if you are using the "fast i/o" mode -- which you are).

You need to setup the tris, at the very beginning of main().
Do it before the while() loop. You can change the direction of
the DQ pin later in your program with a set_tris_x() statement,
but you must setup CLK and RST as output pins at the very
start of main(). Note that because these signals are on different
ports, you will need to set the tris for both Port A and Port C.
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