虽然只有三个任务,除任务调度,其他功能全部关闭。 /* ************************************************************************************************************** * 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.0 2001-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_HZ 7372800 //7.3728Mhz /* 3686400 3.6864Mhz */ #define UART_BAUD_RATE 115200 /* 9600 baud */ #define UART_BAUD_SELECT (CPU_CLOCK_HZ/(UART_BAUD_RATE*16l)-1)
#define TASK_STK_SIZE OS_TASK_DEF_STK_SIZE /* Size of each task's stacks (# of bytes) */ #define N_TASKS 2 /* Number of identical tasks */
/* #define UART_TX_BUF_SIZE 512 */ //#define UART_TX_BUF_SIZE 256 #define S1_XBUFLEN 512 #define S1_RBUFLEN 32 #define S1_DATA UDR1
#define MSG_QUEUE_SIZE 20 /* ************************************************************************************************************** * VARIABLES ************************************************************************************************************** */
OS_STK TaskStk1[TASK_STK_SIZE]; //Task1 stacks OS_STK TaskStk2[TASK_STK_SIZE]; //Task1 stacks OS_STK TaskStartStk[TASK_STK_SIZE]; char TaskData[N_TASKS]; /* Parameters to pass to each task */ static volatile INT8U S1_xbuf[S1_XBUFLEN]; /* UART transmit buffer */ static volatile INT16U S1_xpos; /* UART transmit buffer read pointer */ static volatile INT16U S1_xcnt; /* Number of characters to send */ static volatile INT8U S0_rbuf[S1_RBUFLEN]; /* UART receive buffer */ static volatile INT16U S1_rpos; /* UART receive buffer read pointer */ static volatile INT16U S1_rcnt; /* Number of characters for read */ //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //我添加的变量 unsigned char test_** =0;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& /* ************************************************************************************************************** * FUNCTION PROTOTYPES ************************************************************************************************************** */ //$$$$$$$$$$$$$$$$$$$$$$$$$$$ //我的函数
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$
void Task1(void *data); /* Function prototypes of tasks */ void Task2(void *data); void TaskStart(void *data); /* Function prototypes of Startup task */ void PutChar(char c); /* Write a character to the AVR UART */ void AvrInit(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; } //===================================================================================
|