本帖最后由 yklstudent 于 2013-9-6 23:18 编辑
不知道有没有理解楼主的意思
我就是先开的灯 关也是先关
后开的灯 也是后关
typedef struct
{
INT8U led_state0:1;
INT8U led_state1:1;
INT8U led_state2:1;
INT8U led_state3:1;
INT8U led_state4:1;
INT8U led_state5:1;
INT8U led_state6:1;
INT8U led_state7:1;
}LED_BIT;
typedef union
{
LED_BIT led_bit;
INT8U led_state;
}LED_STATE;
typedef struct
{
INT8U left_count;
INT8U right_count;
INT8U length;
LED_STATE led_value;
}FUN_STATE;
void Task1(void)
{
switch ( Key_Value )
{
case KV_UP:
{
fun_state.led_value.led_bit.led_state0 ^= 1;
if ( !fun_state.led_value.led_bit.led_state0 )
{
fun_state.led_value.led_state &= 0xF0;
fun_state.left_count = 0;
fun_state.right_count = 0;
}
break;
}
case KV_DN:
{
if ( fun_state.led_value.led_bit.led_state0 )
{
if( (fun_state.left_count < 3) )
{
fun_state.length ++;
fun_state.left_count ++;
fun_state.led_value.led_state |= _BV(fun_state.left_count);
if ( fun_state.left_count == 3 )
{
fun_state.left_count = 0;
}
}
}
break;
}
case KV_LF:
{
if ( (fun_state.led_value.led_bit.led_state0) && (fun_state.length!=0) )
{
if( (fun_state.right_count <= fun_state.length+1) )
{
if (fun_state.length!=0)
fun_state.length --;
fun_state.right_count ++;
fun_state.led_value.led_state &= ~_BV(fun_state.right_count);
if ( fun_state.right_count == 3 )
{
fun_state.right_count = 0;
}
}
}
break;
}
case KV_MD:
{
break;
}
default:
break;
}
Key_Value = KV_NO;
}
void Task2(void)
{
LedPort = fun_state.led_value.led_state;
}
|