Duvida num fragmento de codigo

Software e Hardware para uC PIC

Moderadores: andre_luis, 51, guest2003, Renie

Duvida num fragmento de codigo

Mensagempor amboni » 15 Ago 2008 17:17

Boa tarde rapaziada..... já e sexta feira... quase na horade i pra casa...
mais estou tentando fazer funcionar o sensor SHT7Xx da sensirion, la no site deles tem um codigo fonte exemplo pra 8051 e estou convertendo pra CCS c, mais ai entao....

Código: Selecionar todos
//------------------------------------------------------------------------------
char sht11_read_byte(unsigned char ack)       <<< o que significa?!?
//------------------------------------------------------------------------------
{
unsigned char i,val=0;


sei que é simples... só mais nao sei o que e´!
fiz as minha alterações aqui, consegui compilar... mais ele ainda ta mostrando os valores errados no proteus.....

alguem já mecheu com esse sensor?!


amboni
amboni
Nibble
 
Mensagens: 50
Registrado em: 23 Abr 2008 08:26
Localização: Içara - SC

Mensagempor amboni » 15 Ago 2008 17:22

O codigo no site da sensirion segue abaixo.....


Código: Selecionar todos
/***********************************************************************************
Project:          SHTxx demo program (V2.1)
Filename:         SHTxx_Sample_Code.c   

Prozessor:        80C51 family
Compiler:         Keil Version 6.14

Autor:            MST
Copyrigth:        (c) Sensirion AG     
***********************************************************************************/

#include <AT89s53.h> //Microcontroller specific library, e.g. port definitions
#include <intrins.h> //Keil library (is used for _nop()_ operation) 
#include <math.h>    //Keil library 
#include <stdio.h>   //Keil library

typedef union
{ unsigned int i;
  float f;
} value;

//----------------------------------------------------------------------------------
// modul-var
//----------------------------------------------------------------------------------
enum {TEMP,HUMI};

#define   DATA      P1_1
#define   SCK      P1_0

#define noACK 0
#define ACK   1
                            //adr  command  r/w
#define STATUS_REG_W 0x06   //000   0011    0
#define STATUS_REG_R 0x07   //000   0011    1
#define MEASURE_TEMP 0x03   //000   0001    1
#define MEASURE_HUMI 0x05   //000   0010    1
#define RESET        0x1e   //000   1111    0

//----------------------------------------------------------------------------------
char s_write_byte(unsigned char value)
//----------------------------------------------------------------------------------
// writes a byte on the Sensibus and checks the acknowledge
{
  unsigned char i,error=0; 
  for (i=0x80;i>0;i/=2)             //shift bit for masking
  { if (i & value) DATA=1;          //masking value with i , write to SENSI-BUS
    else DATA=0;                       
    SCK=1;                          //clk for SENSI-BUS
    _nop_();_nop_();_nop_();        //pulswith approx. 5 us     
    SCK=0;
  }
  DATA=1;                           //release DATA-line
  SCK=1;                            //clk #9 for ack
  error=DATA;                       //check ack (DATA will be pulled down by SHT11)
  SCK=0;       
  return error;                     //error=1 in case of no acknowledge
}

//----------------------------------------------------------------------------------
char s_read_byte(unsigned char ack)
//----------------------------------------------------------------------------------
// reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"
{
  unsigned char i,val=0;
  DATA=1;                           //release DATA-line
  for (i=0x80;i>0;i/=2)             //shift bit for masking
  { SCK=1;                          //clk for SENSI-BUS
    if (DATA) val=(val | i);        //read bit 
    SCK=0;                 
  }
  DATA=!ack;                        //in case of "ack==1" pull down DATA-Line
  SCK=1;                            //clk #9 for ack
  _nop_();_nop_();_nop_();          //pulswith approx. 5 us
  SCK=0;                     
  DATA=1;                           //release DATA-line
  return val;
}

//----------------------------------------------------------------------------------
void s_transstart(void)
//----------------------------------------------------------------------------------
// generates a transmission start
//       _____         ________
// DATA:      |_______|
//           ___     ___
// SCK : ___|   |___|   |______

   DATA=1; SCK=0;                   //Initial state
   _nop_();
   SCK=1;
   _nop_();
   DATA=0;
   _nop_();
   SCK=0; 
   _nop_();_nop_();_nop_();
   SCK=1;
   _nop_();
   DATA=1;         
   _nop_();
   SCK=0;         
}

