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.

C program won't build..says STRUCT is required?

Status
Not open for further replies.
T

treez

Guest
Newbie level 1
Hello,
My XC8 c program won't build and the below function is being blamed...it says a STRUCT or UNION is required....

void read_dips(void){
dip8 = 0;
if (dip1pin) dipsw1 = 0x00;
else dipsw1 = 0x00;
if (dip2pin) dipsw2 = 0x00;
else dipsw2 = 0x00;
if (dip3pin) dipsw3 = 0x00;
else dipsw3 = 0x00;
if (dip4pin) dipsw4 = 0x00;
else dipsw4 = 0x00;
if (dip5pin) dipsw5 = 0x00;
else dipsw5 = 0x00;
if (dip8pin) dipsw8 = 0x00;
else dipsw8 = 0x00;

}

Please advise whats wrong?

Its the free XC8 C compiler from microchip, and using MPLAB.X, and target is pic18f65k22

the whole code is as follows...

// * File: 3CH TEST.c

//;Code for 3 channel led driver on the updated 550587 PCB
//;WE ARE TRUNCATING THE ADC REGISTER SO JUST USE UPPER 8 BITS
//
//;DEFINE INPUTS FROM DIPSWITCH
//;Note that the new board has pullups on the dipswitch,
//;whereas 550587 PCB had pull downs, thus logic is reversed.
//; XXX DIPSWITCH POLARITY:- XXX
//;DIP 1...ON = EXTERNAL CONNECTOR CONTROL
//;DIP 2...ON = LOGIC HIGH (note 'ON' gives a low input)
//;DIP 3...ON = LOGIC HIGH
//;DIP 4...OFF = 10V is for max current
//;DIP 5...OFF = 80degC, ON = 90degC
//;DIP 6... UNUSED
//;DIP 7... UNUSED
//;DIP 8...ON = NO FAN FITTED, OFF = FAN FITTED
//
//; XXX EXTERNAL CONTROL CONNECTOR POLARITY:- XXX
//;CLEAR = ACTIVE HIGH
//;RESET = ACTIVE HIGH
//;CH1...HIGH = ON, LOW = OFF
//;CH2...HIGH = ON, LOW = OFF
//;CH3...HIGH = ON, LOW = OFF
//
//;List of input ports:
//; ************** DIPSWITCH INPUTS:
//;DIP1 = RB0
//;DIP2 = RB1
//;DIP3 = RB2
//;DIP4 = RB3
//;DIP5 = RB4
//;DIP6 = RB5
//;DIP7 = RC5
//;DIP8 = RE6
//
//;************* External connector INPUTS:
//;clear = RC1
//;ch3 on/off = RC7
//;RESET = RD5
//;CH1 on/off = RD6
//;ch2 on/off = RD7
//
//;Other inputs (DIGITAL I/O
//;Fan tacho = RG2
//;mclr = RG5
//
//;Inputs that are ADC inputs:
//;RA2 = AN2
//;RA3 = AN3
//;RA5 = AN4 ADCON0=0x10
//;RF1 = AN6 ADCON0=0x18
//;RF2 = AN7
//;RF3 = AN8
//;RF4 = AN9
//;RF5 = AN10 ADCON0=0x28
//;RF6 = AN11 ADCON0=0x2C
//;RF7 = AN5 ADCON0=0x1C
//
//;**********ADC INPUTS:
//;AN0 = NC
//;AN1 = NC
//;AN2 = VREF- (0V)
//;AN3 = VREF+ (3V)
//;AN4 = Therm ch1
//;AN5 = I_CH1
//;AN6 = 0-10V control input
//;AN7 = PCB thermistor
//;AN8 = I_ch2
//;AN9 = I_ch3
//;AN10 = Therm-ch2
//;AN11 = Therm-ch3
//
//;OOOOOOOOOOO LIST OF OUTPUTS:
//;Trip = RA4
//;Indicator LED = RC2
//;MCP4013_CS = RC3
//;MCP4013_UD = RC4
//;Shutdown-Ch2 = RE0
//;Shutdown-Ch1 = RE1
//;Fancon PWM = RE2
//;Shutdown-Ch3 = RG0
//
//;NCNCNCNCNCNCNCNCNC LIST OF NON CONNECTED PINS:
//;RA0
//;RA1
//;RA6
//;RA7
//; RB6 = PGC
//; RB7 = PGD
//;RC0
//;RC6
//; RD0
//; RD1
//; RD2
//; RD3
//; RD4
//;RE3
//;RE4
//;RE5
//;RE7
//; RG1
//; RG3
//; RG4/*
#include <xc.h>

void set_ana_dig_ports(void);
void disable_interrupts(void);
void disable_pullups(void);
void disable_opendrain(void);
void disable_comparators(void);
void setup_adc(void);
void setup_ports(void);
void NC_pins_low(void); //make all NC pins low.
void read_dips(void);
//CONFIGS

/*DEFINE OUTPUTS*/
#define ch1out LATE,LATE1
#define ch2out LATE,LATE0
#define ch3out LATG,LATG0
#define ind_ledout LATC,LATC2
#define fanconout LATE,LATE2
#define tripout LATA,LATA4
#define mcp4013_csout LATC,LATC3
#define mcp4013_udout LATC,LATC4
//DIPSWITCH INPUTS
#define dip1pin PORTB.RB0
#define dip2pin PORTB.RB1
#define dip3pin PORTB.RB2
#define dip4pin PORTB.RB3
#define dip5pin PORTB.RB4
#define dip6pin PORTB.RB5
#define dip7pin PORTC.RC5
#define dip8pin PORTE.RE6

