⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 ucos下完成时钟显示及别的任务
💻 C
字号:
/*
 * File:        main.c
 *
 * uC/OS Real-time multitasking kernel for the ARM processor.
 *
 * This program is an example of using semaphore to
 * implement task rendevous.
 *
 * Created by Marco Graziano (marcog@crl.com).
 *
 * Created by Lhj on 2006.04.27
 *
 */

#include	"includes.h"               /* uC/OS interface */

/* add new head files */
#include <string.h>
#include <stdio.h>
#include "rtc.h"
#include "slib.h"
#include "lcdlib.h"


/* allocate memory for tasks' stacks */
#ifdef SEMIHOSTED
#define STACKSIZE       (SEMIHOSTED_STACK_NEEDS+64)
#else
#define	STACKSIZE	64
#endif
unsigned int Stack1[STACKSIZE];
unsigned int Stack2[STACKSIZE];
unsigned int Stack3[STACKSIZE];

unsigned int Stack4[STACKSIZE];

/* add new global variables */
int year;
int month,day,weekday,hour,min,sec;
char *date[8] = {"","SUN","MON","TUE","WED","THU","FRI","SAT"};


/* semaphores event control blocks */
//OS_EVENT *Sem1;
//OS_EVENT *Sem2;
//OS_EVENT *Sem3;
/*
 * Task running at the highest priority. 
 */

void
 Task1(void *i)
{

    INT8U Reply, n;

    for (;;)
    {
        /* wait for the semaphore  */
        //OSSemPend(Sem1, 0, &Reply);

        
uHALr_printf("\nTask1 running");
        //Uart_Printf("1+");

        /* wait a short while */
/*****************for(n=0;n<1;n++)
		{
			LED0(1);
			OSTimeDly(500);
			LED0(0);
			OSTimeDly(500);
		}
		*/
		//Uart_Printf("1-");

        /* signal the semaphore */
        //OSSemPost(Sem1);

/* add new functions to be called */
             Display_Rtc();
             Slib_ClearScr();
             //Delay(10);
             Slib_SetCursor(0,200);
             Slib_Printf("%4x,%2x,%2x,%s,%2x:%2x:%2x\n",year,month,day,date[weekday],hour,min,sec);

//if(sec==0x01)LED1(1);
//if(sec==0x31)LED1(0);
/*Made LED1 flash with 1s cycle*/
if(((sec &0x0f) %2)==0)LED0(1);
else LED0(0);
if(((sec &0x0f) %4)==0)LED1(1);
else LED1(0);


             OSTimeDly(50);
uHALr_printf("\nTask1 exit");

    }
}

void
 Task2(void *i)
{
    INT8U Reply, n;

    for (;;)
    {
     

        uHALr_printf("\nTask2 running");

        /* wait a short while */
		for(n=0;n<1;n++)
		{
			//******LED1(1);
Reply=0;
			
OSTimeDly(500);
			//******LED1(0);
Reply=1;
			OSTimeDly(1000);
		}

	uHALr_printf("\nTask2 exit");
    }
}

void
 Task3(void *i)
{
    INT8U Reply, n;

    for (;;)
    {
        uHALr_printf("\nTask3 running");

        /* wait a short while */
		for(n=0;n<1;n++)
		{
			//******LED2(1);
Reply=2;
			//OSTimeDly(2000);
OSTimeDly(500);
			//******LED2(0);
Reply=3;
			OSTimeDly(2000);
		}
        uHALr_printf("\nTask3 exit");
    }
}

void
 Task4(void *i)
{
    INT8U Reply, n;

    for (;;)
    {
        uHALr_printf("\nTask4 running");

        /* wait a short while */
		for(n=0;n<1;n++)
		{
			//******LED2(1);
Reply=Uart_GetKey();
if(Reply=='a'){
      
       LED2(1);
       OSTimeDly(500);
       LED2(0);
   
}

			//OSTimeDly(2000);
//OSTimeDly(500);
			//******LED2(0);
//Reply=3;
			OSTimeDly(2000);
		}
        uHALr_printf("\nTask4 exit");
    }
}



/*
 * Main function.
 */
void Main(void)
{
    char Id1 = '1';
    char Id2 = '2';
    char Id3 = '3';

    char Id4 = '4';

    Port_Init();
    Uart_Init(0,57600);
	
    Delay(1000);
    Uart_Select(0); //Select UART0

/* add new functions to be called */
    Rtc_Init();
    Lcd_Init(MODE_MONO);
    Lcd_DispON();
    Slib_ClearScr();
    Slib_Init();
    Slib_SetCursor(0,0);





	//Uart_Printf("Uc-OS ii will run at once!");
	

    /* do target (uHAL based ARM system) initialisation */
    ARMTargetInit();

    /* needed by uC/OS */
    OSInit();

    OSTimeSet(0);
    /* 
     * create the semaphores
     */
    //Sem1 = OSSemCreate(1);
    //Sem2 = OSSemCreate(1);
//Sem3 = OSSemCreate(1);
    /* 
     * create the tasks in uC/OS and assign decreasing
     * priority to them 
     */
    OSTaskCreate(Task1, (void *)&Id1, (void *)&Stack1[STACKSIZE - 1], 1);
    OSTaskCreate(Task2, (void *)&Id2, (void *)&Stack2[STACKSIZE - 1], 2);
    OSTaskCreate(Task3, (void *)&Id3, (void *)&Stack3[STACKSIZE - 1], 3);
    
    OSTaskCreate(Task4, (void *)&Id4, (void *)&Stack4[STACKSIZE - 1], 4);



    /* Start the (uHAL based ARM system) system running */
    ARMTargetStart();

    /* start the game */
    OSStart();

    /* never reached */
}                               /* main */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -