📄 led_drv.c
字号:
#include <stdio.h>#include "led_drv.h"#ifdef TARGET_PCstatic unsigned char led_status[LED_NUM] = { 0 };int led_show_status(void){ int i = 0; printf( "\r" ); for(i = 0; i < 4; i++) { if(led_status[i] == 1) printf("*"); else printf("o"); } fflush(stdout); return 0;}#endifint led_open(void){#ifdef TARGET_PC int i = 0; for( i = 0; i < LED_NUM; i++ ) led_status[i] = 0; led_show_status();#else R_IOPMOD |= LED_ALL; R_IOPDATA &= ~LED_ALL;#endif return 0;}int led_read( char * buf, int count ){ #ifdef TARGET_PC int i = 0; // the count has exceeds the count of our board if( count > LED_NUM ) return -1; for( i = 0; i < count; i++ ) buf[i] = led_status[i]; return count;#else return -1;#endif}int led_write( char * buf, int count ){ int i = 0; // the count has exceeds the count of our board if( count > LED_NUM ) return -1; for( i = 0; i < count; i++ ) { if( buf[i] == 1 ) {#ifdef TARGET_PC led_status[i] = 1; led_show_status();#else switch (i) { case 0: R_IOPDATA |= LED0; break; case 1: R_IOPDATA |= LED1; break; case 2: R_IOPDATA |= LED2; break; case 3: R_IOPDATA |= LED3; break; default: break; }#endif } if( buf[i] == 0 ) {#ifdef TARGET_PC led_status[i] = 0; led_show_status();#else switch (i) { case 0: R_IOPDATA &= ~LED0; break; case 1: R_IOPDATA &= ~LED1; break; case 2: R_IOPDATA &= ~LED2; break; case 3: R_IOPDATA &= ~LED3; break; default: break; }#endif } } return count;}int led_release( void ){ // do nothing return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -