如何让stm8s003f3在timer1上做38khz频率?
我想做一些 rc5 发射器项目。
我已经有一个带有stm8s003的电路来发送数据和ne555来产生38khz频率。将它们连接在一起并发送特定数据后,我的 rc5 发射器工作正常,但没有任何相关消息。
但我想删除 ne555 并仅使用 stm8s003 来完成这两项工作。
我只需要一个代码让TIMER_1发送38khz频率。
这里有一个示例代码,但我不知道。
void TIM1_setup(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(16, TIM1_COUNTERMODE_UP, 1000, 1);
TIM1_OC1Init(TIM1_OCMODE_PWM1,
TIM1_OUTPUTSTATE_ENABLE,
TIM1_OUTPUTNSTATE_ENABLE,
1000,
TIM1_OCPOLARITY_LOW,
TIM1_OCNPOLARITY_LOW,
TIM1_OCIDLESTATE_RESET,
TIM1_OCNIDLESTATE_RESET);
TIM1_CtrlPWMOutputs(ENABLE);
TIM1_Cmd(ENABLE);
}
void main(void)
{
int j;
signed int i = 0;
clock_setup();
GPIO_setup();
TIM1_setup();
while(TRUE)
{
for(i = 0; i < 1000; i += 1)
{
TIM1_SetCompare1(i);
for(j=1;j<0x5FFF;j++);
}
for(i = 1000; i > 0; i -= 1)
{
TIM1_SetCompare1(i);
for(j=1;j<0x5FFF;j++);
}
};
}
这段代码似乎可以使 LED 顺利改变亮度
i want to do some rc5 transmitter project.
i already have a circuit with a stm8s003 to send data and a ne555 to make 38khz frequency. with connect them together and send the specific data my rc5 transmitter works fine and its no word about it.
but i want to remove the ne555 and do both work with only use stm8s003.
i only need a code to make TIMER_1 send 38khz frequency.
here a example code but i have no idea about it.
void TIM1_setup(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(16, TIM1_COUNTERMODE_UP, 1000, 1);
TIM1_OC1Init(TIM1_OCMODE_PWM1,
TIM1_OUTPUTSTATE_ENABLE,
TIM1_OUTPUTNSTATE_ENABLE,
1000,
TIM1_OCPOLARITY_LOW,
TIM1_OCNPOLARITY_LOW,
TIM1_OCIDLESTATE_RESET,
TIM1_OCNIDLESTATE_RESET);
TIM1_CtrlPWMOutputs(ENABLE);
TIM1_Cmd(ENABLE);
}
void main(void)
{
int j;
signed int i = 0;
clock_setup();
GPIO_setup();
TIM1_setup();
while(TRUE)
{
for(i = 0; i < 1000; i += 1)
{
TIM1_SetCompare1(i);
for(j=1;j<0x5FFF;j++);
}
for(i = 1000; i > 0; i -= 1)
{
TIM1_SetCompare1(i);
for(j=1;j<0x5FFF;j++);
}
};
}
it seems to this code make a led change brightness smoothly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 TIM1_TimeBaseInit 将预分频值和周期减 1。使用 TIM1_OC1Init 将重复计数设置为 0,将占空比设置为 50%。这是我在 STM8AF/24MHz 中的 1kHz PWM 示例。
Subtract 1 from the prescale and the period with TIM1_TimeBaseInit. Set the repetition count to 0 and the duty cycle to 50% with TIM1_OC1Init. Here is my 1kHz PWM example in STM8AF/24MHz.