This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

# Set blinking LED with direct register access

Hi, I just did the "create blinky project (e² studio)" with the Renesas Video.

How can I get the same result with writing into registers?
I use the S7G2.

Parents
• Here are some useful macros for direct pin access.

//------------------------------------------------------------------------------
// Direct pin access for Synergy:
//------------------------------------------------------------------------------
#define _PIN_OUTPUT(p,b) {R_PORT##p->PCNTR1 |=(uint32_t) (1<<(b)) ;} // Bit PDR = 1
#define _PIN_INPUT(p,b) {R_PORT##p->PCNTR1 &=(uint32_t)(~(1<<(b)));} // Bit PDR = 0
#define _CHK_CLR(p,b) ((R_PORT##p->PCNTR2 & (uint32_t)(1<<((b) )))==0) // Bit PIDR == 0 ?
#define _CHK_SET(p,b) ((R_PORT##p->PCNTR2 & (uint32_t)(1<<((b) )))!=0) // Bit PIDR != 0 ?
#define _CLR_PIN(p,b) {R_PORT##p->PCNTR3 = (uint32_t)(1<<((b)+16));} // Bit PORR = 1
#define _CLR_PINS(p,msk) {R_PORT##p->PCNTR3 = (uint32_t)((msk)<<16) ;} // Bits PORR = 1
#define _SET_PIN(p,b) {R_PORT##p->PCNTR3 = (uint32_t)(1<<((b) ));} // Bit POSR = 1
#define _SET_PINS(p,msk) {R_PORT##p->PCNTR3 = (uint32_t)(msk); } // Bits POSR = 1
#define _SWITCH_PIN(p,b) {R_PORT##p->PCNTR1 ^= (uint32_t)(1<<((b)+16));} // Bit PODR ^= 1

You just put the port in 'p' and the pin in 'b'. For example, to set the pin 7 of PORT2 you can use

_SET_PIN(2, 7);

Or, if you have a green led in PORT6.0 you can define

#define _Green_Led()   _CHK_CLR(6,0) // (P6.0==0) returns status of the green led
#define _Green_Led_Switch()   _SWITCH_PIN(6,0) // P6.0 ^= 1;
#define _Green_Led_On()   _CLR_PIN(6,0) // P6.0= 0;
#define _Green_Led_Off()   _SET_PIN(6,0) // P6.0= 1;

and use those macros directly in your source code.

• Here are some useful macros for direct pin access.

//------------------------------------------------------------------------------
// Direct pin access for Synergy:
//------------------------------------------------------------------------------
#define _PIN_OUTPUT(p,b) {R_PORT##p->PCNTR1 |=(uint32_t) (1<<(b)) ;} // Bit PDR = 1
#define _PIN_INPUT(p,b) {R_PORT##p->PCNTR1 &=(uint32_t)(~(1<<(b)));} // Bit PDR = 0
#define _CHK_CLR(p,b) ((R_PORT##p->PCNTR2 & (uint32_t)(1<<((b) )))==0) // Bit PIDR == 0 ?
#define _CHK_SET(p,b) ((R_PORT##p->PCNTR2 & (uint32_t)(1<<((b) )))!=0) // Bit PIDR != 0 ?
#define _CLR_PIN(p,b) {R_PORT##p->PCNTR3 = (uint32_t)(1<<((b)+16));} // Bit PORR = 1
#define _CLR_PINS(p,msk) {R_PORT##p->PCNTR3 = (uint32_t)((msk)<<16) ;} // Bits PORR = 1
#define _SET_PIN(p,b) {R_PORT##p->PCNTR3 = (uint32_t)(1<<((b) ));} // Bit POSR = 1
#define _SET_PINS(p,msk) {R_PORT##p->PCNTR3 = (uint32_t)(msk); } // Bits POSR = 1
#define _SWITCH_PIN(p,b) {R_PORT##p->PCNTR1 ^= (uint32_t)(1<<((b)+16));} // Bit PODR ^= 1

You just put the port in 'p' and the pin in 'b'. For example, to set the pin 7 of PORT2 you can use

_SET_PIN(2, 7);

Or, if you have a green led in PORT6.0 you can define

#define _Green_Led()   _CHK_CLR(6,0) // (P6.0==0) returns status of the green led
#define _Green_Led_Switch()   _SWITCH_PIN(6,0) // P6.0 ^= 1;
#define _Green_Led_On()   _CLR_PIN(6,0) // P6.0= 0;
#define _Green_Led_Off()   _SET_PIN(6,0) // P6.0= 1;

and use those macros directly in your source code.

Children
No Data