typedef union{
uint8_t val;
struct{
uint8_t b0 :1;
uint8_t b1 :1;
uint8_t b2 :1;
uint8_t b3 :1;
uint8_t b4 :1;
uint8_t b5 :1;
uint8_t b6 :1;
uint8_t b7 :1;
};
}uint8_bits;
void main(void){
uint8_bits union_t;
union_t.val = 48;
}
union_t.b6 = true; //false
typedef union{
uint8_t val;
struct{
uint8_t b0 :1;
uint8_t b1 :1;
uint8_t b2 :1;
uint8_t b3 :1;
uint8_t b4 :1;
uint8_t b5 :1;
uint8_t b6 :1;
uint8_t b7 :1;
};
}uint8_bits;
void main(void){
uint8_bits union_t;
union_t = 48;
}
Una pregunta, ¿uint8_t es algún tipo que hayas definido con anterioridad? Porque quise compilar tu código con HiTech -que supuestamente es ANSI C- y me tiró varios errores.
typedef unsigned char uint8_t;
/********************************************************************************
* Copyright (c) 2010 Julian Ramirez "pandemonium"
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************
* generic_types.h
*
* COMENTARIOS: Implementacion de macros y definiciones para estandarizar
* tipos de datos para el uso de fuciones con multiples
* compiladores.
*
*
**************************************************************************
* Programador: Julián Ramirez "pandemonium".
* Compiladores: CCS PCWHD C, HITECH C, C18, C30, MIKROC.
* Dependencias: no.
* Procesadores: PIC12*, PIC16*, PIC18*, PIC24*, dsPIC.
*
* Cambios Historia:
* Rev Fecha Descripcion
* 1.0 03/01/10 Definicion de tipos de datos genericos y tablas de bits
*
**************************************************************************/
#ifndef __GENERIC_TYPES_H_
#define __GENERIC_TYPES_H_
#endif
/* obtener los tipos da datos especificos del compilador (NULL, size_t, etc) */
#if !defined(__MIKROC_PRO_FOR_PIC__)
#include <stddef.h>
#endif
#define void VOID
#define PRIVATE static
#if defined(__PICC__) /* HT-PICC10/12/16 */
typedef bit boolean_t;
typedef signed char char_t, int8_t;
typedef signed int int_t, int16_t;
typedef signed short short_t;
typedef signed short long short_long_t, int24_t;
typedef signed long long_t, int32_t;
typedef float float_t;
typedef double double_t;
typedef unsigned char uchar_t, uint8_t;
typedef unsigned int uint_t, uint16_t;
typedef unsigned short ushort_t, d_word;
typedef unsigned short long ushort_long_t, uint24_t;
typedef unsigned long ulong_t, uint32_t, q_word;
//------------------------------------------------------------------------------
#elif defined(__PICC18__) /* HT-PICC18 */
typedef bit boolean_t;
typedef signed char char_t, int8_t;
typedef signed int int_t, int16_t;
typedef signed short short_t;
typedef signed short long short_long_t, int24_t;
typedef signed long long_t, int32_t;
typedef float float_t;
typedef double double_t;
typedef unsigned char uchar_t, uint8_t;
typedef unsigned int uint_t, uint16_t;
typedef unsigned short ushort_t, d_word;
typedef unsigned short long ushort_long_t, uint24_t;
typedef unsigned long ulong_t, uint32_t, q_word;
//------------------------------------------------------------------------------
#elif defined(__18CXX) /* Microchip C18 */
typedef signed char char_t, int8_t;
typedef signed int int_t, int16_t;
typedef signed short short_t;
typedef signed short long int24_t;
typedef signed long long_t, int32_t;
typedef float float_t;
typedef unsigned char uchar_t, uint8_t;
typedef unsigned int uint_t, uint16_t;
typedef unsigned short ushort_t, d_word;
typedef unsigned short long uint24_t;
typedef unsigned long ulong_t, uint32_t, q_word;
//------------------------------------------------------------------------------
#elif defined(__C30__) /* Microchip C30 */
typedef signed char char_t, int8_t;
typedef signed int int_t, int16_t;
typedef signed short short_t;
typedef signed long long_t, int32_t;
typedef signed long long long_long_t, int64_t;
typedef float float_t;
typedef long double double_t;
typedef unsigned char uchar_t, uint8_t;
typedef unsigned int uint_t, uint16_t;
typedef unsigned short ushort_t, d_word;
typedef unsigned long ulong_t, uint32_t, q_word;
typedef unsigned long long ulong_long_t, uint64_t;
//------------------------------------------------------------------------------
#elif defined(__PCB__) || defined(__PCM__) || defined(__PCH__) /* CCS para PIC18 o PIC16 */
typedef int1 boolean_t;
typedef signed char char_t;
typedef signed int int8_t;
typedef signed long int_t, int16_t, short_t;
typedef signed long long long_t, int32_t;
typedef float float_t;
typedef unsigned char uchar_t;
typedef unsigned int uint8_t;
typedef unsigned long uint_t, uint16_t, ushort_t, d_word;
typedef unsigned long long ulong_t, uint32_t, q_word;
//------------------------------------------------------------------------------
#elif defined(__PCD__)
typedef signed char char_t;
typedef signed short int8_t;
typedef signed int int_t, int16_t, short_t;
typedef signed long long_t, int32_t;
typedef signed long long long_long_t, int64_t;
typedef float float_t;
typedef long double double_t;
typedef unsigned char uchar_t;
typedef unsigned short uint8_t;
typedef unsigned int uint_t, uint16_t, ushort_t, d_word;
typedef unsigned long ulong_t, uint32_t, q_word;
typedef unsigned long long ulong_long_t, uint64_t;
//------------------------------------------------------------------------------
#elif defined(__MIKROC_PRO_FOR_PIC__)
typedef signed char char_t;
typedef signed short int8_t;
typedef signed int int_t, int16_t, short_t;
typedef signed long int long_t, int32_t;
typedef float float_t;
typedef double double_t;
typedef unsigned char uchar_t;
typedef unsigned short uint8_t;
typedef unsigned int uint_t, uint16_t, ushort_t, d_word;
typedef unsigned long int ulong_t, uint32_t, q_word;
//------------------------------------------------------------------------------
//#elif defined(__AVR__)
//------------------------------------------------------------------------------
//#elif defined(__ICCAVR__)
//------------------------------------------------------------------------------
#endif
#if defined(__C18xx) || defined(__C30__) || defined(__PCD__)
#ifdef false
#undef false
#endif
#ifdef true
#undef true
#endif
typedef enum _BOOL{ false=0, true} boolean_t; // Undefined size
typedef enum _BIT{ clear=0, set} bit_t;
#define false 0
#define true 1
#endif
#if defined(__MIKROC_PRO_FOR_PIC__)
typedef enum _BOOL{ false_t=0, true_t} boolean_t; // Undefined size
typedef enum _BIT{ clear_t=0, set_t} bit_t;
#endif
typedef union{
uint8_t data;
struct{
uint8_t b0 :1;
uint8_t b1 :1;
uint8_t b2 :1;
uint8_t b3 :1;
uint8_t b4 :1;
uint8_t b5 :1;
uint8_t b6 :1;
uint8_t b7 :1;
};
}uint8_bits;
typedef union{
uint16_t dword;
uint8_t a_byte[2];
struct{
uint8_t byte_0;
uint8_t byte_1;
};
struct{
uint8_t b0 :1;
uint8_t b1 :1;
uint8_t b2 :1;
uint8_t b3 :1;
uint8_t b4 :1;
uint8_t b5 :1;
uint8_t b6 :1;
uint8_t b7 :1;
uint8_t b8 :1;
uint8_t b9 :1;
uint8_t b10 :1;
uint8_t b11 :1;
uint8_t b12 :1;
uint8_t b13 :1;
uint8_t b14 :1;
uint8_t b15 :1;
};
}uint16_bits;
typedef union{
uint32_t qword;
uint16_t dword[2];
uint8_t a_byte[4];
struct{
uint16_t l_word;
uint16_t h_word;
};
struct{
uint8_t byte_0;
uint8_t byte_1;
uint8_t byte_2;
uint8_t byte_3;
};
struct{
uint8_t b0 :1;
uint8_t b1 :1;
uint8_t b2 :1;
uint8_t b3 :1;
uint8_t b4 :1;
uint8_t b5 :1;
uint8_t b6 :1;
uint8_t b7 :1;
uint8_t b8 :1;
uint8_t b9 :1;
uint8_t b10 :1;
uint8_t b11 :1;
uint8_t b12 :1;
uint8_t b13 :1;
uint8_t b14 :1;
uint8_t b15 :1;
uint8_t b16 :1;
uint8_t b17 :1;
uint8_t b18 :1;
uint8_t b19 :1;
uint8_t b20 :1;
uint8_t b21 :1;
uint8_t b22 :1;
uint8_t b23 :1;
uint8_t b24 :1;
uint8_t b25 :1;
uint8_t b26 :1;
uint8_t b27 :1;
uint8_t b28 :1;
uint8_t b29 :1;
uint8_t b30 :1;
uint8_t b31 :1;
};
}uint32_bits;
//-------------------------------------------------------------------
#define P1Mas LATAbits.LATA4
#define P1Menos LATAbits.LATA5
#define P2Mas LATAbits.LATA6
#define P2Menos LATAbits.LATA7
union
{
unsigned char motor;
struct
{
unsigned P1Mas:1;
unsigned P1Menos:1;
unsigned P2Mas:1;
unsigned P2Menos:1;
unsigned :4;
}
}PaP;
Hola Suky, gracias por el dato, contesté eso porque ANSI C no soporta estructuras anónimas y creía que el C18 era mas ANSI que CCS.Por suerte si lo soporta! :D Y C18 es muuuucho más ANSI C que CCS ;-)
Saludos !
#define P1Menos1 LATAbits.PAPA.P1menos