微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > ARM7 嵌入uc/os 做流水灯练习

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

时间:11-24 来源:互联网 点击:
#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++);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top