//********************************
//产品名称: NEW_KJ09H
//使用MCU: S3F9454
//FOSC = 3.2MHZ
//********************************
#include "ioS3C9454.h"//
#include "iobit.h" //IO端口位操作定义文件
#include "intrinsics.h"//包含内部函数
//************************************************
//**此处为宏定义替换******
#define uchar unsigned char
#define uint unsigned int
#define nop (__no_operation())
#define di (__disable_interrupt())
#define ei (__enable_interrupt())
//************************************************
//**此处定义程序所用到的全局变量*******
uchar RUNFLAG = 0;
uchar DISPFLAG = 0;
uchar ERRFLAG = 0; //错误代码标志寄存器
uchar TMR_1SL = 0; //定时器1S计数器低位
uchar TMR_1SH = 0; //定时器1S计数器高位
uchar SECOND = 0; //定时器秒计数器
uchar IGBTAD_DT = 0; //IGBT温度检测值
uchar KEY_CODE = 0; //键扫描码
uchar FUNC_LOOP = 0; //功能执行步定义
uchar CURAD_DT = 0; //当前运行电流电压检测值
uchar HSRAD_DT = 0; //炉盘热敏温度检测值
uchar FIRE_SELE = 0; //
uchar IM_LOOP = 0; //间歇加热模式计数器
uchar DELAY_3S = 0; //3S延时计数器
uchar DELAY_2M = 0; //2分钟延时计数器
uchar DELAY_FREE = 0; //间歇延时计数器
uchar DELAY_RUN = 0; //加热延时计数器
uchar DELAY_PV = 0; //电源电压异常时延时计数器
uchar DELAY_2H = 0; //2小时关机定时器
uchar PVAD_DT = 0; //电源电压检测值
uchar TMR_FAST = 0; //
uchar DIGITA = 0; //
uchar DIGITB = 0; //
uchar DIGITC = 0; //
uchar DIGITD = 0; //
uchar SEG_A = 0; //
uchar SEG_B = 0; //
uchar SEG_C = 0; //
uchar SEG_D = 0; //
uchar LED_LOOP = 0; //
uchar TMRFLAG = 0; //
uchar DELAY_HOTA = 0; //
uchar DELAY_HOTB = 0; //
uchar DELAY_HOTC = 0; //
//*************************************************************************
//**位变量操作宏定义
//系统运行操作标志位定义
#define Set_KeyDown (RUNFLAG = RUNFLAG | 0x1)
#define Set_NoFz (RUNFLAG = RUNFLAG | 0x2)
#define Set_ImMode (RUNFLAG = RUNFLAG | 0x4)
#define Set_NoAd (RUNFLAG = RUNFLAG | 0x8)
#define Set_HandStart (RUNFLAG = RUNFLAG | 0x10)
#define Set_OnOff (RUNFLAG = RUNFLAG | 0x20)
#define Set_FastMode (RUNFLAG = RUNFLAG | 0x40)
#define Clr_KeyDown (RUNFLAG = RUNFLAG & ~0x1)
#define Clr_NoFz (RUNFLAG = RUNFLAG & ~0x2)
#define Clr_ImMode (RUNFLAG = RUNFLAG & ~0x4)
#define Clr_NoAd (RUNFLAG = RUNFLAG & ~0x8)
#define Clr_HandStart (RUNFLAG = RUNFLAG & ~0x10)
#define Clr_OnOff (RUNFLAG = RUNFLAG & ~0x20)
#define Clr_FastMode (RUNFLAG = RUNFLAG & ~0x40)
#define Test_KeyDown (RUNFLAG & 0x1)
#define Test_NoFz (RUNFLAG & 0x2)
#define Test_ImMode (RUNFLAG & 0x4)
#define Test_NoAd (RUNFLAG & 0x8)
#define Test_HandStart (RUNFLAG & 0x10)
#define Test_OnOff (RUNFLAG & 0x20)
#define Test_FastMode (RUNFLAG & 0x40)
#define Com_FastMode (RUNFLAG = RUNFLAG ^ 0x40)
//系统显示标志位定义
#define Set_DesMode (DISPFLAG = DISPFLAG | 0x1)
#define Set_TmrWait (DISPFLAG = DISPFLAG | 0x2)
#define Set_FireWait (DISPFLAG = DISPFLAG | 0x4)
#define Set_PvWait (DISPFLAG = DISPFLAG | 0x8)
#define Set_DiFireDisp (DISPFLAG = DISPFLAG | 0x10)
#define Set_DiTmrDisp (DISPFLAG = DISPFLAG | 0x20)
#define Set_DiFireTmr (DISPFLAG = DISPFLAG | 0x40)
#define Set_TmrMode (DISPFLAG = DISPFLAG | 0x80)
#define Clr_DesMode (DISPFLAG = DISPFLAG & ~0x1)
#define Clr_TmrWait (DISPFLAG = DISPFLAG & ~0x2)
#define Clr_FireWait (DISPFLAG = DISPFLAG & ~0x4)
#define Clr_PvWait (DISPFLAG = DISPFLAG & ~0x8)
#define Clr_DiFireDisp (DISPFLAG = DISPFLAG & ~0x10)
#define Clr_DiTmrDisp (DISPFLAG = DISPFLAG & ~0x20)
#define Clr_DiFireTmr (DISPFLAG = DISPFLAG & ~0x40)
#define Clr_TmrMode (DISPFLAG = DISPFLAG & ~0x80)
#define Test_DesMode (DISPFLAG & 0x1)
#define Test_TmrWait (DISPFLAG & 0x2)
#define Test_FireWait (DISPFLAG & 0x4)
#define Test_PvWait (DISPFLAG & 0x8)
#define Test_DiFireDisp (DISPFLAG & 0x10)
#define Test_DiTmrDisp (DISPFLAG & 0x20)
#define Test_DiFireTmr (DISPFLAG & 0x40)
#define Test_TmrMode (DISPFLAG & 0x80)
//系统定时操作标志位定义
#define Set_HalfSedA (TMRFLAG = TMRFLAG | 0x1)
#define Set_HalfSedB (TMRFLAG = TMRFLAG | 0x2)
#define Set_HalfSedC (TMRFLAG = TMRFLAG | 0x4)
#define Set_OneSedA (TMRFLAG = TMRFLAG | 0x8)
#define Set_OneSedB (TMRFLAG = TMRFLAG | 0x10)
#define Set_OneSedC (TMRFLAG = TMRFLAG | 0x20)
#define Set_OneSedD (TMRFLAG = TMRFLAG | 0x40)
#define Clr_HalfSedA (TMRFLAG = TMRFLAG & ~0x1)
#define Clr_HalfSedB (TMRFLAG = TMRFLAG & ~0x2)
#define Clr_HalfSedC (TMRFLAG = TMRFLAG & ~0x4)
#define Clr_OneSedA (TMRFLAG = TMRFLAG & ~0x8)
#define Clr_OneSedB (TMRFLAG = TMRFLAG & ~0x10)
#define Clr_OneSedC (TMRFLAG = TMRFLAG & ~0x20)
#define Clr_OneSedD (TMRFLAG = TMRFLAG & ~0x40)
#define Test_HalfSedA (TMRFLAG & 0x1)
#define Test_HalfSedB TMRFLAG & 0x2)
#define Test_HalfSedC (TMRFLAG & 0x4)
#define Test_OneSedA (TMRFLAG & 0x8)
#define Test_OneSedB (TMRFLAG & 0x10)
#define Test_OneSedC (TMRFLAG & 0x20)
#define Test_OneSedD (TMRFLAG & 0x40)
//P0端口功能定义
#define Set_AutoLed Set_P00
#define Set_HandLed Set_P01
#define Test_AutoLed Test_P00
#define Test_HandLed Test_P01
#define Clr_AutoLed Clr_P00
#define Clr_HandLed Clr_P01
#define Com_AutoLed Com_P00
#define Com_HandLed Com_P01
//P1端口功能定义
#define Set_164sdt Set_P10
#define Set_164sck Set_P11
#define Clr_164sdt Clr_P10
#define Clr_164sck Clr_P11
#define Set_FansPfd Set_P20
#define Set_LedACtrl Set_P21
#define Set_LedBCtrl Set_P22
#define Set_LedCCtrl Set_P23
#define Set_LedDCtrl Set_P24
#define Set_FastLed Set_P25
#define Clr_FansPfd Clr_P20
#define Clr_LedACtrl Clr_P21
#define Clr_LedBCtrl Clr_P22
#define Clr_LedCCtrl Clr_P23
#define Clr_LedDCtrl Clr_P24
#define Clr_FastLed Clr_P25
#define Com_FansPfd Com_P20
#define Com_FastLed Com_P25
#define Test_FansPfd Test_P20
//部分通用宏操作定义
#define Clr_WatchDog (BTCON = BTCON | 0x2)
#define Test_ADOK (ADCON & 0x8)
//*************************************************************************
//***程序所用函数声明*****
//***凡程序中所用到的函数请先在这里声明***
__interrupt void int_9454();
extern void beep();
void chip_init();
void TmrCheck();
void AutoTea();
void PwmCtrl();
void ImCheck();
void ConvertCode();
void DigitConvert();
void ErrCodeConvert();
void KeyScan();
uchar KeyTest();
void FzCheck();
void Current_Check();
void Delay(unsigned int);
void V18Check();
void HsrCheck();
void IgbtCheck();
void PvCheck();
void Beep(uchar);
void LedScan();
void SendTo164(uchar);
//*************************************************************************
//**定义9454的SMART OPTION值****
//**003CH,must be initialized to 0
//**003DH,must be initialized to 0
//**003EH,enable LVR(2.3V)
//**003FH,internal RC(3.2MHZ in Vdd=5V)
//*************************************
__code const volatile uchar SmartOption[4] @0x003c = {0x0,0x0,0xe7,0x03};
//*************************************************************************
//出错代码值定义
#define ERC_PVH 0x1
#define ERC_PVL 0x2
#define ERC_IGBT_OPEN 0x3
#define ERC_IGBT_HOT 0x4
#define ERC_HSR_OPEN 0x5
#define ERC_HSR_HOT 0x6
#define FAST_KEY 0x1
#define AUTO_KEY 0x2
#define HAND_KEY 0x3
#define OFF_KEY 0x4
#define NO_KEY 0xff
#define FUNC_OK 0x80
//*************************************************************************
//数码管显示代码定义(在ROM=0X40)
__code const volatile uchar DigitCode[12] @0x0040 =
{
0x03, //'0'
0x9f, //'1'
0x25, //'2'
0x0d, //'3'
0x99, //'4'
0x49, //'5'
0x41, //'6'
0x1f, //'7'
0x01, //'8'
0x09, //'9'
0xff, //'A'
0x61, //'E'
};
//**************************************************************************
//========================主程序控制===========================
void main(void)
{
//***填充系统SMART OPTION***/
uchar buffer = SmartOption[0];
asm("LD R0,#1");
asm("LD RUNFLAG,R0");
asm("LD P0,R0");
//***初始化过程***//
chip_init();
main_start:
//***主循环开始***//
ei;
Clr_OnOff;
Clr_AutoLed;
Clr_HandLed;
Clr_FastLed;
TMRFLAG = 0;
DISPFLAG = 0;
DELAY_2M = 0;
KEY_CODE = 0;
PWMDATA = 0;
asm("and RUNFLAG,#0x1");
ConvertCode();
if (ERRFLAG)
{
Beep(4);
Delay(50);
Beep(4);
Delay(50);
Beep(4);
Delay(50);
Beep(4);
}
else
{
Beep(0xf);
}
while(!Test_OnOff)
{
asm("push ERRFLAG");
IgbtCheck();
asm("pop ERRFLAG");
if (IGBTAD_DT <= 0x28)
Clr_FansPfd;
else if (IGBTAD_DT > 0x66)
Set_FansPfd;
KeyScan();
}
//启动初始化
DELAY_2H = 0;
DELAY_2M = 0;
FIRE_SELE = 0x2;
//***工作循环开始***//
while(Test_OnOff)
{
//按键检查//
ERRFLAG = 0;
KeyScan();
if (!Test_OnOff)
break;
//电源电压及18V电压检查//
if (Test_PvWait)
goto tmr_check;
V18Check();
if (ERRFLAG)
{
DELAY_PV = 0x3;
goto wait_pv;
}
else
{
PvCheck();
if (!ERRFLAG)
goto chk_hsr;
DELAY_PV = 0;
}
//如果电压出错,则等待2-3S//
wait_pv:
ERRFLAG = 0;
Set_NoFz;
Set_NoAd;
Clr_ImMode;
Set_PvWait;
PWMDATA = 0;
goto tmr_check;
//炉盘热敏检查//
chk_hsr:
HsrCheck();
if (ERRFLAG)
break;
//IGBT热敏检查//
IgbtCheck();
if (ERRFLAG)
break;
//间断加热工作检查//
ImCheck();
//加锅状态检查//
FzCheck();
if (!Test_OnOff)
break;
//功率控制输出检查//
PwmCtrl();
//检查当前工作状态//
if (Test_FastMode)
{
//如果选择了快速加热模式//
FIRE_SELE = 0x1;
if ((KEY_CODE == AUTO_KEY)&&(TMR_FAST > 0x78))
{
Clr_FastMode;
Clr_FastLed;
FIRE_SELE = 0x2;
}
else if ((KEY_CODE == HAND_KEY)&&(TMR_FAST > 0xf0))
{
Clr_FastMode;
Clr_FastLed;
FIRE_SELE = 0x2;
}
}
//检查自动泡茶状态//
if (KEY_CODE == AUTO_KEY)
{
AutoTea();
}
tmr_check:
//显示代码转换及定时运行检查//
ConvertCode();
TmrCheck();
}
goto main_start;
}
//******************************************************************
//****启动时IO初始化子过程******
void chip_init()
{
Clr_KeyDown;
BTCON = 0xa3; //Watch-dog disable
CLKCON = 0x18; //selet non-divided CPU clock
P0PND = 0x0; //P0/INT disable
P0CONH = 0xdf; //P0.7 is as A/D convert port
//P0.6 is PWM output
//P0.5 is as A/D convert port
//P0.4 is as A/D convert port
P0CONL = 0xfa; //P0.3 is as A/D convert port
//P0.2 is as A/D convert port
//P0.0,P0.1 is as push-pull output port
P0 = 0x0;
P1CON = 0xa; //P1.0 is as push-pull output port
//P1.1 is as push-pull output port
P1 = 0x0;
P2CONH = 0x2a; //P2.0-P2.5 is as push-pull output
P2CONL = 0xaa; //P2.6 is as A/D input
P2 = 0x1e;
PWMDATA = 0x0;
PWMCON = 0x5c; //PWM input clock is fosc/8,enable PWM output
//reload from 6 bit coun
T0DATA = 0x32;
T0CON =0x4a; //TMR0 start count,f=fosc/256
//enable TMR0 interrupt/4ms
P2 = 0xff;
SEG_A = 0xff;
SEG_B = 0xff;
SEG_C = 0xff;
SEG_D = 0xff;
Delay(500);
P2 = 0x0;
PvCheck();
if (ERRFLAG)
{
goto init_back;
}
IgbtCheck();
if (!ERRFLAG)
{
goto hsr_chk;
}
Set_FansPfd;
goto init_back;
hsr_chk:
HsrCheck();
//***初始化出口***//
init_back:
return;
}
//**********************************************************************
//功率控制PWM输出子过程
void PwmCtrl()
{
uchar set;
////////////////
if ((Test_NoFz)||(Test_NoAd)) //如果当前未加锅或处于禁止控制状态,则不予处理
goto pwm_back;
di;
switch(FIRE_SELE)
{
case 1:
set = 0xff;
break;
case 2:
set = 0xba;
break;
default:
set = 0x90;
break;
}
if (PWMDATA > set)
{
if (PWMDATA > 0x2)
PWMDATA--;
}
else if (PWMDATA < set)
{
if (PWMDATA < 0xfc)
PWMDATA++;
}
pwm_back:
ei;
return;
}
//**********************************************************************
//定时运行检查子过程
void TmrCheck()
{
if (!Test_OneSedB)
goto tmr_back;
Clr_OneSedB;
di;
if (!Test_PvWait)
{
if (DELAY_2H < 0x78)
goto tmr_back;
Clr_OnOff;
goto tmr_back;
}
DELAY_PV++;
if (DELAY_PV < 0x5)
goto tmr_back;
PvCheck();
if (!ERRFLAG)
V18Check();
Clr_OnOff;
if (!ERRFLAG)
{
Set_OnOff;
Clr_PvWait;
}
tmr_back:
ei;
return;
}
//*************************************************************************
//间断加热模式控制子过程
void ImCheck()
{
Clr_WatchDog;
if ((Test_NoFz)||(!Test_ImMode)||(!Test_OneSedD))
goto im_back;
di;
if (IM_LOOP--)
goto im_back;
if (!Test_NoAd)
{
Clr_NoAd;
Set_NoFz;
DELAY_3S = 0xf0;
IM_LOOP = DELAY_RUN;
goto im_back;
}
else
{
Set_NoAd;
PWMDATA = 0;
IM_LOOP = DELAY_FREE;
}
im_back:
ei;
return;
}
//*************************************************************************
//整机显示转换子过程
void ConvertCode()
{
Clr_WatchDog;
di;
if (!Test_OnOff)
{
if (ERRFLAG)
ErrCodeConvert();
else
{
SEG_A = 0xff;
SEG_B = 0xff;
SEG_C = 0xff;
SEG_D = 0xff;
}
goto cvt_back;
}
DIGITA = 0xa;
DIGITC = 0;
DIGITD = 0;
switch(FIRE_SELE)
{
case 1:
DIGITA = 0x1;
DIGITB = 0x2;
break;
case 2:
DIGITB = 0x9;
break;
case 3:
DIGITB = 0x6;
break;
case 4:
DIGITB = 0x2;
break;
default:
SEG_A = 0xff;
SEG_B = 0xff;
SEG_C = 0xff;
SEG_D = 0x3;
goto cvt_back;
}
DigitConvert();
cvt_back:
ei;
return;
}
//*************************************************************************
//错误显示代码转换子过程
void ErrCodeConvert()
{
DIGITA = 0xa;
DIGITB = 0xb;
DIGITC = ERRFLAG;
DIGITD = 0xa;
DigitConvert();
}
//*************************************************************************
//数码管显示转换子过程
void DigitConvert()
{
Clr_WatchDog;
SEG_A = DigitCode[DIGITA];
SEG_B = DigitCode[DIGITB];
SEG_C = DigitCode[DIGITC];
SEG_D = DigitCode[DIGITD];
return;
}
//*************************************************************************
//自动泡茶控制子过程
void AutoTea()
{
if ((Test_NoFz) || (!Test_OneSedA))
goto tea_back;
Clr_OneSedA;
if (FUNC_LOOP & 0x1)
goto tea_start;
if (FUNC_LOOP & 0x2)
goto tea_second;
if (FUNC_LOOP & 0x4)
goto tea_third;
if (FUNC_LOOP == FUNC_OK)
goto tea_ok;
goto tea_back;
tea_start:
FUNC_LOOP = 0x1;
Set_FansPfd;
Clr_ImMode;
Set_NoFz;
Clr_NoAd;
FIRE_SELE = 0x2;
DELAY_HOTA = 0;
DELAY_HOTB = 0;
DELAY_HOTC = 0;
FUNC_LOOP <<= 1;
tea_second:
//首先予加热1M
if (DELAY_HOTC <= 0x3c)
{
DELAY_HOTC++;
if (DELAY_HOTC < 0x3c)
goto tea_back;
if ((!Test_HandStart)&&(HSRAD_DT < 0x8a))
goto hot_stop;
goto tea_back;
}
if (HSRAD_DT >= 0x80)
{
//予加热6.5M
DELAY_HOTA++;
if (DELAY_HOTA < 0xa)
goto tea_back;
DELAY_HOTA = 0;
DELAY_HOTB++;
if (DELAY_HOTB < 0x27)
goto tea_back;
}
DELAY_HOTA = 0x78;
FUNC_LOOP <<= 1;
tea_third:
//延时90S
FIRE_SELE = 0x3;
if ((DELAY_HOTA--)&&(HSRAD_DT > 0x66))
goto tea_back;
hot_stop:
Clr_HandStart;
PWMDATA = 0;
Clr_ImMode;
Set_NoAd;
Beep(0xf);
FIRE_SELE = 0x4;
FUNC_LOOP = FUNC_OK;
tea_ok:
Com_AutoLed;
if (HSRAD_DT >= 0xa0)
{
FUNC_LOOP = 0x1;
goto tea_start;
}
tea_back:
ei;
return;
}
//*************************************************************************
//按键扫描处理子过程
void KeyScan()
{
uchar key1,key2,key3;
///////////////
di;
Clr_WatchDog;
key1 = KeyTest();
Delay(2);
key2 = KeyTest();
if (key1 != key2)
goto key_back;
Delay(2);
key3 = KeyTest();
if (key3 != key2)
goto key_back;
if (key3 == 0xff)
{
Clr_KeyDown;
goto key_back;
}
if (Test_KeyDown)
goto key_back;
Set_KeyDown;
if ((!Test_OnOff) && (key3 == OFF_KEY))
goto key_back;
switch(key3)
{
case FAST_KEY:
goto fast_key_set;
case AUTO_KEY:
goto auto_key_set;
case HAND_KEY:
goto hand_key_set;
case OFF_KEY:
goto off_key_set;
default:
break;
}
off_key_set:
Clr_OnOff;
ERRFLAG = 0;
goto key_back;
hand_key_set:
if (!Test_FastMode)
{
if (KEY_CODE == HAND_KEY)
goto key_back;
FUNC_LOOP = 0x1;
}
KEY_CODE = HAND_KEY;
Set_HandLed;
Clr_AutoLed;
Clr_FastMode;
Clr_FastLed;
Set_OnOff;
goto key_press_back;
auto_key_set:
if (!Test_FastMode)
{
if (FUNC_LOOP == FUNC_OK)
KEY_CODE = 0;
if (KEY_CODE == AUTO_KEY)
goto key_back;
}
KEY_CODE = AUTO_KEY;
FUNC_LOOP = 0x1;
Set_HandStart;
Clr_HandLed;
Set_AutoLed;
Clr_FastMode;
Clr_FastLed;
Set_OnOff;
goto key_press_back;
fast_key_set:
if (!Test_OnOff)
{
Set_OnOff;
KEY_CODE = AUTO_KEY;
Set_AutoLed;
}
TMR_FAST = 0;
Com_FastLed;
Com_FastMode;
key_press_back:
Beep(4);
Set_NoFz;
Clr_NoAd;
Set_OnOff;
DELAY_2H = 0;
DELAY_3S = 0xf0;
FUNC_LOOP = 0x1;
FIRE_SELE = 0x2;
Set_FansPfd;
key_back:
ei;
return;
}
//*************************************************************************
//按键测试子过程(A/D转换方式进行)
uchar KeyTest()
{
uchar times = 0x5;
uchar high = 0xff;
di;
while(times)
{
ADCON = 0x87; //select P0.0 is as AD convert,input clock=Fosc/1
while(!Test_ADOK);
if (ADDATAH < high)
high = ADDATAH;
times--;
}
if (high > 0xf5)
return NO_KEY;
if (high < 0x19)
return FAST_KEY;
if (high < 0x66)
return AUTO_KEY;
if (high < 0x85)
return HAND_KEY;
if (high < 0xb3)
return OFF_KEY;
return NO_KEY;
}
//*************************************************************************
//加锅检测子过程
void FzCheck()
{
uchar times;
////////////////
Clr_WatchDog;
if (Test_NoAd)
goto fz_back;
di;
if (!Test_NoFz)
goto fz_test;
Delay(10);
DELAY_3S++;
if (DELAY_3S < 0x60)
goto fz_back;
DELAY_3S = 0;
PWMDATA = 0xa0;
Delay(200);
times = 0;
fz_test:
while(times < 0x1)
{
Current_Check();
if (!Test_NoFz)
break;
times++;
}
if (Test_NoFz)
goto no_fz;
ERRFLAG = 0;
DELAY_2M = 0;
goto fz_back;
no_fz:
PWMDATA = 0;
if (DELAY_2M > 0x3c)
{
Clr_OnOff;
goto fz_back;
}
DELAY_2M++;
Beep(4);
fz_back:
return;
}
//*************************************************************************
//加锅运行电流检查子过程
void Current_Check()
{
uchar times = 0x50;
CURAD_DT = 0x33;
while(times)
{
times--;
di;
Clr_WatchDog;
ADCON = 0x73;
while(!Test_ADOK);
if (ADDATAH < CURAD_DT)
CURAD_DT = ADDATAH;
ei;
}
Clr_NoFz;
if (CURAD_DT >= 0xe)
Set_NoFz;
return;
}
//*************************************************************************
//***延时子过程***//
//***以MS为单位,fosc=3.2MHZ,nop_cycle=1.25us
void Delay(unsigned int time)
{
uchar a,temp_sym;
/////////////
temp_sym = SYM;
ei;
while(time>0)
{
a = 123;
Clr_WatchDog;
while(a>0)
{
nop;
nop;
nop;
nop;
a--;
}
time--;
}
SYM = temp_sym;
}
//******************************************************************
//蜂鸣器驱动子过程,time为要鸣响的时间值以25MS为单位
void Beep(uchar time)
{
uchar timer;
asm("push T0DATA");
asm("push T0CON");
asm("push P2");
asm("push P2CONL");
LedScan();
P2CONL = P2CONL | 0x3;
T0CON = 0x88;
T0DATA = 0x32;
BTCON = 0xa3;
di;
while(time>0)
{
timer = 0;
while(timer<0xa) //每个计时周期为25MS
{
Clr_WatchDog;
while(BTCNT<0x2); //每上BT周期为2.56MS
Clr_WatchDog;
LedScan();
timer++;
}
time--;
}
ei;
Clr_WatchDog;
asm("pop P2CONL");
asm("pop P2");
asm("pop T0CON");
asm("pop T0DATA");
return;
}
//*************************************************************************
//电源电压检测子过程
void PvCheck()
{
uchar times,count,high,low;
times = 5;
high = 0x62;
low = 0x46;
if (!Test_PvWait)
{
high = 0x6d;
low = 0x3d;
}
while(times)
{
times--;
PVAD_DT = 0;
count = 0xa0;
Clr_WatchDog;
while(count)
{
di;
ADCON = 0x55;
while(!Test_ADOK);
if (ADDATAH > PVAD_DT)
PVAD_DT = ADDATAH;
ei;
count --;
}
if (PVAD_DT > high)
{
ERRFLAG = ERC_PVH;
continue;
}
if (PVAD_DT < low)
{
ERRFLAG = ERC_PVL;
continue;
}
ERRFLAG = 0;
break;
}
return;
}
//*************************************************************************
//IGBT温度检测子过程
void IgbtCheck()
{
uchar times;
times = 0;
while(times<=0xa)
{
times++;
di;
ADCON = 0x43; //select P0.4 as A/D,AD_CLK=Fosc/8
Clr_WatchDog;
while(!Test_ADOK);
ei;
ERRFLAG = ERC_IGBT_OPEN;
if ((ADDATAH != 0)&&(ADDATAH <= 0x80))
{
ERRFLAG = 0;
break;
}
}
IGBTAD_DT = ADDATAH;
return;
}
//*************************************************************************
//热敏电阻检测子过程
void HsrCheck()
{
uchar times;
times = 0;
HSRAD_DT = 0;
while(times<=0x5)
{
times++;
di;
Clr_WatchDog;
ADCON = 0x31; //select P0.3 as A/D,CLK=Fosc/16
while(!Test_ADOK);
ei;
if (ADDATAH < HSRAD_DT)
continue;
HSRAD_DT = ADDATAH;
}
if (HSRAD_DT > 0xfd)
{
ERRFLAG = ERC_HSR_OPEN;
goto hsr_exit;
}
if (HSRAD_DT < 0x33)
{
ERRFLAG = ERC_HSR_HOT;
goto hsr_exit;
}
hsr_exit:
ei;
return;
}
//*************************************************************************
//18V电源电压状态检查子过程
void V18Check()
{
uchar times;
times = 0xa;
while(times)
{
times--;
di;
ADCON = 0x23; //select P0.2 as A/D,clk=Fosc/8
while(!Test_ADOK);
ERRFLAG = ERC_PVL;
if (ADDATAH < 0x26)
continue;
if (ADDATAH > 0x3a)
continue;
ERRFLAG = 0;
break;
}
ei;
return;
}
//*************************************************************************
//LED扫描子过程
void LedScan()
{
//首先必须关闭所有LED显示
Clr_LedACtrl;
Set_LedBCtrl;
Set_LedCCtrl;
Set_LedDCtrl;
LED_LOOP = LED_LOOP << 1;
if (LED_LOOP == 0x1)
goto scan_leda;
if (LED_LOOP == 0x2)
goto scan_ledb;
if (LED_LOOP == 0x4)
goto scan_ledc;
if (LED_LOOP == 0x8)
goto scan_ledd;
LED_LOOP = 0x1;
scan_leda:
SendTo164(SEG_A);
Set_LedACtrl;
goto scan_back;
scan_ledb:
SendTo164(SEG_B);
Clr_LedBCtrl;
goto scan_back;
scan_ledc:
SendTo164(SEG_C);
Clr_LedCCtrl;
goto scan_back;
scan_ledd:
SendTo164(SEG_D);
Clr_LedDCtrl;
scan_back:
return;
}
//*************************************************************************
//74HC164的数据刷亲子过程
void SendTo164(uchar seg)
{
uchar count;
count = 0x8;
Clr_164sdt;
Clr_164sck;
//seg = 0xc0;
while(count)
{
if (seg & 0x1)
Set_164sdt;
else
Clr_164sdt;
Set_164sck;
nop;
nop;
nop;
Clr_164sck;
seg = seg >> 0x1;
count--;
}
return;
}
//*************************************************************************
//**中断向量及服务程序定义********
#pragma vector=0x00
__interrupt void int_9454()
{
T0CON = T0CON & 0xfe; //必须清T0中断标志
Clr_WatchDog;
LedScan();
TMR_1SH++;
if (TMR_1SH < 0xfa)
return;
TMR_1SH = 0;
Set_OneSedA;
Set_OneSedB;
Set_OneSedC;
Set_OneSedD;
TMR_FAST++;
SECOND++;
if (SECOND < 0x3c)
return;
SECOND = 0;
DELAY_2H++;
}
//*************************************************************************
本文引用于网络,未经测试。
//