您的位置 首页 汽车

ARM7 嵌入uc/os 做流水灯操练

includeconfighdefineTASK_STK_SIZE100defineLedFlowSpeed5OS_STKTaskStartStk[TASK_STK_SIZE];OS_STKTaskK

#include “config.h”

#defineTASK_STK_SIZE100
#defineLedFlowSpeed5

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++);
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/260233.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部