/* Only if _stext routine is not used */
/*
#asm
sim // Disable interrupts
// To initialize the page 0
clrw x
loop0:
clr (x)
incw x
cpw x,#0x05FF
jrne loop0
#endasm
*/
unsigned char value = 100;
in_range = (value >= 10) && (value <= 20);
p_valid = ptr; /* p_valid is true if ptr not 0 */
CLK->CKDIVR = 0x00; // Main freq divided by 1 = Full Freq
TSL_Init();
ExtraCode_Init();
for (;;) {
ExtraCode_StateMachine();
TSL_Action();
}
}
/**
******************************************************************************
* @brief Initialize all the keys, I/Os for LED
* @par Parameters:
* None
* @retval void None
* @par Required preconditions:
* None
******************************************************************************
*/
void ExtraCode_Init(void)
{
u8 i;
/* All keys are implemented and enabled */
for (i = 0; i < NUMBER_OF_SINGLE_CHANNEL_KEYS; i++)
{
sSCKeyInfo[i].Setting.b.IMPLEMENTED = 1;
sSCKeyInfo[i].Setting.b.ENABLED = 1;
sSCKeyInfo[i].DESGroup = 0x01; /* Put 0x00 to disable the DES on these pins */
}
#if NUMBER_OF_MULTI_CHANNEL_KEYS > 0
for (i = 0; i < NUMBER_OF_MULTI_CHANNEL_KEYS; i++)
{
sMCKeyInfo[i].Setting.b.IMPLEMENTED = 1;
sMCKeyInfo[i].Setting.b.ENABLED = 1;
sMCKeyInfo[i].DESGroup = 0x01; /* Put 0x00 to disable the DES on these pins */
}
#endif
/* Init I/O in Output Push-Pull to drive the LED */
LED1_PORT_ODR |= LED1_PIN_MASK; /* LED1 is ON by default */
LED1_PORT_DDR |= LED1_PIN_MASK;
LED1_PORT_CR1 |= LED1_PIN_MASK;
Led1State = ON;
LED2_PORT_ODR |= LED2_PIN_MASK; /* LED1 is ON by default */
LED2_PORT_DDR |= LED2_PIN_MASK;
LED2_PORT_CR1 |= LED2_PIN_MASK;
Led2State = ON;
LED3_PORT_ODR |= LED3_PIN_MASK; /* LED1 is ON by default */
LED3_PORT_DDR |= LED3_PIN_MASK;
LED3_PORT_CR1 |= LED3_PIN_MASK;
Led3State = ON;
enableInterrupts();
}
/**
******************************************************************************
* @brief Example of LED switching using touch sensing keys
* KEY1: LED1 ON
* KEY2: LED1 OFF
* KEY3: LED1 ON then OFF after 1s delay
* KEY4: LED1 ON then OFF after 200ms delay
* KEY5: LED1 ON/OFF
* @par Parameters:
* None
* @retval void None
* @par Required preconditions:
* None
******************************************************************************
*/
void ExtraCode_StateMachine(void) {
if ((TSL_GlobalSetting.b.CHANGED) && (TSLState == TSL_IDLE_STATE))
{
TSL_GlobalSetting.b.CHANGED = 0;
if (sSCKeyInfo[0].Setting.b.DETECTED) /* KEY 1 touched */
{
if (Led1State == OFF)
{
LED1_ON();
}
else
{
LED1_OFF();
}
}
if (sSCKeyInfo[1].Setting.b.DETECTED) /* KEY 2 touched */
{
if (Led2State == OFF)
{
LED2_ON();
}
else
{
LED2_OFF();
}
}