完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我试图运行一个代码,其中定时器导致中断,每次产生中断,变量h递增,但它在快速监视窗口中保持为零。我的代码在下面用stvd和cosmic编译器编写。
#include'stm8s.h' #include'stm8s_tim1.h' #include'stm8s_itc.h'#define TIM1_PSCRH(*(volatile uint8_t *)0x5260) #define TIM1_CR1(*(volatile uint8_t *)0x5250) #define TIM1_ARRH(*(volatile uint8_t *)0x5263) #define TIM1_ARRL(*(volatile uint8_t *)0x5264) #define TIM1_PSCRL(*(volatile uint8_t *)0x5261) #define TIM1_IER(*(volatile uint8_t *)0x5254)int h; void main(void) { // TIM1_SetCounter(5); enableInterrupts(); GPIO_Config(); // TIM1_DeInit(); TIM1_ARRH = 0x55的; TIM1_ARRL = 0X26; TIM1_PSCRH = 0x3e; TIM1_PSCRL = 0x80; TIM1_CR1 = 0×81; TIM1_IER = 0X01; enableInterrupts(); 而(1) { } INTERRUPT_HANDLER(TIM1_UPD_OVF_IRQHANDLER,23) // @ interrupt @far void TIM1_OVF_TRG_BRK_IRQ_Handler(void) { ħ++; } #ifdef USE_FULL_ASSERT / ** * @brief报告源文件的名称和源行号 *发生assert_param错误的地方。 * @param文件:指向源文件名的指针 * @param line:assert_param错误行源编号 * @retval没有 * / void assert_failed(uint8_t * file,uint32_t行) { / *用户可以添加自己的实现来报告文件名和行号, 例如:printf('错误的参数值:文件%s在行%d r n',文件,行)* / / *无限循环* / 而(1) { } } #endif代码出了什么问题?请帮助我。 谢谢。 以上来自于谷歌翻译 以下为原文 I am trying to run a code in which timer causes an interrupt and everytime interrupt is generated, a variable h is incremented, but it remains zero in quickwatch window. My code is written below in stvd and cosmic compiler. #include 'stm8s.h' #include 'stm8s_tim1.h' #include 'stm8s_itc.h'#define TIM1_PSCRH (*(volatile uint8_t *)0x5260) #define TIM1_CR1 (*(volatile uint8_t *)0x5250) #define TIM1_ARRH (*(volatile uint8_t *)0x5263) #define TIM1_ARRL (*(volatile uint8_t *)0x5264) #define TIM1_PSCRL (*(volatile uint8_t *)0x5261) #define TIM1_IER (*(volatile uint8_t *)0x5254)int h; void main(void) { //TIM1_SetCounter(5);enableInterrupts();GPIO_Config(); //TIM1_DeInit();TIM1_ARRH=0X55; TIM1_ARRL=0X26; TIM1_PSCRH = 0x3e; TIM1_PSCRL = 0x80; TIM1_CR1=0X81; TIM1_IER=0X01; enableInterrupts(); while(1) { } }INTERRUPT_HANDLER (TIM1_UPD_OVF_IRQHANDLER,23) //@interrupt @far void TIM1_OVF_TRG_BRK_IRQ_Handler(void) { h++; } #ifdef USE_FULL_ASSERT/** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf('Wrong parameters value: file %s on line %drn', file, line) */ /* Infinite loop */ while (1) { } } #endifWhat is wrong with the code? Kindly help me. Thank you. |
|
相关推荐
11个回答
|
|
嗨,
尝试使用:volatile int h; 问候 安德烈亚斯 以上来自于谷歌翻译 以下为原文 Hi, try to use : volatile int h; Regards Andreas |
|
|
|
你在使用调试器吗?
代码是否启用定时器内部时钟,以便您可以实际写入定时器寄存器? 在旧代码中,我有这个: CLK_PeripheralClockConfig(CLK_Peripheral_TIM1,ENABLE); 作为第一步......(STM8L151) ============================== 挖掘std lib: void CLK_PeripheralClockConfig(CLK_Peripheral_TypeDef CLK_Peripheral,FunctionalState NewState) { / *检查参数* / assert_param(IS_CLK_PERIPHERAL(CLK_Peripheral)); assert_param(IS_FUNCTIONAL_STATE(NewState)); if(((uint8_t)CLK_Peripheral&amp;(uint8_t)0x10)== 0x00) { if(NewState!= DISABLE) { / *启用外设时钟* / CLK-> PCKENR1 | =(uint8_t)((uint8_t)1&lt;((uint8_t)CLK_Peripheral&amp;(uint8_t)0x0F)); } 其他 { / *禁用外设时钟* / CLK-> PCKENR1&amp; =(uint8_t)(〜(uint8_t)(((uint8_t)1&lt;((uint8_t)CLK_Peripheral&amp;(uint8_t)0x0F)))); } } 其他 { if(NewState!= DISABLE) { / *启用外设时钟* / CLK-> PCKENR2 | =(uint8_t)((uint8_t)1&lt;((uint8_t)CLK_Peripheral&amp;(uint8_t)0x0F)); } 其他 { / *禁用外设时钟* / CLK-> PCKENR2&amp; =(uint8_t)(〜(uint8_t)(((uint8_t)1&lt;((uint8_t)CLK_Peripheral&amp;(uint8_t)0x0F)))); } } 是的,你需要将变量声明为volatile才能确定。 以上来自于谷歌翻译 以下为原文 Are you using the debugger? Is the code enabling timer internal clock so you can actually write the timer registers? In an old code, I've got this: CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE); Put as first step... (STM8L151) ============================== Digging at the std lib: void CLK_PeripheralClockConfig(CLK_Peripheral_TypeDef CLK_Peripheral, FunctionalState NewState) { /* Check the parameters */ assert_param(IS_CLK_PERIPHERAL(CLK_Peripheral)); assert_param(IS_FUNCTIONAL_STATE(NewState));if (((uint8_t)CLK_Peripheral & (uint8_t)0x10) == 0x00) { if (NewState != DISABLE) { /* Enable the peripheral Clock */ CLK->PCKENR1 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F)); } else { /* Disable the peripheral Clock */ CLK->PCKENR1 &= (uint8_t)(~(uint8_t)(((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F)))); } } else { if (NewState != DISABLE) { /* Enable the peripheral Clock */ CLK->PCKENR2 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F)); } else { /* Disable the peripheral Clock */ CLK->PCKENR2 &= (uint8_t)(~(uint8_t)(((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F)))); } } }and yes, you need to declare the variable as volatile to be sure. |
|
|
|
|
|
|
|
谢谢,但声明变量h为volatile不会发生任何变化。
以上来自于谷歌翻译 以下为原文 Thanks, but declaring variable h as volatile didn't make any change. |
|
|
|
谢谢,我使用stm8s003k3板与调试器,但h的值在模拟器中也被视为0。
以上来自于谷歌翻译 以下为原文 Thanks, I am using stm8s003k3 board with debugger, but the value of h is seen as 0 in simulator also. |
|
|
|
另外,放线
CLK_PeripheralClockConfig(CLK_Peripheral_TIM1,ENABLE); 导致错误'重新声明的外部CLK_PeripheralClockConfig' 以上来自于谷歌翻译 以下为原文 Also, putting line CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE); resulted in error 'redeclared external CLK_PeripheralClockConfig' |
|
|
|
这种类型的错误似乎告诉源代码有一个问题,如缺失/太多)或}
调用函数不应该产生这样的错误。 以上来自于谷歌翻译 以下为原文 This type of error seems to tell the source code has an issue like missing/too many ) or } Calling a function should not yield such error. |
|
|
|
我已经包含了stm8s_itc.h。我已经看到包含stm8s_it.h文件的某个地方,我认为它支持raisonance和cosmic。当我包含该文件时,会发生另一个错误'symbol f_NonHandeledInterrupt multiply defined'
谢谢。 以上来自于谷歌翻译 以下为原文 I have included stm8s_itc.h. I have seen somewhere stm8s_it.h file being included, which I think, is supported for raisonance as well as cosmic. When I include that file, another error takes place 'symbol f_NonHandeledInterrupt multiply defined' Thank you. |
|
|
|
NVIC是STM32器件中的CortexM中断控制器。因此,当您使用STM8时,请忽略我的帖子。
以上来自于谷歌翻译 以下为原文 NVIC is the CortexM interrupt controller in STM32 devices. Therefore ignore my post as you are working with STM8. |
|
|
|
你启用了中断吗?
enableInterrupts(); //通常在主循环之前... 因此你必须包括:stm8l15x.h 以上来自于谷歌翻译 以下为原文 Have you enabled the interrupts? enableInterrupts(); // usally before the main while loop... therefore you have to include: stm8l15x.h |
|
|
|
改成
以上来自于谷歌翻译 以下为原文
Change to
|
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2699 浏览 1 评论
3229 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1801 浏览 1 评论
3639 浏览 6 评论
6019 浏览 21 评论
957浏览 4评论
1327浏览 4评论
1382浏览 3评论
201浏览 3评论
190浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-13 03:41 , Processed in 1.297645 second(s), Total 101, Slave 84 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号