/======================================================
// The information contained herein is the exclusive property of
// Sunnnorth Technology Co. And shall not be distributed, reproduced,
// or disclosed in whole in part without prior written permission.
// (C) COPYRIGHT 2003 SUNNORTH TECHNOLOGY CO.
// ALL RIGHTS RESERVED
// The entire notice above must be reproduced on all authorized copies.
//========================================================
//============================================================
// 工程名称: DS18B20.spj
// 功能描述: 利用61板、LED键盘模组和DS18B20模块键盘实现多路温度采集
// 涉及的库: CMacro1016.lib
// sacmv26e.lib
// 组成文件: main.c, ds18b20_driver.c
// 18b20.asm, Key.asm, ISR.asm, Dig.asm, Sys.asm, hardware.asm
// 18b20.h, Key.h, Dig.h, Sys.h, S480.h,SPCE061A.h
// Key.inc, SPCE061A.inc, Dig.inc
// 硬件连接: 61板的IOA低8位(J8)与LED键盘模组的1*8KEY接口连接,
// 61板的IOA高8位(J9)与LED键盘模组的SEG接口连接,
// 61板的IOB高8位(J7)与LED键盘模组的DIG接口连接,
// 61板的IOB高8位(J6)与DS18B20模块的J1接口连接.
// 维护记录: 2006-10-10 v1.0
//===============================================
//======================================================
// 文件名称: main.c
// 功能描述: 获取DS18B20的温度并进行数据处理,以及按键处理和语音播放
// 维护记录: 2006-10-10 v1.0
//======================================================
#include "ds18b20_driver.h"
#include "spce061a.h"
#include "sys.h"
#include "key.h"
#include "dig.h"
#include "s480.h"
unsigned int Tep[4];
unsigned int V_Set[3];
float V_Alarm[2];
unsigned int g_Data[10] = {0x003f,0x0006,0x005b,0x004f,0x0066,0x006d,0x007d,0x0007,0x007f,0x006f};
unsigned int uiSet,uiSetChannel,uiChannel,uiSetbit,uiMode,uiTurn;
void Key_Process(unsigned int key);
void PlaySnd(unsigned int Index);
//========================================================================
// 语法格式: int main(void)
// 实现功能: 主函数
// 参数: 无
// 返回值: 无
//========================================================================
int main()
{
unsigned int key;
float fTemp;
V_Alarm[0] = 30;
V_Alarm[1] = 30;
uiTurn = 0;
uiMode = 1;
Key_Init();
DIG_Init();
Sys_Initial();
while(DS18B20_Initial(0) == 0); // 初始化DS18B20
while(DS18B20_Initial(1) == 0); // 初始化DS18B20
while(1)
{
if(uiSet == 0)
{
uiChannel = uiTurn;
fTemp = DS18B20_ReadTemp(uiChannel); // 进行一次测温并读取测量温度值
fTemp += 0.05; // 对百分位取四舍五入
Tep[0] = g_Data[(int) (fTemp*10)%10]; // 小数位
Tep[1] = g_Data[(int) fTemp%10]|0x0080; // 个位(带小数点)
Tep[2] = g_Data[(int) fTemp/10]; // 十位
DIG_Set(1,Tep[0]);
DIG_Set(2,Tep[1]);
DIG_Set(3,Tep[2]);
DIG_Set(4,g_Data[uiChannel+1]);
if(fTemp > V_Alarm[uiChannel] )
{
PlaySnd(uiChannel); // 通道
PlaySnd(uiChannel); // 1或2
PlaySnd(uiChannel); // 温度过高
PlaySnd(uiChannel); // 通道
}
}
key = Key_Get();
if (key != 0)
Key_Process(key);
*P_Watchdog_Clear = 0x0001;
}
}
//========================================================================
// 语法格式: void Key_Process(unsigned int key)
// 实现功能: 键处理
// 参数: key ,键值
// 返回值: 无
//========================================================================
void Key_Process(unsigned int key)
{
key &= 0x0007;
switch(key)
{
case 1: // 手动键
if(uiSet == 1) // 设置状态下
{
if(V_Set[uiSetbit] > 0)
V_Set[uiSetbit]--;
else
V_Set[uiSetbit] = 9;
DIG_Set(1,g_Data[V_Set[0]]);
DIG_Set(2,g_Data[V_Set[1]]|0x0080);
DIG_Set(3,g_Data[V_Set[2]]);
DIG_Set(4,g_Data[uiSetChannel+1]);
}
else
{
if(uiMode == 0) // 手动状态下
{ uiTurn ++; // 显示通道切换
if(uiTurn > 1)
uiTurn = 0;
}
else // 自动状态下
{
uiMode = 0; // 自动模式切换到手动模式
uiTurn = 0; // 显示通道0
}
}
break;
case 2: // 自动键
if(uiSet == 1) // 设置状态下
{
if(V_Set[uiSetbit] < 9)
V_Set[uiSetbit]++;
else
V_Set[uiSetbit] = 0;
DIG_Set(1,g_Data[V_Set[0]]);
DIG_Set(2,g_Data[V_Set[1]]|0x0080);
DIG_Set(3,g_Data[V_Set[2]]);
DIG_Set(4,g_Data[uiSetChannel+1]);
}
else
{
uiMode = 1; // 自动模式
uiTurn = 0;
}
break;
case 4: // 设置键
if(uiSet == 0) // 不在设置模式下
{
uiSet = 1;
uiSetChannel = 0;
uiSetbit = 0;
R_BlinkDIG = uiSetbit;
DIG_Blink_En(); // 开始闪烁
DIG_Set(1,g_Data[V_Set[0]]);
DIG_Set(2,g_Data[V_Set[1]]|0x0080);
DIG_Set(3,g_Data[V_Set[2]]);
DIG_Set(4,g_Data[uiSetChannel+1]);
}
else // 设置状态下
{
uiSetbit ++; // 切换设置位
if (uiSetbit > 2)
{
uiSetbit = 0;
V_Alarm[uiSetChannel] = V_Set[2]*10 + V_Set[1] + V_Set[0]*0.1;
uiSetChannel ++;
if (uiSetChannel > 1)
{
uiSet = 0;
DIG_Blink_Dis();
uiSetChannel = 0;
}
DIG_Set(4,g_Data[uiSetChannel+1]);
}
R_BlinkDIG = uiSetbit;
}
default :
break;
}
}
//========================================================================
// 语法格式: void PlaySnd(unsigned int Index)
// 实现功能: S480语音播放
// 参数: Index 语音索引号
// 返回值: 无
//========================================================================
void PlaySnd(unsigned int Index)
{
SACM_S480_Initial(1);
SACM_S480_Play(Index,3,3);
while((SACM_S480_Status()&0x0001)!=0)
{
SACM_S480_ServiceLoop();
*P_Watchdog_Clear = 1;
}
SACM_S480_Stop();
}