资源预览内容
第1页 / 共5页
第2页 / 共5页
第3页 / 共5页
第4页 / 共5页
第5页 / 共5页
亲,该文档总共5页全部预览完了,如果喜欢就下载吧!
资源描述
电子表C语言程序#include #include void Init_Device(void) ;typedef unsigned char uchar;enum Clock_SHOW_MODE M_NORMAL = 0, M_ADJUEST_HOUR, M_ADJUST_MIN, M_ADJUST_SECOND;enum CLOCK_SHOW_LEFT_RIGHT SHOW_HOUR_MIN, SHOW_MIN_SECONDS;struct TIMERuchar hour;uchar min;uchar seconds;uchar showDot;uchar leds6;enum Clock_SHOW_MODE showMode;enum CLOCK_SHOW_LEFT_RIGHT showLeftRight;typedef struct TIMER* P_TIMER;void TimerInit(P_TIMER pTimer) pTimer-hour = 1;pTimer-min = 23;pTimer-seconds = 45; uchar i;for( i=0;iledsi= 0;pTimer-showLeftRight = SHOW_HOUR_MIN;/SHOW_MIN_SECONDS;pTimer-showMode = M_NORMAL;void TimerInc(P_TIMER ptimer)ptimer-seconds +;if(ptimer-seconds = 60)ptimer-seconds -= 60;ptimer-min +;if(ptimer-min =60)ptimer-min -= 60;ptimer-hour +;if( ptimer-hour = 24)ptimer-hour -= 24;#define BLACK 10code uchar LED_ARRAY=0 ; /*0,1,2,3,4,5,6,7,8,9,10; */void setLedPos(uchar num, uchar *pLed)pLed0 = num/10 ;pLed1 = num%10 ;void SetLeds(P_TIMER pTimer)setLedPos(pTimer-hour, pTimer-leds);setLedPos(pTimer-min, pTimer-leds+ 2);setLedPos(pTimer-seconds, pTimer-leds + 4);if(pTimer- showDot)switch(pTimer- showMode) case M_ADJUEST_HOUR:pTimer-leds0 = BLACK;pTimer-leds1 = BLACK;break;case M_ADJUST_MIN:pTimer-leds2 = BLACK;pTimer-leds3 = BLACK;break;case M_ADJUST_SECOND:pTimer-leds4 = BLACK;pTimer-leds5 = BLACK;break; code posArray =/*/*0,2,4,0x10; */6,4,2,0;code Charecter = 0x3f,0x6,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f ,0xff;/ 0x50, 0x5f, 0x38, 0x17, 0x92, 0x90, 0x5b, 0x10, 0x12;void showLED(uchar num, uchar pos, uchar showDot)P2 = Charecternum - showDot*0x80; P1= posArraypos;#define C_TIME 1void showLESD(P_TIMER ptimer)uchar * pbuff;if(ptimer-showLeftRight = SHOW_HOUR_MIN) pbuff = ptimer- leds;else pbuff = ptimer- leds+2;showLED(pbuff0,0,0);os_wait(K_TMO,C_TIME,0);showLED(pbuff1,1,ptimer-showDot); os_wait(K_TMO,C_TIME,0);showLED(pbuff2,2,0);os_wait(K_TMO,C_TIME,0);showLED(pbuff3,3,ptimer-showDot); os_wait(K_TMO,C_TIME,0); enum KEY_CODE KEY_mode=0xfe, KEY_UP= 0xf7, KEY_CHANGE_SHOW_POS= 0xef;struct TIMER timer;#define TASK_TIMER_INC 0#define TASK_SHOW_LEDS 1#define TASK_KEY 2job0() _task_ TASK_TIMER_INC Init_Device() ; TimerInit(&timer); os_create_task(TASK_SHOW_LEDS); os_create_task(TASK_KEY); while(1) if(timer.showMode = M_NORMAL)TimerInc(&timer);timer.showDot =0;os_wait(K_TMO,500,0);timer.showDot =1;os_wait(K_TMO,500,0);job1() _task_ TASK_SHOW_LEDSwhile(1) SetLeds(&timer); showLESD(&timer);#define true 1#define false 0uchar isKeyPressed( enum KEY_CODE *pkey) uchar P2Temp = P2&0xff; uchar ret = true; P2= 0xff; *pkey = P2; switch(*pkey) case KEY_mode: case KEY_UP: case KEY_CHANGE_SHOW_POS: ret = true; break;default:ret = false;P2 = P2Temp;return ret; job2() _task_ TASK_KEYwhile(1) enum KEY_CODE key,key2; if(isKeyPressed( &key) for(;)if( isKeyPressed(&key2) & key = key2);else break;os_wait(K_TMO,20,0); else goto L1; switch(key) case KEY_mode: timer.showMode+;timer.showMode %= 4;switch(timer. showMode) case M_ADJUEST_HOUR: timer.showLeftRight = SHOW_HOUR_MIN; break; case M_ADJUST_SECOND: timer.showLeftRight = SHOW_MIN_SECONDS; break; default: break; break;case KEY_UP:switch( timer.showMode)default:break;case M_ADJUEST_HOUR:timer.hour +;timer.hour %= 24;break;case M_ADJUST_MIN:timer.min+;timer.min %= 60;break;case M_ADJUST_SECOND:timer.seconds+;timer.seconds %= 60;break; break;case KEY_CHANGE_SHOW_POS: if( timer.showMode =M_NORMAL)timer.showLeftRight+;timer.showLeftRight %= 2;break;L1:os_wait(K_TMO,20,0); 5
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号