#define KEY_ON 1
#define KEY_OFF 0
uint32_t Key_Scan(bsp_io_port_pin_t key)
{
bsp_io_level_t state;
R_IOPORT_PinRead(&g_ioport_ctrl, key, &state);
if (BSP_IO_LEVEL_HIGH == state)
{
return KEY_OFF;
}
else
{
do
{
R_IOPORT_PinRead(&g_ioport_ctrl, key, &state);
} while (BSP_IO_LEVEL_LOW == state);
}
return KEY_ON;
}
void hal_entry(void)
{
#define KEY1_SW2_PIN BSP_IO_PORT_00_PIN_04
#define KEY2_SW3_PIN BSP_IO_PORT_00_PIN_05
#define KEY3_SW2_PIN BSP_IO_PORT_06_PIN_00
#define KEY4_SW3_PIN BSP_IO_PORT_06_PIN_04
int player;
int computer;
int result;
int v;
R_BSP_PinAccessEnable();
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
}
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
}
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
}
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
}
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
}
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
}
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
}
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
}
player = 0;
while(player == 0) {
if( Key_Scan(KEY1_SW2_PIN) == KEY_ON )
{
player = 1;
}
if( Key_Scan(KEY2_SW3_PIN) == KEY_ON )
{
player = 2 ;
}
if( Key_Scan(KEY3_SW2_PIN) == KEY_ON )
{
player = 3;
}
if( Key_Scan(KEY4_SW3_PIN) == KEY_ON )
{
player = 4 ;
}
}
computer = player;
switch (computer) {
case 1:
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
}
break;
case 2:
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
}
break;
case 3:
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
}
break;
case 4:
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
}
break;
}
if ( (player == computer) || (player == 1 && computer == 4) ||
(player == 2 && computer == 3) ){
result = 0;
} else if ((player == 1 && computer == 3) ||
(player == 2 && computer == 1) ||
(player == 3 && computer == 4) ||
(player == 4 && computer == 2)) {
result = 1;
} else {
result = -1;
}
if (result == 0) {
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
}
} else if (result == 1) {
R_BSP_PinWrite(BSP_IO_PORT_08_PIN_06 , BSP_IO_LEVEL_HIGH);
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
}
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_08 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
}
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_06 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
}
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_07 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(19, BSP_DELAY_UNITS_MILLISECONDS);
}
R_BSP_PinWrite( BSP_IO_PORT_08_PIN_06 , BSP_IO_LEVEL_LOW);
} else {
R_BSP_PinWrite(BSP_IO_PORT_08_PIN_04 , BSP_IO_LEVEL_HIGH);
for ( v = 80; v > 40 ; v-- )
{
R_BSP_PinWrite(BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_HIGH);
R_BSP_SoftwareDelay(2, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_09_PIN_00 , BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(18, BSP_DELAY_UNITS_MILLISECONDS);
}
R_BSP_SoftwareDelay(200, BSP_DELAY_UNITS_MILLISECONDS);
R_BSP_PinWrite( BSP_IO_PORT_08_PIN_04 , BSP_IO_LEVEL_LOW);
}
#if BSP_TZ_SECURE_BUILD
R_BSP_NonSecureEnter();
#endif
}