版权声明:转载请关注我的公众号-青儿创客基地 https://blog.csdn.net/Zhu_Zhu_2009/article/details/81916039
S3F94C4/S3F94C8单片机手册CSDN上就有,非常古老的单片机,开发环境采用IAR,支持C语言,这个还不错,如果只能汇编,那可以跳楼了。测频率,由于单片机无脉冲捕获功能,也就是8051的time2,必须自己检测io口翻转,首先写一个程序看看io的翻转速度,
#define FIRE_J7 P22//J10
while (1)
{
FIRE_J7 = !FIRE_J7;
}
速度只有5KHz,单片机主频8MHz,IAR设置output生成汇编,
??main_0:
LD R13,0xE2
AND R13,#251
LD R15,0xE2
LD R14,#2
CALL ?UC_SHR_L01
COM R15
LD R14,#2
CALL ?C_SHL_L01
AND R15,#4
OR R15,R13
LD 0xE2,R15
JR ??main_0
这是一个bug啊,c编译器太弱了,这个单片机估计也不是1T的单片机,应该是12T的,参考这里写链接内容,修改一下,
while (1)
{
if (temp)
{
P2 |= 0x04;
}
else
{
P2 &= (~0x04);
}
temp = 1- temp;
//FIRE_J7 = !FIRE_J7;
}
现在的反汇编,
??main_0:
OR 0xE2,#4
LD R15,#1
SUB R15,R9
LD R9,R15
JR NZ,??main_0
io的速度达到64kHz,满足要求,我们只需要测25kHz的波形。看下c编译器的配置项,参考Optimizing Code with GCC
在实际应用中,单片机不仅要处理一个任务,所以需要划片时间段,测频的时候其他逻辑全优化掉,中断函数尽可能精简,
#pragma vector=0x00
__interrupt void intr_94c4(void)
{
unsigned char intrValue;
intrValue = T0CON;
//TMR0-10MS
if (intrValue & 0x1/*T0CON_bit.PND*/)
{
intrValue &= (~0x9);
T0CON = intrValue | 0x8;
//T0CON_bit.PND = 0;
//T0CON_bit.CLR = 1;
cnt50ms++;
}
}
void main(void)
{
unsigned char freqTick = 0;
di;
sysInit();
timerInit();
tm1620bInit();
tiaoGongPWMInit();
ADCInit();
ei;
while (1)
{
BTCON = 0x02;
if (FLAG_50MS)
{
getADC();
keyProc();
checkADCProc();
//freqCalc();
//gongZuoPLJ5 = gongZuoPLJ5Cnt / 50;
if (gongZuoPLJ5 > 25)
{
workState = WS_E7;
}
gongZuoPLJ5 = 0;
gongZuoPLJ5Cnt = 0;
workProc();
dispProc();
ledProc();
fanBeepCtrl();
tm1620bRefresh();
cnt50ms = 0;
FLAG_50MS = 0;
FLAG_200MS = 0;
FLAG_1S = 0;
}
else
{
//FIRE_J7 = !FIRE_J7;
if (freqTick)
{
P2 |= 0x04;
}
else
{
P2 &= (~0x04);
}
freqTick = 1- freqTick;
//freqCalc();
GONGZUO_PL_J5_LAST = GONGZUO_PL_J5_CUR;
GONGZUO_PL_J5_CUR = P2 & 0x1;//GONGZUO_PL_J5;
if (GONGZUO_PL_J5_CUR != GONGZUO_PL_J5_LAST && GONGZUO_PL_J5_CUR)
{
gongZuoPLJ5Cnt++;
if (gongZuoPLJ5Cnt == 50)
{
gongZuoPLJ5Cnt = 0;
gongZuoPLJ5++;
}
}
}
if (cnt50ms >= 10)
{
cnt50ms = 0;
FLAG_50MS = 1;
cnt200ms++;
if (cnt200ms >= 4)
{
cnt200ms = 0;
FLAG_200MS = 1;
cnt1s++;
if (cnt1s >= 5)
{
cnt1s = 0;
FLAG_1S = 1;
}
}
}
}
}
太老的单片机,网上的资料已经很难搜索到了,被淹没在历史洪流中,知识的获取靠积累,也需要科学的学习方法,遇事不能放弃,方可走出迷宫,收获宝藏。