Closed rbonghi closed 9 years ago
That doesn't refer to the register himself. The only ways to have a better mnemonic is to use a #define or to point to the physical address of the register. The first mode is strongly suggested because the producer of the compiler takes care of maintaining the right association between the registers addresses, that can change model by model, and their mnemonic definitions.
A possible way, that must be carefully tested, could be using a pointer variable that points to the address defined by the mnemonic definition.
Il giorno 14/gen/2015, alle ore 22:50, Raffaello Bonghi notifications@github.com ha scritto:
I implement a similar code, but doesn't work.
unsigned port = _LATC6; port = 1; @katodo https://github.com/katodo @guiott https://github.com/guiott — Reply to this email directly or view it on GitHub https://github.com/officinerobotiche/uNAV.X/pull/23#issuecomment-69999053.
I found this topic: http://www.microchip.com/forums/m593329.aspx
And I will try a similar solution Definition:
typedef struct led_control {
unsigned char * CS_PORT;
unsigned CS_pin :1;
unsigned int counter;
unsigned int wait;
short number_blink;
} led_control_t;
Declaration:
led_control_t led_controller[4];
Configuration:
led_controller[0].CS_PORT = &LATC;
led_controller[0].CS_pin = 6; //<-- To convert a bit number
Usage:
void BlinkController(led_control_t *led) {
*(led->CS_PORT) = *(led->CS_PORT) | ((1 << led->CS_Pin));
}
Do you agree? @guiott
It uses pointers as I suggested.
If I correctly understand it defines an array of structures where each LED is defined by the pointer to the relative PORT and the specific bit the LED is connected to. Specifying the index of the array you select the desired LED.
CLEVER!
Il giorno 15/gen/2015, alle ore 12:47, Raffaello Bonghi <notifications@github.com mailto:notifications@github.com> ha scritto:
I found this topic: http://www.microchip.com/forums/m593329.aspx http://www.microchip.com/forums/m593329.aspx And I will try a similar solution Definition:
typedef struct led_control { unsigned char * CS_PORT; unsigned CS_pin :1; unsigned int counter; unsigned int wait; short number_blink; } led_control_t;
Declaration:
led_control_t led_controller[4]; Configuration:
led_controller[0].CS_PORT = &LATC; led_controller[0].CS_pin = 6; //<-- To convert a bit number Usage:
void BlinkController(led_control_t led) { (led->CS_PORT) = *(led->CS_PORT) | ((1 << led->CS_Pin)); } Do you agree? @guiott https://github.com/guiott — Reply to this email directly or view it on GitHub https://github.com/officinerobotiche/uNAV.X/pull/23#issuecomment-70074735.
Yes! This is my idea!
If you see the code, I wrote the struct with basic information about blink: https://github.com/officinerobotiche/uNAV.X/blob/feature/led_blinks/includes/system/user.h#L36
and the blinkController function (to debug) https://github.com/officinerobotiche/uNAV.X/blob/feature/led_blinks/src/system/user.c#L253
And finally recall on Timer1 interrupt: https://github.com/officinerobotiche/uNAV.X/blob/feature/led_blinks/src/system/user.c#L253
I implement a similar code, but doesn't work.
@katodo @guiott