📄 led.c
字号:
/*************************************************************************
Led.c
These are the line command routines to control the three LEDs on the
CobraNet evaluation board.
Line command supported: LED
Copyright (C) 2001-2004 by Cirrus Logic Inc. All Rights Reserved
*************************************************************************/
#include <stdio.h>
#include <intrpt.h>
#include <8051.h>
#include <string.h>
#include "serial.h"
#include "cnmutil.h"
#include "command.h"
#include "test.h"
#include "error.h"
#include "command.h"
#include "mystrings.h"
#include "led.h"
void led_help( char detailed );
void led_execute( unsigned char color_selection, unsigned char op_selection );
void led( char * com_arg_ptr[] );
code struct command_item_t led_command = {
( code char * ) str_Com_led,
( code command_function_t ) led
};
void led( char * com_arg_ptr[] ) {
unsigned char color_ch;
unsigned char operation_ch;
if ( com_arg_ptr[ 1 ] == NULL ) //look for the command without arguments
led_help( cHELP_SHORT );
else {
if ( *com_arg_ptr[ 1 ] == '?' )
led_help( cHELP_LONG );
else
if ( com_arg_ptr[ 2 ] == NULL )
printErrString( get_error_string( cERR_MISSING_ARG ) );
else {
color_ch = 0;
while ( ( strCodecmp( led_color_arguments[ color_ch ],
com_arg_ptr[ 1 ] ) ) &&
( led_color_arguments[ color_ch ] != NULL ) )
color_ch++;
if ( led_color_arguments[ color_ch ] == NULL )
printErrString( get_error_string( cERR_ARGUMENT ) );
else {
operation_ch = 0;
while ( ( strCodecmp( led_operation_arguments[ operation_ch ],
com_arg_ptr[ 2 ] ) ) &&
( led_operation_arguments[ operation_ch ] != NULL ) )
operation_ch++;
if ( led_operation_arguments[ operation_ch ] == NULL )
printErrString( get_error_string( cERR_ARGUMENT ) );
else
led_execute( color_ch, operation_ch );
}
}
}
}
void led_execute( unsigned char color_selection,
unsigned char op_selection ) {
unsigned char led_num;
unsigned char led_op_num = 1;
unsigned char local_color = color_selection;
if ( color_selection == cCOLOR_ALL )
led_op_num = cCOLOR_ALL;
for (led_num = 0; led_num < led_op_num; led_num++ ) {
if ( color_selection == cCOLOR_ALL )
local_color = led_num;
switch( op_selection ) {
case opLEDON:
LED_Operation( local_color, cLED_ON );
break;
case opLEDOFF:
LED_Operation( local_color, cLED_OFF );
break;
case opBLINKON:
LED_Operation( local_color + cBLINK_OFFSET, cBLINK_ON );
break;
case opBLINKOFF:
LED_Operation( local_color + cBLINK_OFFSET, cBLINK_OFF );
break;
case opTOGGLE:
LED_Toggle( local_color );
break;
default:
break;
}; //switch
}
}
extern void LED_Operation( unsigned char which_led,
unsigned char which_operation ) {
char * LED_ptr = ( char * ) ( cLED_ptr + which_led );
*( LED_ptr ) = which_operation;
}
extern void LED_Toggle( unsigned char which_led ) {
char * LED_ptr = ( char * ) ( cLED_ptr + which_led );
unsigned char current_LED_state;
current_LED_state = *LED_ptr;
*LED_ptr = ~current_LED_state;
}
void led_help( char detailed ) {
printStrCodeC( led_str_help1 );
if ( detailed )
printStrCodeC( led_str_help2 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -