新手上路
- 积分
- 28
- 金钱
- 28
- 注册时间
- 2016-12-12
- 在线时间
- 3 小时
|
4金钱
我向端口D的第4引脚发送频率为125K的PWM,通过触发第4引脚的外部中断,然后用一个数组记录触发后的电平和间隔时间,接收到的电平应该是0101010101...没想到接收到的电平是011011011011....
这是接收PWM的代码
============================
#include <STM8L152C6.h>
_Bool brkPin @PD_IDR:4;
unsigned char jumpSeq;
unsigned char brkEdge[32];
unsigned int imcstData[32];
void initTIM2(void)
{
CLK_PCKENR1 |= 0x01;
TIM2_CR1 = 0x00;
TIM2_PSCR = 0x00;
TIM2_ARRH = 0xff;
TIM2_ARRL = 0xff;
TIM2_IER |= 0x01;
}
main()
{
//系统时钟二分频
CLK_CKDIVR = 0x01;
//位4设置双沿中断
EXTI_CR2 = 0x03;
//PD4配置为中断
PD_DDR &= 0xef;
PD_CR1 &= 0xef;
PD_CR2 |= 0x10;
jumpSeq = 0;
initTIM2();
_asm("rim");
while (1);
}
@far @interrupt void brkRec(void)
{
unsigned char recbit;
recbit = brkPin;
//清除标志位
EXTI_SR1 = 0xff;
EXTI_SR2 = 0xff;
TIM2_CR1 = 0x00;
imcstData[jumpSeq] = TIM2_CNTRH;
imcstData[jumpSeq]= (imcstData[jumpSeq]<<8) + TIM2_CNTRL;
brkEdge[jumpSeq] = recbit;
TIM2_CNTRH = 0x00;
TIM2_CNTRL = 0x00;
jumpSeq++;
if(jumpSeq==32)
jumpSeq = 0;
TIM2_CR1 = 0x01;
}
@far @interrupt void TIM2Over(void)
{
TIM2_SR1 = 0x00;
TIM2_CR1 = 0x00;
TIM2_CNTRH = 0x00;
TIM2_CNTRL = 0x00;
jumpSeq = 0;
}
这个问题困扰好久了,有没有人来拯救我???
刚开始学,我使用的是STM8L152C6,金钱不多,还请多多帮忙啊!!!
|
|