//----------------------------------------------------------------------------------
void s_connectionreset(void)
//----------------------------------------------------------------------------------
// communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart
//       _____________________________________________________         ________
// DATA:                                                      |_______|
//          _    _    _    _    _    _    _    _    _        ___     ___
// SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______|   |___|   |______

  unsigned char i;
  DATA=1; SCK=0;                    //Initial state
  for(i=0;i<9;i++)                  //9 SCK cycles
  { SCK=1;
    SCK=0;
  }
  s_transstart();                   //transmission start
}

//----------------------------------------------------------------------------------
char s_softreset(void)
//----------------------------------------------------------------------------------
// resets the sensor by a softreset
{
  unsigned char error=0; 
  s_connectionreset();              //reset communication
  error+=s_write_byte(RESET);       //send RESET-command to sensor
  return error;                     //error=1 in case of no response form the sensor
}

//----------------------------------------------------------------------------------
char s_read_statusreg(unsigned char *p_value, unsigned char *p_checksum)
//----------------------------------------------------------------------------------
// reads the status register with checksum (8-bit)
{
  unsigned char error=0;
  s_transstart();                   //transmission start
  error=s_write_byte(STATUS_REG_R); //send command to sensor
  *p_value=s_read_byte(ACK);        //read status register (8-bit)
  *p_checksum=s_read_byte(noACK);   //read checksum (8-bit) 
  return error;                     //error=1 in case of no response form the sensor
}

//----------------------------------------------------------------------------------
char s_write_statusreg(unsigned char *p_value)
//----------------------------------------------------------------------------------
// writes the status register with checksum (8-bit)
{
  unsigned char error=0;
  s_transstart();                   //transmission start
  error+=s_write_byte(STATUS_REG_W);//send command to sensor
  error+=s_write_byte(*p_value);    //send value of status register
  return error;                     //error>=1 in case of no response form the sensor
}
                         
//----------------------------------------------------------------------------------
char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode)
//----------------------------------------------------------------------------------
// makes a measurement (humidity/temperature) with checksum
{
  unsigned error=0;
  unsigned int i;

  s_transstart();                   //transmission start
  switch(mode){                     //send command to sensor
    case TEMP   : error+=s_write_byte(MEASURE_TEMP); break;
    case HUMI   : error+=s_write_byte(MEASURE_HUMI); break;
    default     : break;   
  }
  for (i=0;i<65535;i++) if(DATA==0) break; //wait until sensor has finished the measurement
  if(DATA) error+=1;                // or timeout (~2 sec.) is reached
  *(p_value)  =s_read_byte(ACK);    //read the first byte (MSB)
  *(p_value+1)=s_read_byte(ACK);    //read the second byte (LSB)
  *p_checksum =s_read_byte(noACK);  //read checksum
  return error;
}

//----------------------------------------------------------------------------------
void init_uart()
//----------------------------------------------------------------------------------
//9600 bps @ 11.059 MHz
{SCON  = 0x52;   
 TMOD  = 0x20;   
 TCON  = 0x69;     
 TH1   = 0xfd;   
}

