STM8L101f3p6定时器2中断测试程序

上传人:飞*** 文档编号:4680876 上传时间:2017-08-22 格式:DOC 页数:3 大小:28KB
返回 下载 相关 举报
STM8L101f3p6定时器2中断测试程序_第1页
第1页 / 共3页
STM8L101f3p6定时器2中断测试程序_第2页
第2页 / 共3页
STM8L101f3p6定时器2中断测试程序_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《STM8L101f3p6定时器2中断测试程序》由会员分享,可在线阅读,更多相关《STM8L101f3p6定时器2中断测试程序(3页珍藏版)》请在金锄头文库上搜索。

1、本程序分两个 C 文件:main.c 和 stm8_interrupt_vector.cMain.c 文件内容#include STM8L101F3P.h #include STM8l10x.h #include stm8l10x_tim2.h/*LED 灯系列开关*/_Bool LED02 PD_ODR:0;_Bool LED01 PC_ODR:2;#define L 0#define H 1#define Library_function/*延迟函数*/void Delay(unsigned int nCount)/* Decrement nCount value */while (nCo

2、unt != 0)nCount-;/*主函数*/void main(void) _asm(sim);CLK_CKDIVR = 0x00;CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);/ 必须有PC_DDR = 0x04; /配置 LED 输出PC_CR1 = 0x04;PD_DDR = 0x01;PD_CR1 = 0x01;LED01=1;LED02=1;#ifdef Library_functionTIM2_DeInit();TIM2_TimeBaseInit(TIM2_Prescaler_16,TIM2_CounterMode

3、_Up, 1000);/定时 1sTIM2_Cmd(ENABLE);TIM2_ITConfig(TIM2_IT_Update, ENABLE);TIM2_ARRPreloadConfig(ENABLE);#elseTIM2_ARRH = 10008;/定时 1ms TIM2_ARR 高位TIM2_ARRL = 1000; TIM2-IER = 0x01; /使能溢出中断TIM2-PSCR= 0x04; /16 分频TIM2-CR1 = 0x01; /enable Timer2#endif_asm(rim);while (1)LED01=1;Delay(0xffff);LED01=0;Delay

4、(0xffff);far interrupt void TIM2_interrupt(void) static char i=0;static unsigned int TIM_Work;if(TIM_Work+1000)TIM_Work=0;i=1-i;LED02=i;TIM2_SR1 = 0x00;return;stm8_interrupt_vector.c 内容/* BASIC INTERRUPT VECTOR TABLE FOR STM8 devices* Copyright (c) 2007 STMicroelectronics*/typedef void far (*interru

5、pt_handler_t)(void);struct interrupt_vector unsigned char interrupt_instruction;interrupt_handler_t interrupt_handler;far interrupt void NonHandledInterrupt(void)/* in order to detect unexpected events during development, it is recommended to set a breakpoint on the following instruction*/return;ext

6、ern void _stext(); /* startup routine */extern far interrupt void TIM2_interrupt(void);struct interrupt_vector const _vectab = 0x82, (interrupt_handler_t)_stext, /* reset */0x82, NonHandledInterrupt, /* trap */0x82, NonHandledInterrupt, /* irq0 */0x82, NonHandledInterrupt, /* irq1 */0x82, NonHandled

7、Interrupt, /* irq2 */0x82, NonHandledInterrupt, /* irq3 */0x82, NonHandledInterrupt, /* irq4 */0x82, NonHandledInterrupt, /* irq5 */0x82, NonHandledInterrupt, /* irq6 */0x82, NonHandledInterrupt, /* irq7 */0x82, NonHandledInterrupt, /* irq8 */0x82, NonHandledInterrupt, /* irq9 */0x82, NonHandledInte

8、rrupt, /* irq10 */0x82, NonHandledInterrupt, /* irq11 */0x82, NonHandledInterrupt, /* irq12 */0x82, NonHandledInterrupt, /* irq13 */0x82, NonHandledInterrupt, /* irq14 */0x82, NonHandledInterrupt, /* irq15 */0x82, NonHandledInterrupt, /* irq16 */0x82, NonHandledInterrupt, /* irq17 */0x82, NonHandled

9、Interrupt, /* irq18 */0x82, TIM2_interrupt, /* irq19 */0x82, NonHandledInterrupt, /* irq20 */0x82, NonHandledInterrupt, /* irq21 */0x82, NonHandledInterrupt, /* irq22 */0x82, NonHandledInterrupt, /* irq23 */0x82, NonHandledInterrupt, /* irq24 */0x82, NonHandledInterrupt, /* irq25 */0x82, NonHandledInterrupt, /* irq26 */0x82, NonHandledInterrupt, /* irq27 */0x82, NonHandledInterrupt, /* irq28 */0x82, NonHandledInterrupt, /* irq29 */;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号