51单片机循环轮询多任务编程
2018-12-15杜隆胤方冰郑军
杜隆胤 方冰 郑军
摘 要: 针对51单片机内存资源非常有限,很难布设操作系统,从而导致51单片机中多个功能有机融合比较困难的问题,首先分析了使用轻型的循环轮询多任务编程思想在51单片机编程中的优势;然后针对真实任务中存在阻塞问题,讲述了如何对真实任务进行分解以满足系统实时性要求;最后分析了循环轮询系统中周期性实时任务和非周期性实时任务的触发方式,设计出了较为通用的、以周期性实时任务和中断服务任务为基本触发源的系统实现模板。
关键词: 51单片机; 循环轮询系统; 多任务; 触发条件
中图分类号:TP368.1 文献标志码:A 文章编号:1006-8228(2018)10-01-03
Abstract: This paper is aimed at the problem that it's difficult to implement multifunctional system in 51 single chip microcomputer, because the RAM of 51 single chip microcomputer is so limited that it's impossible to place operating system into it. The advantage of the method of polling loop system multitask programming is analyzed. The really task is divided into a lot of tasks in order to ensure the real-time characteristic of the system, and avoid the task to be blocked. The trigger conditions of periodic real-time task and aperiodic real-time task are analyzed, and a software template for 51 single chip microcomputer with the basic trigger sources of periodic real-time tasks and interrupt service tasks is designed.
Key words: 51 single chip microcomputer; polling loop system; multitask; trigger condition
0 引言
今天,智慧城市、智慧小区、数字化校园等概念逐步深入人们的生活,嵌入式系统正悄然进入到人们的生活。作为低成本、低功耗和易上手的嵌入式芯片典型代表——51单片机一开始就成为嵌入式家族中不可或缺的重要一分子[1]。但是,51单片机最典型的缺点就是片载资源少,一般不能采用操作系统作为系统的支撑,这就使得系统实现时缺少了进程或任务的概念。在实现一些较复杂的应用时,多个真实任务相互制约使得系统实现非常困难,也为调试带来较大的挑战。因此、研究如何在51单片机有限资源的环境里实现轻型任务、以实现多任务编程以降低系统实现难度是非常有意义的。特别对于一些刚接触51编程的人来说,多任务的思想无疑为编码和调试带来极大的便利。……
