本帖最后由 zhiyonghe 于 2010-4-21 15:54 编辑
闲来无事做个程序玩玩,没想到我被玩了,
思路在TPM这么多通道设置上写个可以通用的调用初始化函数
突然想玩玩在初始化后在主程序里修改初始化,没想到带给我的是单片机下载老是出错,仿真也莫名其妙的老是要重启才能正常跑!
//========TPMoc_init:初始化输出比较系统配置==========
//功 能:
// 设置通道是否产生方波对每个通道0~7设置是否启动方波,设置成功回送
//参 数:
// channel-通道号('0'~'7')字符型变量
// Switch-开关('S'-产生方波,'E'-停止)字符型变量
//返 回:无
//-------------------------------------------------------------
void TPMoc_init(uchar channel, uchar Switch)
{
switch (channel)
{
case '0' :
if(Switch == 'S')
{
TPM1SC = 0X0F; //关中断,总线时钟,128分频(计数到1S时中断)
TPM1C0SC = 0X54; //输出比较,反转电平,中断使能
TPM1C0VH = 0XF4;
TPM1C0VL = 0X24;
}
if(Switch == 'E') //0通道停止
{
TPM1C0SC = 0X00; //恢复通用IO
TPM1C0VH = 0X00; //TPM1C0V清零
TPM1C0VL = 0X00;
}
break;
case '1' :
if(Switch == 'S')
{
TPM1SC = 0X0F;
TPM1C1SC = 0X54;
TPM1C1VH = 0XF4;
TPM1C1VL = 0X24;
}
if(Switch == 'E') //0通道停止
{
TPM1C1SC = 0X00; //恢复通用IO
TPM1C1VH = 0X00;
TPM1C1VL = 0X00;
}
break;
case '2' :
if(Switch == 'S')
{
TPM1SC = 0X0F;
TPM1C2SC = 0X54;
TPM1C2VH = 0XF4;
TPM1C2VL = 0X24;
}
if(Switch == 'E') //0通道停止
{
TPM1C2SC = 0X00; //恢复通用IO
TPM1C2VH = 0X00;
TPM1C2VL = 0X00;
}
break;
……
……
default:
break;
}
if(int_Flag == 0x56)
{
oc_flag = 1;
}
else oc_flag = 0;
// SCISend1(int_Flag); //返回设置标志
} |