//DEFINE INPUTS FROM EXT. CONNECTOR
#define resetext PORTD.RD5
#define ch1ext PORTD.RD6
#define ch2ext PORTD.RD7
#define ch3ext PORTC.RC7
#define clearext PORTC.RC1

/* TURN LEDS ON AND OFF*/
#define ON1 LATE,LATE1 = 1; /*Turn on chan1*/
#define OFF1 LATE,LATE1 = 0; /*Turn off chan1*/
#define ON2 LATE,LATE0 = 1; /*Turn on chan2*/
#define OFF2 LATE,LATE0 = 0; /*Turn off chan2*/
#define ON3 LATG,LATG0 = 1; /*Turn on chan2*/
#define OFF3 LATG,LATG0 = 0; /*Turn off chan2*/
#define FANON LATE,LATE2 = 1; /*Turn fan on*/
#define FANOFF LATE,LATE2 = 0; /*Turn fan off*/

/*DEFINE INPUTS FROM DIPSWITCH*/
/*Note that the new board has pullups on the dipswitch,*/
/*whereas 550587 PCB had pull downs, thus logic is reversed.*/
unsigned int dipsw1;
unsigned int dipsw2;
unsigned int dipsw3;
unsigned int dipsw4;
unsigned int dipsw5;
unsigned int dipsw8;
unsigned int dip8; //bit0=dip1...
unsigned int dip8_init;
unsigned int ext5; //bit0=reset,bit1=ch1...etc, to bit4=clear
//external connector pins
unsigned int extbit3; //reset
unsigned int extbit4; //ch1
unsigned int extbit5; //ch2
unsigned int extbit6; //ch3
unsigned int extbit9; //an in
unsigned int extbit10; //clear
unsigned int extbit11; //TRIP OUT
unsigned int temp1;
unsigned int temp2;
unsigned int temp3;
unsigned int tempb;
unsigned int ana8; //holds ADRESH
unsigned int max_led_temp;
unsigned int max_pcb_temp;
unsigned int board_90c; //max board temp value
unsigned int board_80c;
unsigned int led_90c;
unsigned int led_80c; //max led temp value
unsigned int ledthermopen; //trip value when thermistor open
unsigned int pcbthermopen;
unsigned int current; //represents 0A, 1.76A, 2.64A, 3.52A
//bit0=0,bit1=1a76...etc
unsigned int iset_mcp4013; //numer of down pulses needed to get current.


void main(void) {
disable_interrupts();
disable_pullups();
disable_opendrain();
disable_comparators();
setup_adc();
setup_ports();
NC_pins_low(); //make all NC pins low.
OFF1;
OFF2;
OFF3;
FANOFF;

read_dips();

while(1){;}
return;
}

void set_ana_dig_ports(void){
ANCON0 = 0xFC;
ANCON1 = 0x0F;
ANCON2 = 0x00;
}
void disable_interrupts(void) {
INTCON =0x00;
INTCON2 =0x80;
INTCON3 = 0x00;
PIE1 = 0x00;
PIE2 = 0x00;
PIE3 = 0x00;
PIE4 = 0x00;
PIE5 = 0x00;
PIE6 = 0x00;
}
void disable_pullups(void){
PADCFG1 = 0;
}
void disable_opendrain(void){
ODCON1 = 0;
ODCON2 = 0;
ODCON3 = 0;
}
void disable_comparators(void){
CM1CON = 0;
CM2CON = 0;
CM3CON = 0;
}
void setup_adc(void){
ADCON0 = 0;
ADCON1 = 0x10; //VREF
ADCON2 = 0x3E; // Left jus/Tacq
}
void setup_ports(void){
TRISA = 0x2C;
TRISB = 0x3F;
TRISC = 0xA2;
TRISD = 0xD0;
TRISE = 0x40;
TRISF = 0xFE;
TRISG = 0x24;
}
void NC_pins_low(void){
//Make all NC pins low (they are already made to outputs)
//They are outputs for noise immunity reasons.
LATA,LATA0 = 0;
LATA,LATA1 = 0;
LATA,LATA6 = 0;
LATA,LATA7 = 0;

LATB,LATB6 = 0; //PGC
LATB,LATB7 = 0; //PGD

LATC,LATC0 = 0;
LATC,LATC6 = 0;

LATD,LATD0 = 0;
LATD,LATD1 = 0;
LATD,LATD2 = 0;
LATD,LATD3 = 0;
LATD,LATD4 = 0;

LATE,LATE3 = 0;
LATE,LATE4 = 0;
LATE,LATE5 = 0;
LATE,LATE7 = 0;

LATG,LATG1 = 0;
LATG,LATG3 = 0;
LATG,LATG4 = 0;
}
void read_dips(void){
dip8 = 0;
if (dip1pin) dipsw1 = 0x00;
else dipsw1 = 0x00;
if (dip2pin) dipsw2 = 0x00;
else dipsw2 = 0x00;
if (dip3pin) dipsw3 = 0x00;
else dipsw3 = 0x00;
if (dip4pin) dipsw4 = 0x00;
else dipsw4 = 0x00;
if (dip5pin) dipsw5 = 0x00;
else dipsw5 = 0x00;
if (dip8pin) dipsw8 = 0x00;
else dipsw8 = 0x00;

}
 

try defining the PORTB B bits so
Code:
//DIPSWITCH INPUTS
#define dip1pin PORTBbits.RB0
#define dip2pin PORTBbits.RB1
#define dip3pin PORTBbits.RB2
...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top