Blink LED green & red to display the binary number input by push buttons in binary format

Viewed 33

A cool example for the Renesas Synergy SK-S7G2 to try out without a Board support package. I think its worth it to point it out.

This is not a question, more a summary about the example with the code for future users.

The LED circuit (page 12 in Schematic). Green LED is connected to signal 00 of Port6. enter image description here

The Port6 address: 0x400400C0 With low voltage (0) we can turn the green LED on, and with high voltage (1) off. This is managed by bit 16 PODR 00 of the Port6 control register 1 PCNTR1 with the address 0x400400C0. Page 451 user manual. enter image description here

Configure Port6 as output so microcontroller sends a signal to port6. Write the data to Port6 Control Register 1. The program uses the green and red LEDs to display the binary number input by push buttons S4 and S5 in binary format.

1 Answers

The code. Feedback for code optimization or other ideas welcome!

#define P6CTR1 (*(volatile unsigned long *) 0x400400c0)
#define P0CTR1 (*(volatile unsigned long *) 0x40040000)
#define P0CTR2 (*(volatile unsigned long *) 0x40040004)

void hal_entry(void)
{
    unsigned long v1;
    //I/O Initialization
    P6CTR1 = 0xFFFFFFFF; // 400400C0, FFFFFFFF
    P0CTR1 = 0x0; //40040000, 00000000

    while(1)
    {
        v1 = P0CTR2;
        v1 &= 0x060;

        switch(v1)
        {
            case 0x0060 : P6CTR1 = 0x0007FFFF;
                break;
            case 0x0020 : P6CTR1 = 0x0006FFFF; //turns green LED on
                break;
            case 0x0040 : P6CTR1 = 0x0005FFFF; //turns red LED on 
                break;
            case 0 : P6CTR1 = 0x0004FFFF;
        }

    }

}
Related