The simplest multi-tasking template for MCU

Publisher:yanfeng00Latest update time:2016-12-15 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/******MCU multi-task template******/

#include

#define TASK_NUM 2 //Number of tasks

#define FRE(x) 10000/x //define frequency

unsigned char code s[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //digital tube 0---9

unsigned int task_delay[TASK_NUM]; //Define the delay required for each task 

unsigned int i=0;

void Init_Timer0(){

 

   EA=1;

   ET0=1;

   TR0=1;

   TMOD=0x02;

   TH0=TL0=256-100; //12M crystal oscillator 10000Hz

}

void task0(){ // Task function

 

 P0=~P0;

}

void task1(){ // Task function

 

 P1=~P1;

}

void main(){

 

 Init_Timer0();

 

 while(1){

 

  if(task_delay[0]==0){task0();task_delay[0]=FRE(1);} // Scan task function

  if(task_delay[1]==0){task1();task_delay[1]=FRE(10);} // Scan task function

  

 }

 

}

void timer0()interrupt 1{

 

 for(i=0;i

  if(task_delay[i])

   --task_delay[i];

  

 

}


Reference address:The simplest multi-tasking template for MCU

Previous article:Several issues that should be noted in keil C
Next article:A non-preemptive operating system architecture based on C51 single-chip microcomputer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号