📄 system.c
字号:
/*************************************************/
/**************类型定义及说明*************/
/***************2003年1月8日*******************/
/************WROTE BY WANGSW********************/
#include "reg52x2.h"
#include <intrins.h>
#include "define.h"
#include "rtc.h"
#include "routine.h"
#include "smart_timer.h"
static bool bEA;
static byte data i;
static byte data MsgPoolPoint=0;
static MSGTYPE data msgType;
static byte data MsgPool[MSG_STACK_DEPTH][2];
static byte data RTCCounter = 0;
byte data g_MsgReturnValue=0; /*for msg_queue_out return point*/
byte code g_DAA[100] = /*用于十进制调整*/
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31,
0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x60, 0x61, 0x62, 0x63,
0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95,
0x96, 0x97, 0x98, 0x99
};
/*r0~9,A~F的伪十六进制数字字符码表*/
byte code g_Data2Char[16] =
{
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46
};
/******************************************************************************************
*函数名: Timer2Server
*参数: 无
*返回值: 无
*描述: 定时器2中断服务程序,每5ms进入一次
*编写: 王绍伟
*版本信息: V1.0 2003年8月15日
******************************************************************************************/
static void Timer2Server(void) interrupt 5 /*不要带指定寄存器,否则将产生移位指令出错*/
{
ET2 = 0;
TF2 = 0; /*状态位必须得清除,否则中断占用时间很长*/
/***************/
smart_timer_server(); /*r进行智能时钟服务程序*/
if(++RTCCounter == 200)
{
RTCCounter = 0;
rtc_soft_routine(); /*定时器例行程序*/
}
routine_process(); /*r运行例行任务程序*/
/****************/
ET2 = 1;
}
/******************************************************************************************
*函数名: delay
*参数: wData 递减字值
*返回值: 无
*描述: 用来延迟一段时间
*编写: 王绍伟
*版本信息: V1.0 2003年8月15日
******************************************************************************************/
extern void delay(word wData)
{
while(wData--)
{
#ifdef SPEEDUP
_nop_();
_nop_();
_nop_();
#else
_nop_();
#endif
}
}
/******************************************************************************************
*函数名: msg_queue_in
*参数: msgType 消息类型
msgPoint 消息指针
*返回值: 无
*描述: 将消息添加到消息队列中去,消息堆栈最多记录4条消息.
*编写: 王绍伟
*版本信息: V1.0 2003年8月15日
******************************************************************************************/
extern void msg_queue_in(MSGTYPE msgType, MSGPOINT msgPoint)
{
if(MsgPoolPoint == MSG_STACK_DEPTH) /*r如果消息堆栈满了,则退出*/
{
return;
}
bEA = EA; /*r若消息堆栈未满,先将当前所有中断允许位保存起来*/
EA = 0; /*r暂时禁止一切中断,待处理完消息后恢复*/
MsgPool[MsgPoolPoint][0] = msgType;
MsgPool[MsgPoolPoint++][1] = msgPoint;
EA = bEA;
}
#ifdef FIFO /*r如果定义为先入先出*/
/******************************************************************************************
*函数名: msg_queue_out
*参数: 无
*返回值: MSG_NULL 当消息队列为空时返回MSG_NULL
msgType 当消息队列不为空时返回消息类型
*描述: 弹出消息队列中最早进入的消息类型.
*编写: 王绍伟
*版本信息: V1.0 2003年8月15日
******************************************************************************************/
extern byte msg_queue_out(void)
{
if(MsgPoolPoint == 0)
{
return(MSG_NULL);
}
bEA = EA;
EA = 0; /*r关断所有中断*/
g_MsgReturnValue = MsgPool[0][1]; /*r推出最早进入的消息*/
msgType = MsgPool[0][0];
if(--MsgPoolPoint) /*r如果消息队列未空,则剩余消息前移*/
{
for(i = 0; i < MsgPoolPoint; i++)
{
MsgPool[i][0] = MsgPool[i + 1][0];
MsgPool[i][1] = MsgPool[i + 1][1];
}
}
EA = bEA;
return(msgType);
}
#endif
#ifdef FILO
/*FILO 先入后出*/
/******************************************************************************************
*函数名: msg_queue_out
*参数: 无
*返回值: MSG_NULL 当消息队列为空时返回MSG_NULL
msgType 当消息队列不为空时返回消息类型
*描述: 弹出消息队列中最后进入的消息类型.
*编写: 王绍伟
*版本信息: V1.0 2003年8月15日
******************************************************************************************/
extern byte msg_queue_out(void)
{
if(MsgPoolPoint == 0)
{
return(MSG_NULL);
}
bEA = EA;
EA = 0;
g_MsgReturnValue = MsgPool[--MsgPoolPoint][1];
msgType = MsgPool[MsgPoolPoint][0];
EA = bEA;
return(msgType);
}
#endif
#ifdef PRIORITY
extern byte msg_queue_out(void)
{
if(MsgPoolPoint == 0)
{
return(MSG_NULL);
}
bEA = EA;
EA = 0;
if(MsgPoolPoint == 1)
{
g_MsgReturnValue = MsgPool[--MsgPoolPoint][1];
msgType = MsgPool[MsgPoolPoint][0];
EA = bEA;
return(msgType);
}
msgType =MsgPool[0][0];
g_MsgReturnValue = 0;
for(i = 1; i < MsgPoolPoint; i++)
{
if((msgType & 0xF0) < (MsgPool[i][0] & 0xF0))
{
msgType = MsgPool[i][0];
g_MsgReturnValue = i;
}
}
i = g_MsgReturnValue;
g_MsgReturnValue = MsgPool[i][1];
MsgPoolPoint--;
for(; i < MsgPoolPoint; i++)
{
MsgPool[i][0] = MsgPool[i + 1][0];
MsgPool[i][1] = MsgPool[i + 1][1];
}
EA = bEA;
return(msgType);
}
#endif
extern void msg_queue_clear(byte selMSG)
{
if(selMSG ==ALL)
{
MsgPoolPoint = 0;
}
else
{
bEA = EA;
EA = 0;
for(i = 0; i < MsgPoolPoint; i++)
{
if(MsgPool[i][0] == selMSG)
{
MsgPool[i][0] = MSG_NULL;
}
}
EA = bEA;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -