• AVR Freaks

AnsweredHot!I can't create a structure for managing several pins of different ports like one port.

Author
vra
Junior Member
  • Total Posts : 110
  • Reward points : 0
  • Joined: 2014/07/14 18:35:19
  • Location: 0
  • Status: offline
2019/07/18 12:54:33 (permalink)
0

I can't create a structure for managing several pins of different ports like one port.

Hi all, I'm using a PIC24EP and I want to write values on different port pins  like those pins in different ports like there was one port, the subject of this is to manage a four caracter seven segment display and I'm looking to do that in this way because the proximity of the pins and I don't have the posibility to make multi layer PCBs, so:
 
mi header file is the following until now is the following:
 

#ifndef LCD_CUATRO_SEG_H
#define LCD_CUATRO_SEG_H
//Definiciones de pines de variables.

// Terminales de control para los cuatro controladores 74XX47.
#define LT PORTDbits.RD7
#define RBI PORTDbits.RD6
#define BI3 PORTBbits.RB0
#define BI2 PORTBbits.RB1
#define BI1 PORTBbits.RB2
#define BI0 PORTBbits.RB3
// Terminales de datos BCD para los controladores 74XX47.
#define D PORTBbits.RB4
#define C PORTBbits.RB5
#define B PORTEbits.RE9
#define A PORTEbits.RE8
//Puntos del display.
#define P3 PORTAbits.RA9
#define P2 PORTAbits.RA10
#define P1 PORTBbits.RB8
#define P0 PORTBbits.RB9
/* Definiciones de estructura para manejar los pines del puerto para el display
* LCD de cuatro caracteres como un solo dato. */
typedef struct LCD_cuatro
{
extern unsigned int A:1;
extern unsigned int B:1;

} LCD_cuatro_car;
//Prototipo de funciones.
void Imprimir_Dato(unsigned int dato); //Función para mostrar los datos en el
//display.
void Cont_Pantalla(unsigned short porc);//Función para variar el contraste del
//display.
void Activa_Display(short pos,unsigned short data);//Función para activar el caracter a
//imprimir. La función se utilizará
//también para probar el display
//completo y apagarlo.
void Espera_Display(short tiempo); //Función para mostrar pantalla de
//espera en el diplay.
#endif /* LCD_CUATRO_SEG_H */

 
like you see I've wrote several #defines for naming some port pins like the pins that I wanna control in the display, then I've created the structure that follows (there are several definitions not made yet):
 

typedef struct LCD_cuatro
{
extern unsigned int A:1;
extern unsigned int B:1;

} LCD_cuatro_car;

 
but it gives me the same error on both declarations which is
 

LCD_cuatro_seg.h:50:5: error: expected specifier-qualifier-list before 'extern'

 
it seems like is trying to get the definition of the variable outside the structure (the extern word) but I taught that like PORTEbits.RE8 was already defined then I didn't need the definition but I obviously wrong, then, how can I make this works?.
 
NOTE: I was trying to create something like the Port definitions in the PIC header file.
#1
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11421
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: I can't create a structure for managing several pins of different ports like one port. 2019/07/18 13:06:30 (permalink) ☼ Best Answerby vra 2019/07/18 13:24:43
#2
du00000001
Just Some Member
  • Total Posts : 3230
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: I can't create a structure for managing several pins of different ports like one port. 2019/07/18 13:12:22 (permalink)
+3 (3)
vra
I can't create ...

We can't either. Because it's impossible.
 
The PIC headers are different insofar as each struct stays within the limits of a byte (or a number of subsequent bytes). And C's bit-fields are limited to . . . exactly these byte (sequence)s..
 
Others tried the same - failing too. There are a lot of threads on this topic in these forums...
 
