完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,
端口-c pc6连接到50 Hz方波信号, 问题是变量cCounter没有增加 port_c_isr,所以PC4引脚没有切换,请指教 关于解决方案。 谢谢 ================================================== ====== #include&lt; iostm8s903.h&gt; unsigned char cCounter; void main(void) { CLK_ICKCR = 0x01; //高速内部osc启用 CLK_ECKCR = 0x00; //高速xtal osc禁用 CLK_SWR = 0xE1; //选择高速内部osc作为主时钟 CLK_CKDIVR = 0x10; // master clk divide / 4,cpu clk div / 1 PC_ODR = 0x9E; PC_DDR = 0x9E; PC_CR1 = 0xFF; PC_CR2 = 0x40; // pc6中断使能 EXti_CR1 = 0x20; //只有port-c中断下降沿 //全局中断启用 _asm( '' 轮缘 ''); 而(1) { 而(cCounter&lt; 25); PC_ODR | = 0x10; //设置PC4引脚 cCounter = 0; 而(cCounter&lt; 25); PC_ODR&amp; = ~0x10; //清除PC4引脚 cCounter = 0; } } @far @interrupt void port_c_isr(void) { cCounter ++; } ===================================== stm8_interrupt_vector.c文件内容 ===================================== / *用于STM8设备的基本中断向量表 *版权所有(c)2007 STMicroelectronics * / typedef void @far(* interrupt_handler_t)(void); struct interrupt_vector { unsigned char interrupt_instruction; interrupt_handler_t interrupt_handler; }; @far @interrupt void NonHandledInterrupt(void) { //为了在开发过程中检测意外事件, //建议在以下指令中设置断点 返回; } extern @far @interrupt void port_c_isr(void); extern void _stext(); / *启动例程* / 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,port_c_isr},/ * irq5 port -c exti * / {0x82,NonHandledInterrupt},/ * irq6 * / {0x82,NonHandledInterrupt},/ * irq7 * / {0x82,NonHandledInterrupt},/ * irq8 * / {0x82,NonHandledInterrupt},/ * irq9 * / {0x82,NonHandledInterrupt},/ * irq10 * / {0x82,NonHandledInterrupt},/ * irq11 * / {0x82,NonHandledInterrupt},/ * irq12 * / {0x82,NonHandledInterrupt},/ * irq13 * / {0x82,NonHandledInterrupt},/ * irq14 * / {0x82,NonHandledInterrupt},/ * irq15 * / {0x82,NonHandledInterrupt},/ * irq16 * / {0x82,NonHandledInterrupt},/ * irq17 * / {0x82,NonHandledInterrupt},/ * irq18 * / {0x82,NonHandledInterrupt},/ * 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 * / }; 以上来自于谷歌翻译 以下为原文 Hi, Port-c pc6 is connected to a 50 Hz square wave signal, the problem is the variable cCounter did not increment in the port_c_isr, so the PC4 pin did not toggle, please advise about the solution. Thanks ======================================================== #include unsigned char cCounter; void main(void) { CLK_ICKCR = 0x01; // high speed internal osc enable CLK_ECKCR = 0x00; // high speed xtal osc disable CLK_SWR = 0xE1; // select high speed internal osc as master clock CLK_CKDIVR = 0x10; // master clk divide / 4, cpu clk div / 1 PC_ODR = 0x9E; PC_DDR = 0x9E; PC_CR1 = 0xFF; PC_CR2 = 0x40; // pc6 interrupt enable EXTI_CR1 = 0x20; // port-c interrupt falling edge only // global interrupt enable _asm(''rim''); while (1) { while (cCounter < 25); PC_ODR |= 0x10; // set PC4 pin cCounter = 0; while (cCounter < 25); PC_ODR &= ~0x10; // clear PC4 pin cCounter = 0; } } @far @interrupt void port_c_isr(void) { cCounter++; } ===================================== stm8_interrupt_vector.c file contents ===================================== /* BASIC INTERRUPT VECTOR TABLE FOR STM8 devices * Copyright (c) 2007 STMicroelectronics */ typedef void @far (*interrupt_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; } extern @far @interrupt void port_c_isr(void); extern void _stext(); /* startup routine */ 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, port_c_isr}, /* irq5 port-c exti */ {0x82, NonHandledInterrupt}, /* irq6 */ {0x82, NonHandledInterrupt}, /* irq7 */ {0x82, NonHandledInterrupt}, /* irq8 */ {0x82, NonHandledInterrupt}, /* irq9 */ {0x82, NonHandledInterrupt}, /* irq10 */ {0x82, NonHandledInterrupt}, /* irq11 */ {0x82, NonHandledInterrupt}, /* irq12 */ {0x82, NonHandledInterrupt}, /* irq13 */ {0x82, NonHandledInterrupt}, /* irq14 */ {0x82, NonHandledInterrupt}, /* irq15 */ {0x82, NonHandledInterrupt}, /* irq16 */ {0x82, NonHandledInterrupt}, /* irq17 */ {0x82, NonHandledInterrupt}, /* irq18 */ {0x82, NonHandledInterrupt}, /* 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 */ }; |
|
相关推荐
2个回答
|
|
假设实际生成并处理了中断,问题可能来自于您的变量未声明为volatile。
以上来自于谷歌翻译 以下为原文 assuming that the interrupt is actually generated and serviced, the problem might come from the fact that your variable is not declared as volatile. |
|
|
|
谢谢luca,使用volatile功能解决了这个问题。
我有另一个问题,如何检查和清除外部中断状态 如果我不想使用gpio外部中断? 问候 以上来自于谷歌翻译 以下为原文 Thanks luca the problem is solved by using the volatile feature. I have another question, how to check and clear the external interrupt status if i do not want to use the gpio external interrupts? Regards |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2608 浏览 1 评论
3201 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1775 浏览 1 评论
3600 浏览 6 评论
5979 浏览 21 评论
930浏览 4评论
1306浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
574浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1293浏览 3评论
1349浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-18 03:14 , Processed in 1.031713 second(s), Total 82, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号