//----------------------------------------------------------------------------------------
void calc_sth11(float *p_humidity ,float *p_temperature)
//----------------------------------------------------------------------------------------
// calculates temperature [°C] and humidity [%RH]
// input :  humi [Ticks] (12 bit)
//          temp [Ticks] (14 bit)
// output:  humi [%RH]
//          temp [°C]
{ const float C1=-4.0;              // for 12 Bit
  const float C2=+0.0405;           // for 12 Bit
  const float C3=-0.0000028;        // for 12 Bit
  const float T1=+0.01;             // for 14 Bit @ 5V
  const float T2=+0.00008;           // for 14 Bit @ 5V   

  float rh=*p_humidity;             // rh:      Humidity [Ticks] 12 Bit
  float t=*p_temperature;           // t:       Temperature [Ticks] 14 Bit
  float rh_lin;                     // rh_lin:  Humidity linear
  float rh_true;                    // rh_true: Temperature compensated humidity
  float t_C;                        // t_C   :  Temperature [°C]

  t_C=t*0.01 - 40;                  //calc. temperature from ticks to [°C]
  rh_lin=C3*rh*rh + C2*rh + C1;     //calc. humidity from ticks to [%RH]
  rh_true=(t_C-25)*(T1+T2*rh)+rh_lin;   //calc. temperature compensated humidity [%RH]
  if(rh_true>100)rh_true=100;       //cut if the value is outside of
  if(rh_true<0.1)rh_true=0.1;       //the physical possible range

  *p_temperature=t_C;               //return temperature [°C]
  *p_humidity=rh_true;              //return humidity[%RH]
}

//--------------------------------------------------------------------
float calc_dewpoint(float h,float t)
//--------------------------------------------------------------------
// calculates dew point
// input:   humidity [%RH], temperature [°C]
// output:  dew point [°C]
{ float logEx,dew_point;
  logEx=0.66077+7.5*t/(237.3+t)+(log10(h)-2);
  dew_point = (logEx - 0.66077)*237.3/(0.66077+7.5-logEx);
  return dew_point;
}

//----------------------------------------------------------------------------------
void main()
//----------------------------------------------------------------------------------
// sample program that shows how to use SHT11 functions
// 1. connection reset
// 2. measure humidity [ticks](12 bit) and temperature [ticks](14 bit)
// 3. calculate humidity [%RH] and temperature [°C]
// 4. calculate dew point [°C]
// 5. print temperature, humidity, dew point 

{ value humi_val,temp_val;
  float dew_point;
  unsigned char error,checksum;
  unsigned int i;

  init_uart();
  s_connectionreset();
  while(1)
  { error=0;
    error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI);  //measure humidity
    error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP);  //measure temperature
    if(error!=0) s_connectionreset();                 //in case of an error: connection reset
    else
    { humi_val.f=(float)humi_val.i;                   //converts integer to float
      temp_val.f=(float)temp_val.i;                   //converts integer to float
      calc_sth11(&humi_val.f,&temp_val.f);            //calculate humidity, temperature
      dew_point=calc_dewpoint(humi_val.f,temp_val.f); //calculate dew point
      printf("temp:%5.1fC humi:%5.1f%% dew point:%5.1fC\n",temp_val.f,humi_val.f,dew_point);
    }
    //----------wait approx. 0.8s to avoid heating up SHTxx------------------------------     
    for (i=0;i<40000;i++);     //(be sure that the compiler doesn't eliminate this line!)
    //-----------------------------------------------------------------------------------                       
  }
}


.....


e o que tentei transformar...

Código: Selecionar todos

#include <16F876A.h>
#use delay(clock=22118400,RESTART_WDT) // 
#use rs232(baud=57600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,restart_wdt)
#fuses HS,NOWDT,noPUT,NOPROTECT,NOLVP
#include <math.h>    //Keil library
#include <stdio.h>   //Keil library
#use standard_io(a)       // CONFIGURA PINO RB0 COMO ENTRADA
typedef union
{ unsigned int i;
  float f;
} value;

//----------------------------------------------------------------------------------
// modul-var
//----------------------------------------------------------------------------------
enum {TEMP,HUMI};

#define   DATA     PIN_C3
#define   SCK      PIN_C4

#define noACK 0
#define ACK   1
                            //adr  command  r/w
#define STATUS_REG_W 0x06   //000   0011    0
#define STATUS_REG_R 0x07   //000   0011    1
#define MEASURE_TEMP 0x03   //000   0001    1
#define MEASURE_HUMI 0x05   //000   0010    1
#define RESET        0x1e   //000   1111    0