@ jtemples
Thanks for providing this link. (I'm somewhat lazy with digging up references.) 😊
post edited by du00000001 - 2019/07/18 13:15:03

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#3
vra
Junior Member
  • Total Posts : 110
  • Reward points : 0
  • Joined: 2014/07/14 18:35:19
  • Location: 0
  • Status: offline
Re: I can't create a structure for managing several pins of different ports like one port. 2019/07/18 13:24:17 (permalink)
+1 (1)
jtemples
http://www.xargs.com/pic/c-faq.html#pinremap


Yes, thank you so much for the link
#4
malaugh
Super Member
  • Total Posts : 400
  • Reward points : 0
  • Joined: 2011/03/31 14:04:42
  • Location: San Diego
  • Status: offline
Re: I can't create a structure for managing several pins of different ports like one port. 2019/07/18 15:52:50 (permalink)
+1 (1)
As other posters have said, you cannot do this with bit addresses, but you can do this with byte addresses
 
I do this with my LCD display, defining the segment addresses as an address and a bitmask.
Here is a snippet of the code.
 
You can get the addresses of each of the CPU registers from the header file
 

typedef const struct
{
UINT8 *LcdAddress;
UINT8 LcdMask;
} LCD_SEGMENT_ENTRY;
LCD_SEGMENT_ENTRY Lcd_RightNumericSegments[] =
{ /* Digit 1 */
/* a */ { (UINT8*)0xf7d, (1 << 7) }, /* C4 S03 */
/* b */ { (UINT8*)0xf78, (1 << 0) }, /* C4 S04 */
/* c */ { (UINT8*)0xf6c, (1 << 0) }, /* C2 S04 */
/* d */ { (UINT8*)0xf6b, (1 << 7) }, /* C1 S03 */
/* e */ { (UINT8*)0xf71, (1 << 7) }, /* C2 S03 */
/* f */ { (UINT8*)0xf77, (1 << 7) }, /* C3 S03 */
/* g */ { (UINT8*)0xf72, (1 << 0) }, /* C3 S04 */
};
#define LCD_SEGMENT_TABLE_SIZE (sizeof(Lcd_RightNumericSegments) / sizeof(LCD_SEGMENT_ENTRY))
LCD_SEGMENT_ENTRY Lcd_LeftNumericSegments[] =
{ /* Digit 2 */
/* a */ { (UINT8*)0xf7d, (1 << 5) }, /* C4 S01 */
/* b */ { (UINT8*)0xf7d, (1 << 6) }, /* C4 S02 */
/* c */ { (UINT8*)0xf71, (1 << 6) }, /* C2 S02 */
/* d */ { (UINT8*)0xf6b, (1 << 5) }, /* C1 S01 */
/* e */ { (UINT8*)0xf71, (1 << 5) }, /* C2 S01 */
/* f */ { (UINT8*)0xf77, (1 << 5) }, /* C3 S01 */
/* g */ { (UINT8*)0xf77, (1 << 6) }, /* C3 S02 */
};
/*****************************************************************************************
* FUNCTION: LcdDigit_Display
*
* DESCRIPTION: Display a single character on one of the 7 segment displays
*
* PARAMETERS: Digit - ASCII representation of character
* LcdTable - Table matching segment with bit position
*
* RETURN: None
*****************************************************************************************/
void LcdDigit_Display( char Digit, LCD_SEGMENT_ENTRY *SegmentTable)
{
UINT8 Segments;
UINT8 i;

if(Digit >= '0' && Digit <= '9')
{
Segments = LcdDigits_SevenSegTable[Digit - '0'];
}
else if (Digit >= 'A' && Digit <= 'F')
{
Segments = LcdDigits_SevenSegTable[Digit - 'A' + 0x0A];
}
else if (Digit >= 'a' && Digit <= 'f')
{
Segments = LcdDigits_SevenSegTable[Digit - 'a' + 0x0A];
}
else if (Digit == ' ')
{
Segments = LcdDigits_SevenSegTable[SPACE_INDEX];
}
else if (Digit == 'I' || Digit == 'i')
{
Segments = LcdDigits_SevenSegTable[I_INDEX];
}
else if (Digit == 'L' || Digit == 'l')
{
Segments = LcdDigits_SevenSegTable[L_INDEX];
}
else if (Digit == 'N' || Digit == 'n')
{
Segments = LcdDigits_SevenSegTable[N_INDEX];
}
else if (Digit == 'P' || Digit == 'p')
{
Segments = LcdDigits_SevenSegTable[P_INDEX];
}
else if (Digit == 'R' || Digit == 'r')
{
Segments = LcdDigits_SevenSegTable[R_INDEX];
}
else if (Digit == '#')
{
Segments = LcdDigits_SevenSegTable[HASH_INDEX];
}
else if (Digit == '-')
{
Segments = LcdDigits_SevenSegTable[MINUS_INDEX];
}
else
{
return;
}

for( i = 0; i < LCD_SEGMENT_TABLE_SIZE; i++)
{
if(Segments & 1)
{
*(SegmentTable[i].LcdAddress) |= SegmentTable[i].LcdMask;
}
else
{
*(SegmentTable[i].LcdAddress) &= ~SegmentTable[i].LcdMask;
}
Segments >>= 1;
}
}

#5
mlp
boots too small
  • Total Posts : 825
  • Reward points : 0
  • Joined: 2012/09/10 15:12:07
  • Location: previously Microchip XC8 team
  • Status: offline
Re: I can't create a structure for managing several pins of different ports like one port. 2019/07/19 09:58:54 (permalink)
0
malaugh
but you can do this with byte addresses

Just don't complain that the resulting code is horribly inefficient. PIC 8- and 16-bit architectures are somewhat pointer-unfriendly.

Mark (this opinion available for hire)
#6
Jump to:
© 2019 APG vNext Commercial Version 4.5