虽然只有三个任务,除任务调度,其他功能全部关闭。 /* ************************************************************************************************************** *uC/OS-II *The Real-Time Kernel * * *AVR Sample code * File: TEST.C * By: Ole Saether * Version: V1.01 * * 2004-05-23 modified by Zhang Yunfeng (yfzhang@ele.pku.edu.cn) * * AVR-GCC port version : 1.02001-04-02 modified/ported to avr-gcc by Jesper Hansen (jesperh@telia.com) * * 2003-06-27 Modification to gcc v. 3.x and uC/OS-II v 2.52 by Julius Luukko (Julius.Luukko@lut.fi). *See the file README for details of the changes. * * * Description : * *This file contains a simple example program showing how to use the AVR port of uC/OS-II. It is *based on Example #1 from Jean Labrosse's book "MicroC/OS-II, The Real Time Kernel." The main *difference is that this example does not display the time of day and the uC/OS-II version number. *You must have the AVR UART connected to a VT102 compatible terminal (HyperTerminal in Windows is OK) *to get the most out of this example. * *The support routines at the end of this file are included only to make this example run; they should *not be used in production code without careful testing. ************************************************************************************************************** */ #include "includes.h" /* ************************************************************************************************************** *CONSTANTS ************************************************************************************************************** */ #define CPU_CLOCK_HZ7372800//7.3728Mhz/* 36864003.6864Mhz */ #define UART_BAUD_RATE115200/* 9600 baud */ #define UART_BAUD_SELECT (CPU_CLOCK_HZ/(UART_BAUD_RATE*16l)-1) #defineTASK_STK_SIZEOS_TASK_DEF_STK_SIZE/* Size of each task's stacks (# of bytes)*/ #defineN_TASKS2/* Number of identical tasks*/ /* #define UART_TX_BUF_SIZE 512 */ //#define UART_TX_BUF_SIZE 256 #define S1_XBUFLEN512 #define S1_RBUFLEN32 #define S1_DATA UDR1 #define MSG_QUEUE_SIZE 20 /* ************************************************************************************************************** *VARIABLES ************************************************************************************************************** */ OS_STKTaskStk1[TASK_STK_SIZE];//Task1 stacks OS_STKTaskStk2[TASK_STK_SIZE];//Task1 stacks OS_STKTaskStartStk[TASK_STK_SIZE]; charTaskData[N_TASKS];/* Parameters to pass to each task*/ static volatile INT8US1_xbuf[S1_XBUFLEN];/* UART transmit buffer*/ static volatile INT16US1_xpos;/* UART transmit buffer read pointer*/ static volatile INT16US1_xcnt;/* Number of characters to send*/ static volatile INT8US0_rbuf[S1_RBUFLEN];/* UART receive buffer*/ static volatile INT16US1_rpos;/* UART receive buffer read pointer*/ static volatile INT16US1_rcnt;/* Number of characters for read*/ //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //我添加的变量 unsigned char test_flg =0; //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& /* ************************************************************************************************************** *FUNCTION PROTOTYPES ************************************************************************************************************** */ //$$$$$$$$$$$$$$$$$$$$$$$$$$$ //我的函数 //$$$$$$$$$$$$$$$$$$$$$$$$$$$$ voidTask1(void *data);/* Function prototypes of tasks*/ voidTask2(void *data); voidTaskStart(void *data);/* Function prototypes of Startup task*/ voidPutChar(char c);/* Write a character to the AVR UART*/ voidAvrInit(void);/* Initialize AVR*/ /* ************************************************************************************************************** *MAIN ************************************************************************************************************** */ int main (void) { AvrInit();/* Initialize the AVR UART and Timer*/ OSInit(); OSTaskCreate(TaskStart, (void *)0, (void *)&TaskStartStk[TASK_STK_SIZE - 1], 0); OSStart();/* Start multitasking*/ return 0; } /* ************************************************************************************************************** *STARTUP TASK ************************************************************************************************************** */ void TaskStart (void *data) { data = data;/* Prevent compiler warning*/ unsigned char lingt_f = 0; OS_ENTER_CRITICAL(); /*TCCR0=0x05;/\* on some processors other than mega128 *\/ */ TCCR0=0x07;/* Set TIMER0 prescaler to CLK/1024*/ TIMSK=_BV(TOIE0);//T0溢出中断允许/* Enable TIMER0 overflow interrupt*/ TCNT0=256-(CPU_CLOCK_HZ/OS_TICKS_PER_SEC/1024);/* Set the counter initial value*/ OS_EXIT_CRITICAL(); OSStatInit();/* Initialize uC/OS-II's statistics*/ OSTaskCreate(Task1, (void *)0, (void *)&TaskStk1[TASK_STK_SIZE - 1],2); OSTaskCreate(Task2, (void *)0, (void *)&TaskStk2[TASK_STK_SIZE - 1],4); while(1) { //lingt_f=(~lingt_f); //PORTF = lingt_f; /* if(lingt_f == 0) { PORTF |= 0x02; //PORTF &= 0xfd; lingt_f = 1; } if(lingt_f == 1) { //PORTF |= 0x02; PORTF &= 0xfd; lingt_f = 0; } */ OSCtxSwCtr = 0; OSTimeDlyHMSM(0, 0, 2, 0);/* Wait one second*/ } } /* ************************************************************************************************************** *TASKS ************************************************************************************************************** */ void Task1 (void *data) { INT8U err; unsigned char lingt_f1 = 0; //PORTF &= 0xf7; for (;;) { //lingt_f1=(~lingt_f1); //PORTF = lingt_f1; /* if(lingt_f1 == 0) { PORTF |= 0x08; //PORTF &= 0xfd; lingt_f1 = 1; } if(lingt_f1 == 1) { //PORTF |= 0x02; PORTF &= 0xf7; lingt_f1 = 0; } */ OSTimeDly(100);/* Delay 6 clock ticks*/ } } //@@@@@@@@@@@@@@ void Task2 (void *data) { INT8U err; unsigned char lingt_f2 = 0; //PORTF &= 0x7f; for (;;) { lingt_f2=(~lingt_f2); PORTF = lingt_f2; /* if(lingt_f2 == 0) { PORTF |= 0x80; //PORTF &= 0xfd; lingt_f2 = 1; } if(lingt_f2 == 1) { //PORTF |= 0x02; PORTF &= 0x7f; lingt_f2 = 0; } */ OSTimeDly(10);/* Delay 6 clock ticks */ } } //@@@@@@@@@@@@@@@@ void AvrInit (void) { //####################################### MCUCR=0x00;//###zkq modif SREG|=0x80;//全局中断允许 //############## DDRF = 0xff; PORTF = 0xff; } //=================================================================================== 作者:keer_zu 2007-4-5 16:06:00 |