Code:
void main()
{
union
{
int Full;
struct
{
bit ADRES0;
bit ADRES1;
unsigned char ADRESH;
} Part;
}ADCValue;
int Value = ADCValue.Full;
}
Hi.. Above are some code for Hi-Tech C.
What I'm trying to do is to get the 10 bit ADC value in one go and store it in Value. I know that there is another way to do it ((ADRESH << 2) + (ADRESL >> 6)) but I'm also hoping to learn assign/read from different PIC registers in one go using union.
In C18, similar things can be done for PORT. the code below are found in PIC header file.
Code:
extern volatile near unsigned char PORTB;
extern volatile near union {
struct {
unsigned RB0:1;
unsigned RB1:1;
unsigned RB2:1;
unsigned RB3:1;
unsigned RB4:1;
unsigned RB5:1;
unsigned RB6:1;
unsigned RB7:1;
};
struct {
unsigned INT0:1;
unsigned INT1:1;
unsigned INT2:1;
};
struct {
unsigned AN12:1;
unsigned AN10:1;
unsigned AN8:1;
unsigned AN9:1;
unsigned AN11:1;
unsigned PGM:1;
unsigned PGC:1;
unsigned PGD:1;
};
struct {
unsigned :2;
unsigned VMO:1;
unsigned VPO:1;
unsigned KBI0:1;
unsigned KBI1:1;
unsigned KBI2:1;
unsigned KBI3:1;
};
} PORTBbits;
Any idea how I can do similar things in Hi-Tech C for ADC..? thanks alot.
Last edited: