#include <intrins.h>
#include "reg51.h"
#include "DS1302-2.h"
#include "keyscan.h"
#include "LEDdisplay.h"
#include "DS18B20.h"
#include <rtx51tny.h> /* RTX51 tiny functions & defines */
#define BEE P3^7
#define BEON P3 &= 0xBF
#define BEOFF P3 |= 0x40
#define uint unsigned int
#define uchar unsigned char
#define Pass 1
#if Pass
sbit PLed = P2^3;
#else
sbit PLed = P1^0; //LED Sec flash
#endif
/*
sbit Set = P3^2; //设置调整
sbit Up = P3^3; //向上调整
sbit Down = P3^4; //向下调整
sbit BEEP = P1^7; //提示音输出
*/
#define FullTask 1
#if FullTask
//定义任务数量:
#define Init 0 //任务初始化
#define Display 1 //显示任务
#define ReadTime 2 //读取当前时间任务
#define ReadTemp 3 //读取当前测试任务
#define DS18BInit 4 //初始化DS18B20并延时准备读取温度值
#define TimerSet 5 //设置时间任务
#define ModeKey 6
#else //调试模式简化任务数量
//define task NO.
#define Init 0 //Init
#define TimerSet 1 //Display
#define ReadTime 2 //Read time
#endif
#undef FullTask
//unsigned char code Bit_Tab[6] = {0x01,0x02,0x04,0x08,0x10,0x20}; //NPN
//unsigned char code Bit_Tab[6] = {0xFE,0xFD,0xFB,0xF7,0xEF,0xDF}; //PNP
bit Time_flag = 0; //按键第一次按下时停止时钟
unsigned char KeyCount; //按键状态计数
unsigned char DisplayBuffer[4] = {0,0,0,0}; //显示缓冲
void job(void) _task_ Init //任务初始化
{
DS1302_RST = 0;
DS18B20_Init_Jindu(); //调整DS18B20转换精度
//获得当前时间
os_create_task(Display);
os_create_task(ModeKey);
os_create_task(ReadTime);
os_create_task(DS18BInit);
// Initial_DS1302();
_nop_();
_nop_();
DS1302_GetTime();
os_delete_task(Init);
}
void ReadModeKey(void) _task_ ModeKey //按键检测任务
{
static unsigned char Count = 0;
static unsigned int ReadDsTemp = 0; //读取温度值&延时
static bit Flag_mode = 0; //温度与时间显示转换标志
while(1)
{
if(!Set) //读取当TimerSet按键
{
os_delete_task(ReadTemp);
os_create_task(TimerSet); //进入时钟设置模式
os_delete_task(ModeKey); //删除当前模式
}
else
{
Count = 0;
}
ReadDsTemp++; //垒加
ReadDsTemp &= 0x03ff; //防溢出
if(ReadDsTemp == 0) //开始转换显示温度
{
Flag_mode = 1;
PLed = 1; //显示温度秒不闪闪
os_create_task(ReadTemp);
}
if(ReadDsTemp == 0x015f) //开始转换显示时间
{
os_send_signal(ReadTime);
Flag_mode = 0;
}
if(!Flag_mode)
{
if((ReadDsTemp & 0x7F) == 0)
{
os_send_signal(ReadTime); //读取当前时间,间隔0.9S
}
if((ReadDsTemp & 0x1F) == 0)
{
PLed = !PLed; //秒每间隔0.3S闪一次
}
if((ReadDsTemp & 0x1ff) == 0)
{
os_send_signal(DS18BInit); //初始化DS18B20准备读取温度
}
}
os_wait2(K_TMO,2);
}
}
void LedDisplay(void) _task_ Display //数码管显示任务
{
while(1)
{
os_wait2(K_TMO,2);
display(); //显示当前时间
}
}
void DisplaySet(void) _task_ TimerSet //时间调整任务
{
static unsigned int count = 0; //read time jiange
static unsigned char Key_count = 0; //按键判断
static bit KeyR = 0; //防止反复读入Key值
while(1)
{
os_wait2(K_TMO,2);
if(!Set)
{
if(!KeyR)
{
Key_count++;
if(Key_count > 8) //防抖
{
KeyR = 1;
di(100);
KeyCount ++; //设置模式加1
count = 0;
Time_flag = 0; //停止时钟
PLed = 0; //秒灯常亮
Key_count = 0;
}
}
}
else
{
Key_count = 0;
KeyR = 0;
if(KeyCount == 0)
{
timedone();
Key_count = 0;
KeyR = 0;
Time_flag = 0;
count = 0;
os_send_signal(ReadTime);
os_create_task(ModeKey);
os_delete_task(TimerSet);
}
}
timedone();
count++;
if(count > 0x3fff)
{
count = 0;
KeyCount = 0;
}
}
}
void DS_Init(void) _task_ DS18BInit //读取测试初始化
{
static unsigned char count = 0;
while(10)
{
os_wait1(K_SIG);
if(!(Ds18b20_Init()))
{
Ds18b20_WriteByte(0xcc); //铬?ROM
Ds18b20_WriteByte(0x44); //?????
}
else
{
count++;
if(count > 6)
{
count = 0;
}
else
{
os_send_signal(DS18BInit);
}
}
}
}
void DS_ReadTemp(void) _task_ ReadTemp //读取温度
{
unsigned char tempL = 0,tempH = 0,temp = 0;
unsigned char TempValue = 0;
while(1)
{
os_wait2(K_TMO,10);
TR0 =0;
Ds18b20_Init();
Ds18b20_WriteByte(0xcc); //铬?ROM
Ds18b20_WriteByte(0xbe); //??誹
tempL = Ds18b20_ReadByte();
tempH = Ds18b20_ReadByte();
TR0 = 1;
if(tempH & 0xF0)
{
tempH = ~tempH;
tempL = (~tempL)+1;
temp = 1;
}
TempValue = tempH << 4;
TempValue |= (tempL >> 4);
if(temp == 1)
{
CurrentTimeYear = 22;
}
else
{
CurrentTimeYear = 0;
}
CurrentTimeHour = TempValue/10;
CurrentTimeSecond = TempValue%10;
CurrentTimeMinute = TempCharC;
os_delete_task(ReadTemp);
}
}
void ReadTime_Sec(void) _task_ ReadTime
{
while(1)
{
DS1302_GetTime();
os_wait1(K_SIG);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于RTX-51 Tiny多任务系统设计 #define Init 0 //任务初始化 #define Display 1 //显示任务 #define ReadTime 2 //读取当前时间任务 #define ReadTemp 3 //读取当前测试任务 #define DS18BInit 4 //初始化DS18B20并准备读取温度值 #define TimerSet 5 //设置时间任务 #define ModeKey 6 //按键检测任务
资源推荐
资源详情
资源评论
收起资源包目录
KeilC51.rar (38个子文件)
KeilC51
CONF_TNY.OBJ 4KB
Test
Last Loaded DS1302-Rtx.DBK 180KB
DS1302-Rtx.DSN 180KB
main.lst 10KB
DS1302.plg 1KB
STARTUP.LST 14KB
DS1302.uvopt 62KB
CONF_TNY.A51 18KB
OutFile
DS1302-pass.lnp 158B
DS1302-pass2.hex 7KB
DS1302-pass2 35KB
DS1302-pass2.plg 17KB
main.__i 165B
main.obj 35KB
DS1302-pass.plg 17KB
DS1302-pass2.lnp 160B
STARTUP.obj 849B
CONF_TNY.obj 4KB
DS1302-pass.hex 9KB
DS1302-pass 38KB
include
keyscan.h 6KB
DS1302-2.h 4KB
main.lst 141KB
CONF_TNY.lst 47KB
DS1302-pass2.m51 56KB
STARTUP.lst 14KB
main.i 15KB
DS18B20.h 7KB
LEDdisplay.h 4KB
DS1302-pass.m51 62KB
main.__i 79B
Csource
main.c 5KB
DS1302_uvproj.bak 13KB
CONF_TNY.LST 45KB
STARTUP.A51 6KB
DS1302.uvproj 13KB
DS1302_uvopt.bak 63KB
STARTUP.OBJ 749B
共 38 条
- 1
资源评论
- 小屁孩闹情绪2015-04-16不错,对我来说很有用
熊已出没
- 粉丝: 56
- 资源: 29
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功