/****************************************Copyright (c)******************* * 功能:LED数码管显示0-F字符 * 说明:将跳线器JP3、JP4、JP7短接。 ****************************************************************************/ #include "config.h" #include "stdlib.h"
#define TaskStkLengh 64 //定义用户任务堆栈长度 #define LED (1<<24) OS_STK TaskStk [TaskStkLengh]; //定义用户任务0的堆栈 OS_STK TaskStk1 [TaskStkLengh]; //定义用户任务1的堆栈 OS_STK TaskStk2 [TaskStkLengh]; //定义用户任务0的堆栈 OS_STK TaskStk3 [TaskStkLengh]; OS_STK TaskStk4 [TaskStkLengh]; //定义用户任务0的堆栈 OS_STK TaskStk5 [TaskStkLengh];
void Task0(void *pdata); //Task0 任务0 void Task1(void *pdata); //void Task2(void *pdata); void Task3(void *pdata); void Task4(void *pdata); void Task5(void *pdata);
OS_EVENT *MyBox; OS_EVENT *MyQueue; void *MyDatQueue[16]; INT8U *Data; //INT8U Time=0; /* 此表为0--F的字模 */ INT8U DISP_TAB[16] = { 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90, 0x88,0x83,0xC6,0xA1,0x86,0x8E };
/**************************************************************************** * 名称:DelayNS() * 功能:长软件延时 ****************************************************************************/ void DelayNS(uint32 dly) { uint32 i;
for(; dly>0; dly--) for(i=0; i<50000; i++); }
/**************************************************************************** * 名称:HC595_SendDat() * 功能:向74HC595发送一字节数据 * 入口参数:*dat 要发送的数据 * 出口参数:无 * 说明:发送数据时,高位先发送。 ****************************************************************************/ void HC595_SendDat(INT8U dat) { IO0CLR = SPI_CS; // SPI_CS = 0 S0PDR= dat; while((S0PSR&0x80)==0); IO0SET = SPI_CS; // SPI_CS = 1,输出显示数据 }
/* 主函数 */ int main (void) { OSInit (); OSTaskCreate (Task0,(void *)0, &TaskStk[TaskStkLengh - 1], 0); OSStart (); return 0; }
/*任务Task0*/ void Task0 (void *pdata) { pdata = pdata; Data=DISP_TAB; OSTaskCreate (Task1,(void *)0, &TaskStk1[TaskStkLengh - 1], 1); //OSTaskCreate (Task2,(void *)0, &TaskStk2[TaskStkLengh - 1], 2); OSTaskCreate (Task3,(void *)0, &TaskStk3[TaskStkLengh - 1], 3); OSTaskCreate (Task4,(void *)0, &TaskStk4[TaskStkLengh - 1], 4); OSTaskCreate (Task5,(void *)0, &TaskStk5[TaskStkLengh - 1], 5); //MyBox=OSMboxCreate((void *)0); //MyQueue=OSQCreate(&MyDatQueue[0],16); TargetInit (); PINSEL0&=~LED; IO0DIR|=LED; for(;;) { /*for(Time=0;Time<16;Time++) { *Data=DISP_TAB[Time]; OSMboxPost(MyBox,Data); //Time++; //OSQPost(MyQueue,Data); //OSTimeDly(5); //HC595_SendDat(DISP_TAB[Time]); IO0SET|=LED;
OSTimeDlyHMSM(0,0,10,0); }*/ HC595_SendDat(DISP_TAB[10]); OSTimeDly(OS_TICKS_PER_SEC); } } /*任务Task1*/ void Task1 (void *pdata) { // INT8U *Disp; //INT8U err; pdata=pdata; for(;;) { /* Disp=OSMboxPend(MyBox,0,&err); IO0CLR|=LED; // Disp=OSQPend(MyQueue,2,&err); //OSMboxDel(MyBox,OS_DEL_NO_PEND,&err);//没有信号量时删除邮箱 HC595_SendDat(Disp); // 输出LED显示数据 // if(Time>=10) OSTaskSuspend(OS_PRIO_SELF); DelayNS(40); // 延时 //OSTimeDlyHMSM(0,0,1,0); OSTimeDlyResume(0);*/ HC595_SendDat(DISP_TAB[1]); OSTimeDly(OS_TICKS_PER_SEC); } }
void Task3 (void *pdata) { pdata=pdata; for(;;) { HC595_SendDat(DISP_TAB[3]); OSTimeDly(OS_TICKS_PER_SEC); } }
void Task4 (void *pdata) { pdata=pdata; for(;;) { HC595_SendDat(DISP_TAB[4]); OSTimeDly(OS_TICKS_PER_SEC); } }
void Task5 (void *pdata) { pdata=pdata; for(;;) { HC595_SendDat(DISP_TAB[5]); OSTimeDly(OS_TICKS_PER_SEC); } }
|