本帖最后由 busdriver 于 2010-11-12 16:59 编辑
1.按键扫描程序:
void key_scan(void)
{
if(key_step == 0)//in the step of key scanning
{
//key scanning
if(FOUT_ON_OFF != on_off_status)//if key FOUT_ON_OFF change
key_step = 1;//enter the step of delay
else if(LED_SWITCH != led_switch_status)//if key LED_SWITCH change
key_step = 1;//enter the step of delay
else if(!FOUT_UP)//if key FOUT_UP touch
key_step = 1;//enter the step of delay
else if(!FOUT_DOWN)
key_step = 1;//enter the step of delay
}
else if(key_step == 1)//in the step of delay
{
if(key_timer == 2)//delay timeout
{
key_step = 0;//reset to the step of key scanning
//get key value
if(FOUT_ON_OFF != on_off_status)//if key FOUT_ON_OFF change
{
key_val = KEY_ON_OFF;
//on_off_swap = 1;//set ON/OFF swap flag
on_off_status = ~on_off_status;//flip
key_change = 1;//set key change flag
}
else if(LED_SWITCH != led_switch_status)//if key LED_SWITCH change
{
key_val = KEY_LED_SWITCH;
//led_switch_swap = 1;//set LED_SWITCH flag
led_switch_status = ~led_switch_status;//flip
key_change = 1;//set key change flag
}
else if(FOUT_UP == 0)//if key FOUT_UP touch
{
if(!on_off_status)//if ON,or else no actions
{
up_down_active = 1;
key_val = KEY_UP;
//fout_up_flag = 0;
key_change = 1;//set key change flag
}
}
else if(FOUT_DOWN == 0)
{
if(!on_off_status)//if ON,or else no actions
{
up_down_active = 1;
key_val = KEY_DOWN;
//fout_down_flag = 0;
key_change = 1;//set key change flag
}
}
}
}
}
/***********************************************************************
Name:key_action(data)
Function:key action routine
Input:none
Output:none
************************************************************************/
void key_action(void)
{
//unsigned char *set_EN_CLKout
unsigned char i;
//unsigned char SET_CLKout_DIV;
switch(key_val)
{
case KEY_ON_OFF:
{
if(!on_off_status)//ON
{
lmk04031_set_word = SET_EN_CLKout;//LMK04031 set word
lmk04031_set_flag = 1;
led_decode(led,*fout);
led_display(led);//refresh LEDs
}
else if(on_off_status)//OFF
{
lmk04031_set_word = RESET_EN_CLKout;//LMK04031 set word
lmk04031_set_flag = 1;
for(i=0;i<=4;i++)
{
led=10;
}
led_display(led);//all off
}
break;
}
case KEY_LED_SWITCH:
{
if(led_switch_status)//channel 0
{
//set_EN_CLKout = &SET_EN_CLKout0
SET_CLKout_DIV = SET_CLKout0_DIV;
CLKout_DIV = &CLKout0_DIV;
fout = &fout0;
}
else if(!led_switch_status)//channel 3
{
//set_EN_CLKout = &SET_EN_CLKout3
SET_CLKout_DIV = SET_CLKout3_DIV;
CLKout_DIV = &CLKout3_DIV;
fout = &fout3;
}
break;
}
case KEY_UP:
{
if(*CLKout_DIV == 32)
*CLKout_DIV = 1;
else if((*CLKout_DIV == 12) || (*CLKout_DIV == 16) || (*CLKout_DIV == 20))
*CLKout_DIV += 4;
else if(*CLKout_DIV == 24)
*CLKout_DIV += 6;
else
*CLKout_DIV += 2;
lmk04031_set_word = SET_CLKout_DIV;//LMK04031 set word
lmk04031_set_flag = 1;
//led_decode(led,*fout);
//led_display(led);//refresh LEDs
break;
}
case KEY_DOWN:
{
if(*CLKout_DIV == 1)
*CLKout_DIV = 32;
else if((*CLKout_DIV == 16) || (*CLKout_DIV == 20) || (*CLKout_DIV == 24))
*CLKout_DIV -= 4;
else if(*CLKout_DIV == 30)
*CLKout_DIV -= 6;
else
*CLKout_DIV -= 2;
lmk04031_set_word = SET_CLKout_DIV;//LMK04031 set word
lmk04031_set_flag = 1;
//led_decode(led,*fout);
//led_display(led);//refresh LEDs
break;
}
default:
break;
}
}
2.中断程序
if(key_step == 0)//in the step of key scanning
{
key_timer = 0;//reset key timer
}
else if(key_step == 1)//in the step of delay
{
key_timer++;//key timet +1
} |