//ESSE ACK AI DE BAIXO DA UMA PAU ****** QNDO COMPILA....
 
//----------------------------------------------------------------------------------
char s_read_byte (unsigned char ack)
//----------------------------------------------------------------------------------
// reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"
{
unsigned char i,val=0;
 
  OUTPUT_HIGH(DATA);                           //release DATA-line
  for (i=0x80;i>0;i/=2)             //shift bit for masking
  {
    OUTPUT_HIGH(SCK);                          //clk for SENSI-BUS
//    if (DATA)
    if (input(DATA)==1)
    val=(val | i);        //read bit
    OUTPUT_LOW(SCK);                 
  }
//  DATA=!ack;                        //in case of "ack==1" pull down DATA-Line
  output_bit(DATA,!ack); //in case of "ack==1" pull down DATA-Line
  OUTPUT_HIGH(SCK);                            //clk #9 for ack
  delay_us(5); //pulswith approx. 5 us         
  OUTPUT_LOW(SCK);                     
  OUTPUT_HIGH(DATA);                           //release DATA-line
  return val;
}
//----------------------------------------------------------------------------------
char s_write_byte(unsigned char value)
//----------------------------------------------------------------------------------
// writes a byte on the Sensibus and checks the acknowledge
{
  unsigned char i,error=0; 
  for (i=0x80;i>0;i/=2)             //shift bit for masking
  {
    if (i & value)
      OUTPUT_HIGH(DATA);          //masking value with i , write to SENSI-BUS
    else
      OUTPUT_LOW(DATA);
      OUTPUT_HIGH(SCK);                          //clk for SENSI-BUS
      delay_us(5);              //pulswith approx. 5 us     
      OUTPUT_LOW(SCK);
  }
  OUTPUT_HIGH(DATA);                           //release DATA-line
  OUTPUT_HIGH(SCK);                            //clk #9 for ack
  error=input(DATA); //check ack (DATA will be pulled down by SHT11)
//  error=DATA;                       //check ack (DATA will be pulled down by SHT11)
  OUTPUT_LOW(SCK);       
  return error;                     //error=1 in case of no acknowledge
}
//----------------------------------------------------------------------------------
void s_transstart(void)
//----------------------------------------------------------------------------------
// generates a transmission start
//       _____         ________
// DATA:      |_______|
//           ___     ___
// SCK : ___|   |___|   |______

   OUTPUT_HIGH(DATA);
   OUTPUT_LOW(SCK);                   //Initial state
   delay_us(1); //pulswith approx. 5 us
   OUTPUT_HIGH(SCK);
   delay_us(1); //pulswith approx. 5 us
   OUTPUT_LOW(DATA);
   delay_us(1); //pulswith approx. 5 us
   OUTPUT_LOW(SCK); 
   delay_us(3);            //pulswith approx. NO OUTRO SOFT EH 3 uS
   OUTPUT_HIGH(SCK);
   delay_us(1); //pulswith approx. 5 us
   OUTPUT_HIGH(DATA);         
   delay_us(1); //pulswith approx. 5 us
   OUTPUT_LOW(SCK);         
}

