- /************************************************
- **文件名称:stm8s_interrupt_verctor.c
- **说明:以下内容为加入的部分,模板代码部分省略
- *************************************************/
- #include"stm8s105c_s.h"
- // 代码省略
- unsigned int count =0;
- [url=home.php?mod=space&uid=1095855]@far[/url] [url=home.php?mod=space&uid=422518]@interrupt[/url] void TIM2_1US(void)
- {
- count++;
-
- TIM2_SR1 &=~(0x01); // 清除TIM2溢出中断标志位
-
- if(count ==1000) // 1s时间到
- {
- count =0;
- PD_ODR ^=0x0D; // LED翻转
- }
- return;
- }
-
- // TIM2在中断向量表中的定义
- struct interrupt_vector const _vectab[] = {
- {0x82, (interrupt_handler_t)_stext}, /* reset */
- {0x82, NonHandledInterrupt}, /* trap */
- {0x82, NonHandledInterrupt}, /* irq0 */
- {0x82, NonHandledInterrupt}, /* irq1 */
- {0x82, NonHandledInterrupt}, /* irq2 */
- {0x82, NonHandledInterrupt}, /* irq3 */
- {0x82, NonHandledInterrupt}, /* irq4 */
- {0x82, NonHandledInterrupt}, /* irq5 */
- {0x82, NonHandledInterrupt}, /* irq6 */
- {0x82, NonHandledInterrupt}, /* irq7 */
- {0x82, NonHandledInterrupt}, /* irq8 */
- {0x82, NonHandledInterrupt}, /* irq9 */
- {0x82, NonHandledInterrupt}, /* irq10 */
- {0x82, NonHandledInterrupt}, /* irq11 */
- {0x82, NonHandledInterrupt}, /* irq12 */
- {0x82, TIM2_1US}, /* irq13 */
- {0x82, NonHandledInterrupt}, /* irq14 */
- {0x82, NonHandledInterrupt}, /* irq15 */
- // 以下内容省略
- {0x82, NonHandledInterrupt}, /* irq29 */ // 手册中的32个中断向量,这里才29个,因为用的是STM8S105S4这款片子的原因,可能没那么多吧,cosmic真的很傻很强大。顺便了解了TIM2的中断级别也不错。
- };
|