新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > ARM7 嵌入uc/os 做流水燈練習(xí)

ARM7 嵌入uc/os 做流水燈練習(xí)

作者: 時(shí)間:2016-11-24 來源:網(wǎng)絡(luò) 收藏
#include "config.h"

#defineTASK_STK_SIZE100
#defineLedFlowSpeed5

本文引用地址:http://m.butianyuan.cn/article/201611/320821.htm

OS_STKTaskStartStk[TASK_STK_SIZE];
OS_STKTaskKeyScanStk[TASK_STK_SIZE];

OS_EVENT*LedFlowMbox;

#defineLed1(1<<22)
#defineLed2(1<<23)
#defineLed3(1<<24)
#defineLed4(1<<25)
#define KEY1(1<<16)
#define KEY2(1<<17)
#define KEY3(1<<18)
#define KEY4(1<<19)
#defineKEY5(1<<20)
#define KEY6(1<<21)


void TaskStart(void *pdata);
void TaskKeyScan(void *pdata);
void DelayNms(INT32U dly);



int main()
{
OSInit();
OSTaskCreate(TaskStart, (void *)0, &TaskStartStk[TASK_STK_SIZE-1], 0);
OSStart();
return 0;
}

void TaskStart(void *pdata)
{
uint8 *KeyValue;
uint8 err;
pdata = pdata;

LedFlowMbox = OSMboxCreate(NULL);
if(LedFlowMbox == NULL)
{
while(1);
}
TargetInit();

IO0DIR &= (~KEY1)|(~KEY2)|(~KEY3)|(~KEY4)|(~KEY5)|(~KEY6);
IO0DIR |= Led1|Led2|Led3|Led4;
IO0SET = Led1|Led2|Led3|Led4;
PINSEL0 = (PINSEL0&0x00000000) | 0x05;
PINSEL1 = (PINSEL1&0x00000000);
OSTaskCreate(TaskKeyScan, (void *)0, &TaskKeyScanStk[TASK_STK_SIZE-1],8);


for(;;)
{
KeyValue = (uint8 *)OSMboxPend(LedFlowMbox, 0 , &err);
if(*KeyValue==1)
{
IO0CLR = Led1;
//DelayNms(200);
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
IO0SET = Led1;
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
//DelayNms(200);
IO0CLR = Led1;
//DelayNms(200);
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
IO0SET = Led1;
} else if(*KeyValue ==2)
{
IO0CLR = Led2;
//DelayNms(200);
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
IO0SET = Led2;
//DelayNms(200);
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
IO0CLR = Led2;
//DelayNms(200);
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
IO0SET = Led2;
}else if(*KeyValue ==3)
{
IO0CLR = Led3;
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
//DelayNms(200);
IO0SET = Led3;
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
//DelayNms(200);
IO0CLR = Led3;
//DelayNms(200);
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
IO0SET = Led3;
}else if(*KeyValue==4)
{
IO0CLR = Led4;
//DelayNms(200);
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
IO0SET = Led4;
//DelayNms(200);
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
IO0CLR = Led4;
//DelayNms(200);
OSTimeDly(OS_TICKS_PER_SEC/LedFlowSpeed);
IO0SET = Led4;
}
}
}

void TaskKeyScan(void *pdata)
{
uint8 KeyValue;
pdata = pdata;
KeyValue = 1;

for(;;)
{
while(((IO0PIN&KEY1)!=0) && ((IO0PIN&KEY2)!=0) && ((IO0PIN&KEY3)!=0) && ((IO0PIN&KEY4)!=0) );
{
OSTimeDly(OS_TICKS_PER_SEC/50);
}
if((IO0PIN&KEY1)==0)
{
OSTimeDly(OS_TICKS_PER_SEC/50);
if((IO0PIN&KEY1)!=0) continue;
KeyValue = 1;
while((IO0PIN&KEY1)==0)
{
OSTimeDly(OS_TICKS_PER_SEC/50);
}
}
else if((IO0PIN&KEY2)==0)
{
OSTimeDly(OS_TICKS_PER_SEC/50);
if((IO0PIN&KEY2)!=0) continue;
KeyValue = 2;
while((IO0PIN&KEY2)==0)
{
OSTimeDly(OS_TICKS_PER_SEC/50);
}
}
else if((IO0PIN&KEY3)==0)
{
OSTimeDly(OS_TICKS_PER_SEC/50);
if((IO0PIN&KEY3)!=0) continue;
KeyValue = 3;
while((IO0PIN&KEY3)==0)
{
OSTimeDly(OS_TICKS_PER_SEC/50);
}
}
else if((IO0PIN&KEY4)==0)
{
OSTimeDly(OS_TICKS_PER_SEC/50);
if((IO0PIN&KEY4)!=0) continue;
KeyValue = 4;
while((IO0PIN&KEY4)==0)
{
OSTimeDly(OS_TICKS_PER_SEC/50);
}
}

OSMboxPost(LedFlowMbox,&KeyValue);

OSTimeDly(OS_TICKS_PER_SEC/10);
}
}


void DelayNms(INT32U dly)
{ INT32U i;

for(; dly>0; dly--)
for(i=0; i<7142; i++);
}



關(guān)鍵詞: ARM7ucos做流水

評(píng)論


技術(shù)專區(qū)

關(guān)閉