Mikroc Pro bug with unions?

Beta Testing discussion on mikroC PRO for PIC.
Post Reply
Author
Message
codepleb
Posts: 14
Joined: 14 Sep 2008 07:41
Location: Australia

Mikroc Pro bug with unions?

#1 Post by codepleb » 08 Feb 2010 03:57

I can compile the following 'joystick' code with Mikro C 8.2.0.0, but not with Mikro C Pro 3.2. Is it me or is there a bug re structures / unions in the Pro version (I just bought it - love it but I need to sort out this issue).

Pro version does not like instructions like "buttons.bit.B4=1", but 8.2.0.0. is OK with them.

Regards,

Codepleb

Code is as follows:

typedef struct
{
POV:4;
B4:1;
B5:1;
B6:1;
B7:1;
} byte_bits;

typedef union
{
unsigned char byte;
unsigned byte_bits;
} byte;

byte buttons;

char read[64],write[64];
unsigned char temp,pov;
char x_axis,y_axis,throttle=0;

void interrupt(void)
{
HID_InterruptProc();
}

void main(void)
{


buttons.byte=0;

//Initialize ports
TRISB=0xFF; //Set port B to inputs - Port B samples all the digital switches

HID_Enable(read,write);

while(1)
{
/////////////////////////////////
//Joystick buttons
/////////////////////////////////
//Button 1
if (PORTB.RB0)
buttons.bit.B4=1;
else
buttons.bit.B4=0;
//Button 2
if (PORTB.RB1)
buttons.bit.B5=1;
else
buttons.bit.B5=0;
//Button 3
if (PORTB.RB2)
buttons.bit.B6=1;
else
buttons.bit.B6=0;
//Button 4
if (PORTB.RB3)
buttons.bit.B7=1;
else
buttons.bit.B7=0;

///////////////////////////////////
//POV Hat
///////////////////////////////////
pov=Adc_Read(0)>>2;

buttons.bit.POV=4; //idle
if (pov<=193 && pov>=176) //Left
buttons.bit.POV=3;
if (pov<=175 && pov>=143) //Down
buttons.bit.POV=2;
if (pov<=142 && pov>=61) //Right
buttons.bit.POV=1;
if (pov<=60 && pov>=0) //Up
buttons.bit.POV=0;

///////////////////////////////
//Joystick Axes
x_axis=(Adc_Read(1)>>2)-128; //Read only the top 8-bits of the ADC
y_axis=(Adc_Read(2)>>2)-128;
throttle=(Adc_Read(3)>>2)-128;
//////////////////////////////
//USB
write[0]=throttle;
write[1]=x_axis;
write[2]=y_axis;
write[3]=buttons.byte;
write[4]=0xFF;

while(!HID_Write(write,4));

}
}

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: Mikroc Pro bug with unions?

#2 Post by tihomir.losic » 08 Feb 2010 18:39

codepleb wrote:Pro version does not like instructions like "buttons.bit.B4=1", but 8.2.0.0. is OK with them.
Hello,

in mikroC PRO (v3.2) you can use following instruction:

Code: Select all

PORTB.F4=1;
For other ways of defining bits in mikroC PRO, you need to open help file (F1),
and read about Accessing Individual Bits.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

codepleb
Posts: 14
Joined: 14 Sep 2008 07:41
Location: Australia

Re: Mikroc Pro bug with unions?

#3 Post by codepleb » 11 Feb 2010 09:49

Thanks.
I will work it out from the help file you suggested.

Regards,

codepleb

Post Reply

Return to “mikroC PRO for PIC Beta Testing”