专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
STM32
经不住诱惑,今天开始玩STM8!麻烦过来人进来讲讲心得
2019-12-26 18:53
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
STM32/STM8
19512
77
77
1、买的STM8 value line discovery板刚到手,从最简单的STM8S003开始吧。
2、下载了STVD/COSMIC。COSMIC_32K坛里有和谐好的,不过要先下载原版安装。
3、争取今晚把LED点亮。
4、其实我很看好STM8L152,之后要测试一下耗电和ADC性能。
5、纯业余玩的,还没想好弄点啥……
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
77条回答
millwood0
2019-12-30 16:51
interrupt is easy.
for example, here is a timer interrupt:
//tim2.h
//tim definitions
//good for tim2/3/5
//tim prescaler definitions
#define TIM_PS_1x 0x00 //prescaler = 1:1
#define TIM_PS_2x 0x01 //prescaler = 1:2
#define TIM_PS_4x 0x02 //prescaler = 1:4
#define TIM_PS_8x 0x03 //prescaler = 1:8
#define TIM_PS_16x 0x04 //prescaler = 1:16
#define TIM_PS_32x 0x05 //prescaler = 1:32
#define TIM_PS_64x 0x06 //prescaler = 1:64
#define TIM_PS_128x 0x07 //prescaler = 1:128
#define TIM_PS_256x 0x08 //prescaler = 1:256
#define TIM_PS_512x 0x09 //prescaler = 1:512
#define TIM_PS_1024x 0x0a //prescaler = 1:1024
#define TIM_PS_2048x 0x0b //prescaler = 1:2048
#define TIM_PS_4096x 0x0c //prescaler = 1:4096
#define TIM_PS_8192x 0x0d //prescaler = 1:8192
#define TIM_PS_16384x 0x0e //prescaler = 1:16384
#define TIM_PS_32768x 0x0f //prescaler = 1:32768
//tim2 handler
//executed by tim2_ovr_isr
//to be defined by usr
void tim2_init(unsigned char tm_prescaler, unsigned short period);
void tim2_act(void (*func_ptr)(void));
复制代码
tim2.c
#include <iostm8.h>
#include "tim2.h"
//user code needs to assigned _tmr0_func to a subroutine or the mcu will reboot when the isr trips
void (*_tim2_func) (void); //tim2_function ptr
//tim3_ovr_handler to be set by users
//tim3 isr handler
#pragma vector = TIM2_OVR_UIF_vector //tim3 overflow interrupt
__interrupt void tim2_ovr_isr(void) {
TIM2_SR1_UIF=0; //clear the flag
//tim2_handler(); //execute tim3 handler
_tim2_func(); //execute function
}
void tim2_init(unsigned char tm_prescaler, unsigned short period) {
TIM2_CR1_CEN = 0; //turn off the timer
TIM2_CNTRL = 0; //preload the counter's low byte
TIM2_PSCR = tm_prescaler; /* Configure TIM2 prescaler */
TIM2_ARRH = period >> 8; /* Configure TIM3 auto reload -> period. ms byte first*/
TIM2_ARRL = period & 0x00ff; /* Configure TIM3 auto reload -> period. */
TIM2_CNTRH = 0; //preload the counter high byte
TIM2_CR1_ARPE = 1; //turn on auto reload
TIM2_CR1_CEN = 1; //turn on the timer
TIM2_IER_UIE = 1; //enable the tim3 updateinterrupt
}
void tim2_act(void (*func_ptr)(void)) {
_tim2_func=func_ptr;
}
复制代码
tim2_init() sets the prescaler and desired delay for each interrupt. tim2_act() installs a user handler.
加载中...
查看其它77个回答
一周热门
更多
>
相关问题
STM32F4上I2C(在PROTEUS中模拟)调试不通的问题
6 个回答
芯片供应紧张,准备换个MCU,MM32L系列替换STM32L系列的怎么样?
7 个回答
STM32同时使用两个串口进行数据收发时数据丢包的问题
5 个回答
STM32F103串口通信死机问题
4 个回答
STM32WLE5CC连接SX1268在LoRa模式下能与 SX1278互通吗?
2 个回答
相关文章
ST公司第一款无线低功耗单片机模块有效提高物联网设计生产效率
0个评论
如何实现对单片机寄存器的访问
0个评论
通过USB用STM32片内自带Bootloader下载程序及注意事项
0个评论
欲练此功必先自宫之STM32汇编启动,放慢是为了更好的前行
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
STM32
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
for example, here is a timer interrupt:
//tim2.h
- //tim definitions
- //good for tim2/3/5
- //tim prescaler definitions
- #define TIM_PS_1x 0x00 //prescaler = 1:1
- #define TIM_PS_2x 0x01 //prescaler = 1:2
- #define TIM_PS_4x 0x02 //prescaler = 1:4
- #define TIM_PS_8x 0x03 //prescaler = 1:8
- #define TIM_PS_16x 0x04 //prescaler = 1:16
- #define TIM_PS_32x 0x05 //prescaler = 1:32
- #define TIM_PS_64x 0x06 //prescaler = 1:64
- #define TIM_PS_128x 0x07 //prescaler = 1:128
- #define TIM_PS_256x 0x08 //prescaler = 1:256
- #define TIM_PS_512x 0x09 //prescaler = 1:512
- #define TIM_PS_1024x 0x0a //prescaler = 1:1024
- #define TIM_PS_2048x 0x0b //prescaler = 1:2048
- #define TIM_PS_4096x 0x0c //prescaler = 1:4096
- #define TIM_PS_8192x 0x0d //prescaler = 1:8192
- #define TIM_PS_16384x 0x0e //prescaler = 1:16384
- #define TIM_PS_32768x 0x0f //prescaler = 1:32768
- //tim2 handler
- //executed by tim2_ovr_isr
- //to be defined by usr
- void tim2_init(unsigned char tm_prescaler, unsigned short period);
- void tim2_act(void (*func_ptr)(void));
复制代码tim2.c
- #include <iostm8.h>
- #include "tim2.h"
- //user code needs to assigned _tmr0_func to a subroutine or the mcu will reboot when the isr trips
- void (*_tim2_func) (void); //tim2_function ptr
- //tim3_ovr_handler to be set by users
- //tim3 isr handler
- #pragma vector = TIM2_OVR_UIF_vector //tim3 overflow interrupt
- __interrupt void tim2_ovr_isr(void) {
- TIM2_SR1_UIF=0; //clear the flag
- //tim2_handler(); //execute tim3 handler
- _tim2_func(); //execute function
- }
- void tim2_init(unsigned char tm_prescaler, unsigned short period) {
- TIM2_CR1_CEN = 0; //turn off the timer
- TIM2_CNTRL = 0; //preload the counter's low byte
- TIM2_PSCR = tm_prescaler; /* Configure TIM2 prescaler */
- TIM2_ARRH = period >> 8; /* Configure TIM3 auto reload -> period. ms byte first*/
- TIM2_ARRL = period & 0x00ff; /* Configure TIM3 auto reload -> period. */
- TIM2_CNTRH = 0; //preload the counter high byte
- TIM2_CR1_ARPE = 1; //turn on auto reload
- TIM2_CR1_CEN = 1; //turn on the timer
- TIM2_IER_UIE = 1; //enable the tim3 updateinterrupt
- }
- void tim2_act(void (*func_ptr)(void)) {
- _tim2_func=func_ptr;
- }
复制代码tim2_init() sets the prescaler and desired delay for each interrupt. tim2_act() installs a user handler.一周热门 更多>