//----------------------------------------------------------------------------------
void s_connectionreset(void)
//----------------------------------------------------------------------------------
// communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart
//       _____________________________________________________         ________
// DATA:                                                      |_______|
//          _    _    _    _    _    _    _    _    _        ___     ___
// SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______|   |___|   |______

  unsigned char i;
  OUTPUT_HIGH(DATA);
  OUTPUT_LOW(SCK);                    //Initial state
  for(i=0;i<9;i++)                  //9 SCK cycles
  {
    OUTPUT_HIGH(SCK);
    OUTPUT_LOW(SCK);
  }
  s_transstart();                   //transmission start
}
//----------------------------------------------------------------------------------
char s_softreset(void)
//----------------------------------------------------------------------------------
// resets the sensor by a softreset
{
  unsigned char error=0; 
  s_connectionreset();              //reset communication
  error+=s_write_byte(RESET);       //send RESET-command to sensor
  return error;                     //error=1 in case of no response form the sensor
}
//----------------------------------------------------------------------------------
char s_read_statusreg(unsigned char *p_value, unsigned char *p_checksum)
//----------------------------------------------------------------------------------
// reads the status register with checksum (8-bit)
{
  unsigned char error=0;
  s_transstart();                   //transmission start
  error=s_write_byte(STATUS_REG_R); //send command to sensor
  *p_value=s_read_byte(ACK);        //read status register (8-bit)
  *p_checksum=s_read_byte(noACK);   //read checksum (8-bit) 
  return error;                     //error=1 in case of no response form the sensor
}
//----------------------------------------------------------------------------------
char s_write_statusreg(unsigned char *p_value)
//----------------------------------------------------------------------------------
// writes the status register with checksum (8-bit)
{
  unsigned char error=0;
  s_transstart();                   //transmission start
  error+=s_write_byte(STATUS_REG_W);//send command to sensor
  error+=s_write_byte(*p_value);    //send value of status register
  return error;                     //error>=1 in case of no response form the sensor
}
                         
//----------------------------------------------------------------------------------
char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char mode)
//----------------------------------------------------------------------------------
// makes a measurement (humidity/temperature) with checksum
{
  unsigned error=0;
  unsigned int i;

  s_transstart();                   //transmission start
  switch(mode)
  {                     //send command to sensor
    case TEMP   : error+=s_write_byte(MEASURE_TEMP); break;
    case HUMI   : error+=s_write_byte(MEASURE_HUMI); break;
    default     : break;   
  }
  for (i=0;i<65535;i++)
//  if(DATA==0)
  if(input(DATA)==0)
  break; //wait until sensor has finished the measurement
//  if(DATA)
  if(input(DATA)==1)
  error+=1;                // or timeout (~2 sec.) is reached
  *(p_value+1)=s_read_byte(ACK);    //read the second byte (LSB)
  *(p_value)  =s_read_byte(ACK);    //read the first byte (MSB)
 
  *p_checksum =s_read_byte(noACK);  //read checksum
  return error;
}
//----------------------------------------------------------------------------------------
void calc_sth11(float *p_humidity ,float *p_temperature)
//----------------------------------------------------------------------------------------
// calculates temperature [°C] and humidity [%RH]
// input :  humi [Ticks] (12 bit)
//          temp [Ticks] (14 bit)
// output:  humi [%RH]
//          temp [°C]
{ const float C1=-4.0;              // for 12 Bit
  const float C2=+0.0405;           // for 12 Bit
  const float C3=-0.0000028;        // for 12 Bit
  const float T1=+0.01;             // for 14 Bit @ 5V
  const float T2=+0.00008;           // for 14 Bit @ 5V   

  float rh;             // rh:      Humidity [Ticks] 12 Bit
  float t;           // t:       Temperature [Ticks] 14 Bit
  float rh_lin;                     // rh_lin:  Humidity linear
  float rh_true;                    // rh_true: Temperature compensated humidity
  float t_C;                        // t_C   :  Temperature [°C]

t=*p_temperature;
rh=*p_humidity; 

  t_C=t*0.01 - 40;                  //calc. temperature from ticks to [°C]
  rh_lin=C3*rh*rh + C2*rh + C1;     //calc. humidity from ticks to [%RH]
  rh_true=(t_C-25)*(T1+T2*rh)+rh_lin;   //calc. temperature compensated humidity [%RH]
  if(rh_true>100)rh_true=100;       //cut if the value is outside of
  if(rh_true<0.1)rh_true=0.1;       //the physical possible range

  *p_temperature=t_C;               //return temperature [°C]
  *p_humidity=rh_true;              //return humidity[%RH]
}
//--------------------------------------------------------------------
float calc_dewpoint(float h,float t)
//--------------------------------------------------------------------
// calculates dew point
// input:   humidity [%RH], temperature [°C]
// output:  dew point [°C]
{ float logEx,dew_point;
  logEx=0.66077+7.5*t/(237.3+t)+(log10(h)-2);
  dew_point = (logEx - 0.66077)*237.3/(0.66077+7.5-logEx);
  return dew_point;
}
//----------------------------------------------------------------------------------
void main()
//----------------------------------------------------------------------------------
// sample program that shows how to use SHT11 functions
// 1. connection reset
// 2. measure humidity [ticks](12 bit) and temperature [ticks](14 bit)
// 3. calculate humidity [%RH] and temperature [°C]
// 4. calculate dew point [°C]
// 5. print temperature, humidity, dew point 

