HolTek单片机的问题?
我的程序怎么不能用啊,好像没有任何反应?
/*=======================================
* Project Name: Power_Display
* Program Name: PowDly
* Author: Tao Shan Biao
* Copyright: Tao Shan Biao
* CPU: ht46r064
* Virsion: 1.0
* Project Start Time: 2011-07-24
* Modify Comment: Non
=======================================*/
#include "HT46R064.h"
#define S1 _pb5
#define S2 _pa6
#define S3 _pb4
#define DCUP _pa1
#define ExtPowConnect _pa3
#define iPadConnect _pa2
unsigned long int P_count0;
unsigned char P_count1;
unsigned char P_count2;
unsigned long int halt_count0;
unsigned char halt_count1;
unsigned char LED_DisplayBuffer;
unsigned char Pow_grade;
unsigned char charge_count1;
unsigned char charge_count2;
//-------------------------------------------------------------------------
#pragma vector isr_4 @ 0x04 //外部中断
#pragma vector isr_8 @ 0x08 //定时/计数器0溢出中断
#pragma vector isr_c @ 0x0c //A/D转换完成中断
#pragma vector isr_10 @ 0x10 //时基溢出中断
void isr_4()
{
}
void isr_8(){}
void isr_c(){}
void isr_10(){}
//-------------------------------------------------------------------------
void init_MCU(void)
{
_ctrl1 = 0xCA; //INT外部中断触发方式:双边沿,时基最小,WDT关闭
_wdts = 0x07; //设置定时器最大周期
_clkmod = 0; //振荡器低功耗模
_qosc = 1; //使用HIRC作为系统时
_pbc = 0; //设置B端口为输
_pac = 0xBF; //设置除PA6为输出的其他A端口为输
_papu = 0xBF; //设置除PA6端口其他A端口若上
_pawk = 0x1C; //设置PA.4,3,2为下降沿唤
_adcr = 0x21; //设置PA.0为AD通
_acsr = 0x44; //开启AD模块电源,选择AD时钟源为系统时
_start = 0;
_start = 1;
_start = 0;
_intc0 = 0x07; //定时器,外部中断使能
}
void init_Device(void)
{
S1 = 0;
S2 = 1;
DCUP = 1;
S3 = 1;
P_count0 = 0;
P_count1 = 0;
P_count2 = 0;
Pow_grade = 0;
charge_count1 = 0;
charge_count2 = 0;
halt_count0 = 0;
halt_count1 = 0;
LED_DisplayBuffer = 0;
}
void Updata_Powgrade(void)
{
_adcr = 0x21; //设置PA.0为AD通道
_acsr = 0x44; //开启AD模块电源,选择AD时钟源为系统时钟
_start = 0;
_start = 1;
while(_eocb);
Pow_grade = _adrh / 0x30;
}
void Updata_ledbuff(void)
{
unsigned char i;
for(i = 0; i < Pow_grade; i++)
{
LED_DisplayBuffer |= (1 << i);
}
}
void warn_Display(void)
{
}
void Pow_Display(void)
{
Updata_ledbuff();
_pb |= 0x0F & LED_DisplayBuffer;
}
void charge_Display(void)
{
if(charge_count1 >= (5 - Pow_grade))
{
charge_count1 = 0;
Updata_ledbuff();
}
LED_DisplayBuffer |= (1 <
charge_count1++;
_pb |= 0x0F & LED_DisplayBuffer;
}
void poll_count(void)
{
if(!P_count0)
{
P_count0 = 0x0F51;
P_count1--;
}
if(!P_count1)
{
P_count1 = 0xFF;
P_count2--;
if(S3)
{
Pow_Display(); //显示电量
}
else
{
charge_Display(); //显示充电
}
}
if(!P_count2)
{
P_count2 = 0x12;
Updata_Powgrade();
}
P_count0--;
}
void Core_proc(void)
{
if(ExtPowConnect)
{
if(iPadConnect)
{
S1 = 0; //给电池充电
S2 = 1;
DCUP = 0; //此地是开还是不开?
S3 = 1;
}
else
{
S2 = 1; //连入外部电源
DCUP = 1;
S3 = 1;
S1 = 1;
}
halt_count0 = 0;
halt_count1 = 0;
}
else
{
if(iPadConnect)
{
if(halt_count0 == 0x4C97) {halt_count0 = 0; halt_count1++;}
if(halt_count0 == 250)
{
halt_count0 = 0;
_halt(); //休眠
}
}
else
{
if(1)
{
S1 = 0; //用电池供电
S2 = 1;
DCUP = 1;
S3 = 0;
}
else
{
//显示缺电警告
}
halt_count0 = 0;
halt_count1 = 0;
}
}
}
//-------------------------------------------------------------------------
void main()
{
init_MCU();
init_Device();
do
{
poll_count();
Core_proc();
}
while(1);
}