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] illegal conversion between types int -> struct

Status
Not open for further replies.

7ezhil7

Junior Member level 2
Joined
Mar 31, 2016
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
214
Hi,
I am trying to reuse a code for different pins in pic16f877a.For that i have use structure concept in C.I haven't completed my program.As I was a begginer to structures concept I compiled it for any syntax errors.I got [illegal conversion between types int -> struct DHT11] error.

Code:
#define _XTAL_FREQ 10000000
#include<htc.h>
#include<stdio.h>
struct DHT11
{
unsigned char pin;
volatile unsigned char *port;
volatile unsigned char *tris;
}
checkhigh(struct DHT11 *POS)
{
  char say = 0;		//waitforhigh

    while(!POS->pin) {
        say++;
        __delay_us(1);
        
        if(say > 100)return 0;
    }      

void main()
{
struct DHT11 OUT;
OUT.pin = 0;
OUT.port = &PORTA;
OUT.tris  = &TRISA;
}

I would like to know why this error arises also whether my method to reuse code for different pins would work or not.
THANKS IN ADVANCE.
 

Code:
#define _XTAL_FREQ 10000000
#include<htc.h>
#include<stdio.h>

//declare function
char checkhigh(DHT11StructTypeDef * POS);

//declare struct type definition
typedef struct
{
unsigned char pin;
volatile unsigned char *port;
volatile unsigned char *tris;
}DHT11StructTypeDef;

char checkhigh(DHT11StructTypeDef * POS)
{
  char say = 0;		//waitforhigh

    while(!(POS->port & POS->pin)) 
    {
        say++;
        __delay_us(1);
        
        if (say > 100) return 0;
    }  
 return 1;    
}

void main()
{
char Result;
DHT11StructTypeDef DHT11;
DHT11.pin = 0;
DHT11.port = &PORTA;
DHT11.tris  = &TRISA;

Result = checkhigh(&DHT11);
}
 
Thank you for your reply sir,
I tried my code as per your suggestion.But I got error [type conflict] at while loop i.e.while(!(POS->port & POS->pin)) . I dont know why we are using (POS->port & POS->pin) rather than using POS->pin only.Also What is the use of variable 'Result'.
Please clarify my doubts sir.
 

Try this:

volatile unsigned char *port;
volatile unsigned char *tris;
shuld be
char *port;
char *tris;


and

POS->port shuld be converted to value of pointer, not a pointer. I cant push my head working this morning, sorry
POS->port & POS->pin we are using because we are taking value of register and applying bit mask 'pin' to get only one pin value.
 
Hi 7ezhil7,

Obviously your code is not complete.
As a first step, and before trying to complete and later to improve the code, it should be clear why the compiler is giving syntax errors.

Syntax issues in your code (maybe there are other problems) are:
a) missing semicolon at the end of the definition of the struct
b) missing closing bracket for the function

Not necessarily a syntax error, but needed is:
c) return value outside the while loop

Code:
...
struct DHT11
{
unsigned char pin;
volatile unsigned char *port;
volatile unsigned char *tris;
}[COLOR="#FF0000"][B];[/B][/COLOR]

checkhigh(struct DHT11 *POS)
{
  char say = 0;		//waitforhigh

    while(!POS->pin) {
        say++;
        __delay_us(1);
        
        if(say > 100)return 0;
    }      
    [COLOR="#008000"][B]return 1;[/B][/COLOR]
[COLOR="#FF0000"][B]}[/B][/COLOR]
...
 

Just tested. Works! I forgot that port is a pointer, not a variable.
Code:
//declare struct type definition
typedef struct
{
  unsigned char pin;
  volatile unsigned char *port;
  volatile unsigned char *tris;
}DHT11StructTypeDef;

//declare function
char checkhigh(DHT11StructTypeDef * POS);

void main() 
{
  char Result;
  DHT11StructTypeDef DHT11;
  DHT11.pin = 0;
  DHT11.port = &PORTA;
  DHT11.tris  = &TRISA;

  Result = checkhigh(&DHT11);
}


char checkhigh(DHT11StructTypeDef * POS)
{
  char say = 0;		//waitforhigh

    while(!(*POS->port & POS->pin))
    {
        say++;
        __delay_us(1);

        if (say > 100) return 0;
    }
 return 1;
}
 
Last edited:
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top