{
value humi_val,temp_val;
float dew_point;
unsigned char error,checksum;
//unsigned int i;
port_b_pullups (TRUE);
//  init_uart();

  s_connectionreset();
  while(TRUE)
  {
    DELAY_MS(1000);
    error=0;
    error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI);  //measure humidity
    error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP);  //measure temperature
    if(error!=0)
      s_connectionreset();                 //in case of an error: connection reset
         else
            {
               humi_val.f=(float)humi_val.i;                   //converts integer to float
               temp_val.f=(float)temp_val.i;                   //converts integer to float
               calc_sth11(&humi_val.f,&temp_val.f);            //calculate humidity, temperature
               dew_point=calc_dewpoint(humi_val.f,temp_val.f); //calculate dew point
               printf("temp:%5.1fC humi:%5.1f%% dew point:%5.1fC\n\r",temp_val.f,humi_val.f,dew_point);
            }
    //----------wait approx. 0.8s to avoid heating up SHTxx------------------------------     
//   for (i=0;i<40000;i++);     //(be sure that the compiler doesn't eliminate this line!)
    //-----------------------------------------------------------------------------------                       
  }
}
amboni
Nibble
 
Mensagens: 50
Registrado em: 23 Abr 2008 08:26
Localização: Içara - SC

Mensagempor ze » 18 Ago 2008 09:21

oi . num cunheço o sensor em questão. e num li o dataxit. mas ele num é i2c não??? se sim tal pic tem isso no seu hw. facilita as coisas.
...

não achei a rotina completa st11_read....
Avatar do usuário
ze
Dword
 
Mensagens: 1655
Registrado em: 05 Jun 2007 14:32

Mensagempor amboni » 18 Ago 2008 13:51

Lellis....

aquele fragmento copiei de outro codigo.... sorry!!
mais eh esse ai...
nao sei qual o motivo ou circunstancia.....


Código: Selecionar todos
//ESSE ACK AI DE BAIXO DA UMA PAU ****** QNDO COMPILA....
 
//----------------------------------------------------------------------------------
char s_read_byte (unsigned char ack)   <<<<<<<< ESSE AQUI ÓOH
//----------------------------------------------------------------------------------
// reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"
{
unsigned char i,val=0;
 
  OUTPUT_HIGH(DATA);                           //release DATA-line
  for (i=0x80;i>0;i/=2)             //shift bit for masking
  {
    OUTPUT_HIGH(SCK);                          //clk for SENSI-BUS
//    if (DATA)
    if (input(DATA)==1)
    val=(val | i);        //read bit
    OUTPUT_LOW(SCK);                 
  }
//  DATA=!ack;                        //in case of "ack==1" pull down DATA-Line
  output_bit(DATA,!ack); //in case of "ack==1" pull down DATA-Line
  OUTPUT_HIGH(SCK);                            //clk #9 for ack
  delay_us(5); //pulswith approx. 5 us         
  OUTPUT_LOW(SCK);                     
  OUTPUT_HIGH(DATA);                           //release DATA-line
  return val;
}
amboni
Nibble
 
Mensagens: 50
Registrado em: 23 Abr 2008 08:26
Localização: Içara - SC

Mensagempor andre_luis » 18 Ago 2008 14:32

amboni,

Posso estar enganado, mas até onde sei, a função output_bit (pin, value) aceita somente constantes como entrada, e não variável ( isso não está claramente explicado no HELP do CCS ).

Dessa forma como voce fez, nunca tentei :

Código: Selecionar todos
output_bit(DATA,!ack);


Dá uma olhada no FAQ do HELP do CCS chamado :
How can I pass a variable to functions like OUTPUT_HIGH().

+++
"Por maior que seja o buraco em que você se encontra, relaxe, porque ainda não há terra em cima."
Avatar do usuário
andre_luis
Dword
 
Mensagens: 5447
Registrado em: 11 Out 2006 18:27
Localização: Brasil - RJ

Mensagempor ze » 18 Ago 2008 15:56

qual pau que dá? se o teprom tiver certo é só fazer
if (!ack) outputbit(data, 0); else outputbit(data, 1); //odeio ccs por isso. num é + facil "RB0=0 " ??????!!!! a propósito no hitech c funciona RB0=ack. e também data e ack podem ser "static bit" (global)
se seu odioso compilador xingar, faça: if (ack==0) ....else....
abs
Avatar do usuário
ze
Dword
 
Mensagens: 1655
Registrado em: 05 Jun 2007 14:32

Mensagempor amboni » 18 Ago 2008 17:01

ahááa entao aprendi a colocar foto.... ¬¬

então... nao tive tempo de mecher na bagaça ainda.... provavelmente so depois da facul.... mais o codigo que "tentei" converter do 8051 original disponivel no site da sensirion para PIC CCS, que esta no exemplo acima gera esse erro no compilador.... acredito que seja mesmo sobre o !ACK

Imagem

valeu por enquanto....
amboni
Nibble
 
Mensagens: 50
Registrado em: 23 Abr 2008 08:26
Localização: Içara - SC

Mensagempor amboni » 18 Ago 2008 17:23

dei uma olhada agora e nao é do

Código: Selecionar todos
  output_bit(DATA,!ack); //in case of "ack==1" pull down DATA-Line


pq coloquei ele em comentario e continuou o erro...
percebi que o erro e diretamente aqui....


Código: Selecionar todos
  char s_read_byte (unsigned char ack)


pq se eu renomear o ACK com qualquer nome, por exemplo "joao"....

assim...

Código: Selecionar todos
char s_read_byte (unsigned char joao)


ele compila.... mais nao faz a leitura certa..... to achando que deve te alguns detalhezinhu na minha conversão.... do Keil pra CCS...

atée
amboni
Nibble
 
Mensagens: 50
Registrado em: 23 Abr 2008 08:26
Localização: Içara - SC

Mensagempor Jorge_Francisco » 18 Ago 2008 19:43

Tira o espaço entre o nome da função e o parentese do parametro, não sei se é isso, mas tente apagar aquele comentário entre a função e a primeira chave.

Abraço
Avatar do usuário
Jorge_Francisco
Dword
 
Mensagens: 1009
Registrado em: 12 Out 2006 09:53
Localização: Rio de Janeiro

Mensagempor Jorge_Francisco » 18 Ago 2008 19:47

Aqui me pareceu que o parentese não está fechando, parece que tem um '(' ao invés de um ')' no final.

Está assim:

char s_read_byte (unsigned char ack(

e deveria ser assim:

char s_read_byte(unsigned char ack)

É apenas um palpite.
Avatar do usuário
Jorge_Francisco
Dword
 
Mensagens: 1009
Registrado em: 12 Out 2006 09:53
Localização: Rio de Janeiro

Mensagempor andre_luis » 18 Ago 2008 23:27

2 observaçoes :

1) Não vi nos códigos anteriores ( e nem nesse último código ) um Include de algum arquivo de cabeçalho ( .H ) para o protótipo dessas funçoes. Isto é necessário. Algo tipo : char s_read_byte(unsigned char ack) ;

2) a constante ACK já foi definida anteriormente. De algum modo isso pode estar causando algum problema com a variável ack; mesmo sendo o C case sensitive.

+++
"Por maior que seja o buraco em que você se encontra, relaxe, porque ainda não há terra em cima."
Avatar do usuário
andre_luis
Dword
 
Mensagens: 5447
Registrado em: 11 Out 2006 18:27
Localização: Brasil - RJ

Mensagempor joao » 19 Ago 2008 06:18

Ola Amboni,

Não tenho certeza sobre o seu erro, mas aparentemente, o erro está dizendo que ele espera um identificador e isso significa que ele precisa de um nome para a função, método, union, struct, variavel e etc...

O que eu notei é que somente o seu union não tem um nome de identificador:
Código: Selecionar todos
typedef union
{ unsigned int i;
  float f;
} value;



mude para
Código: Selecionar todos
typedef union VALUE
{ unsigned int i;
  float f;
} value;


E tente novamente. Tenho quase certeza que o problema não é na sua função e sim alguma coisa antes dela. Isso ocorre muito quando se esquece uma , ou um ; ou ainda uma }, mas não seria esse o caso já que é a primeira função.

Outra dica é vc simplesmente apagar tudo que está acima desse código e deixar apenas o include do pic e ver se o erro dá em outro lugar. Se sim, com certeza é problema do código acima. Neste caso, vc pode ir apagando linha por linha até achar o erro. :)

[]'s
Avatar do usuário
joao
Byte
 
Mensagens: 463
Registrado em: 17 Out 2006 08:21

Mensagempor amboni » 19 Ago 2008 08:33

Joao...

coloquei o nome de função no struct.....
ai fui seguindo a sua dica de ir apagando (novamente).....

e entao qndo colocava o a linah abaixo em comentario:

Código: Selecionar todos
#define noACK 0
//#define ACK   1


ele gerava outro erro... mais de identificador indefinido.... ACK...

Pera..pera...pera..pera... tive uma ideia...
por incrivel que pareça....

coloquei assim e compilou....

Código: Selecionar todos
//#define noACK 0
//#define ACK   1
CHAR ACK=1;
CHAR NOACK=0;


não sei o que dizer a respeito....
amboni
Nibble
 
Mensagens: 50
Registrado em: 23 Abr 2008 08:26
Localização: Içara - SC

Mensagempor andre_luis » 19 Ago 2008 08:48

Aparentemente o compilador não faz um casting implicito.
Trabalhar com variável é ligeiramente mais lento que trabalhar com constante.

Voce poderia tentar fazer o seguinte :
Código: Selecionar todos
#define   noACK     (CHAR)0
#define     ACK     (CHAR)1


Apenas pra tirar essa dúvida.

ou, se não funcionar, ao menos :

Código: Selecionar todos
const CHAR ACK=1;
const CHAR NOACK=0;


+++
"Por maior que seja o buraco em que você se encontra, relaxe, porque ainda não há terra em cima."
Avatar do usuário
andre_luis
Dword
 
Mensagens: 5447
Registrado em: 11 Out 2006 18:27
Localização: Brasil - RJ

Mensagempor joao » 19 Ago 2008 09:32

Como as coisas ficam mais simples né!

O andre tem razão, vc está tentando passar uma variável que é 0 ou 1 para uma função que está esperando um char.

Código: Selecionar todos
  *(p_value+1)=s_read_byte(ACK);    //read the second byte (LSB)
  *(p_value)  =s_read_byte(ACK);    //read the first byte (MSB)


quem sabe, fazendo o cast aqui:


Código: Selecionar todos
  *(p_value+1)=s_read_byte((unsigned char)ACK);    //read the second byte (LSB)
  *(p_value)  =s_read_byte((unsigned char)ACK);    //read the first byte (MSB)


Já está resolvido.

Isso também pode ser melhorado, desde que exista boolean no CCS. Se alguém puder responder, seria legal, pois o código fica muito mais entendivel, se ao invés de vc ter um parametro unsigned char, vc teria um boolean.


Mas o importante é que a bagaça tá funfando! :) :) :)

[]'s
Avatar do usuário
joao
Byte
 
Mensagens: 463
Registrado em: 17 Out 2006 08:21

Próximo

Voltar para PIC

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

x