完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我试图用一个哔哔声倒计时,每秒钟哔哔哔哔声。之前,我的中断功能是在同一个文件中,我拥有我所有其他的哔哔功能。现在,我想控制蜂鸣器和倒计时。因此,我在互联网上看,它看起来好像不能单独中断功能,因为它犯了一个错误,说我在同一个向量上有两个函数。于是我做了一个中断,C和一个中断.h文件。现在,我有一个中断中的蜂鸣器和同一个函数中的倒计时中断。问题是现在我得到了这个错误:我的函数是在一个中断管理器中定义的。H:“虚中断ISR(无效)”,我找了整个周末试图解决它。找不到问题所在,我用的是PIC18F47 K42。这是我的第一张图片。我使用MPLABX的版本5,最新的XC8编译器V2.00。我进入微控制器大约3个月,在我的空闲时间,请不要太苛刻。
以上来自于百度翻译 以下为原文 I'm trying to make a countdown with a beeper that beeps each second. Before, my interrupt function was in the same file in which I had all my other beeper functions. Now, I want to control the beeper AND the countdown. Thus, I looked on the internet and it looks like I cannot make separate interrupt function because it threw an error saying that I had two functions on the same vector. So I made a interrupt.c and a interrupt.h file. Now, I have the beeper in an interrupt and the countdown interrupt in the same function. #include #include "mcc.h" #include "beeper.h" #include "interrupt_manager.h" void interrupt ISR(void) { //BEEPER if (PIR4bits.TMR1IF == 1) { BEEPER1 = 0; // line 17 LED1 = 0; T1CONbits.ON = 0; PIR4bits.TMR1IF = 0; T2PR = 0x72; } //COUNTDOWN if (PIR3bits.TMR0IF == 1) { T0CON0bits.EN = 0; //line 33 PIR3bits.TMR0IF = 0; } } The problem is that now I get this error: interrupt_manager.c:17: error: (255) not a member of the struct/union "" interrupt_manager.c:17: error: (182) illegal conversion between types interrupt_manager.c:33: error: (255) not a member of the struct/union "" interrupt_manager.c:33: error: (182) illegal conversion between types My function is defined in an interrupt_manager.h like this: "void interrupt ISR(void);" I looked for a whole weekend trying to resolve it. Can't find what the problem is. I'm using a PIC18F47k42. This is my first PIC. I'm using version 5.00 of MPLABX with most recent XC8 compiler v2.00. I'm into microcontroller since about 3 months during my free-time, please don't be too harsh. |
|
相关推荐
18个回答
|
|
|
|
|
|
对不起,导数是什么意思?我使用MPLABX的版本4.15和最新的XC8编译器。
以上来自于百度翻译 以下为原文 Sorry what do you mean by derivative? I'm using version 4.15 of MPLABX with most recent XC8 compiler. |
|
|
|
你的“宝贝”有一个中断,它需要在ISR中轮询中断的确切来源。你的源代码没有显示行号,而我目前在一个有限的移动设备上,因此我简单地问:如果不是PrI3的成员,它是否是TMR0(它是大多数P上的ITCCON成员)。IC16S)?同样适用于TMR1IF和PIR4吗?(中断标志到寄存器的分配与分配寄存器到配置寄存器的次数一样频繁。)
以上来自于百度翻译 以下为原文 Your "babe" has got a single interrupt, which requires polling the exact source of the interrupt within the ISR. Your source code shows no line numbers and I'm currently on a somewhat limited mobile device, thus I simply ask:
|
|
|
|
|
|
|
|
我只是仔细检查了一下。他们是会员。事实上,我必须检查,因为我甚至不知道2个月前的寄存器是什么。这是PIC18F47 K42的PDF。在第9.1页的第141页和第142页中,困扰我的是,如果我用PIR3删除第二个函数并把中断放回包含我的寻呼机功能的文件中,蜂鸣器就可以正常工作了。
以上来自于百度翻译 以下为原文 I just double checked. They are members. In fact I had to check, because I didn't even know what registers were 2 months ago. Here is the PDFof the PIC18F47K42. In chapter 9.1 at page p.141 and p.142. What bothers me a alot is that if I remove the second function with PIR3 and put the interrupt back in the file containing my beeper functions, the beeper works just fine. |
|
|
|
尝试用这个替换这个
以上来自于百度翻译 以下为原文 Try replacing this void interrupt ISR(void) with this void __interrupt(irq(TMR0,TMR1),high_priority) ISR(void) |
|
|
|
好的。然后定位PIC18F47 K42的头文件(在XC8安装路径的包含子目录中),搜索TMR0IF和/或PIR3。可能是头文件中有一些类型错误。时常发生。尤其是当一个导数是比较新的。如果有一些错误,我建议纠正头文件(如TMR0IF正好在这个拼写广泛)。
以上来自于百度翻译 以下为原文 OK. Then locate the header file for your pic18f47k42 (in the include subdirectory of the XC8 installation path) and search for TMR0IF and/or PIR3. Might be there is some typo in the header file. Happens from time to time. Especially when a derivative is comparably new. If there is some typo, I suggest to correct the header file (as TMR0IF in exactly this spelling is widespread). |
|
|
|
…或者这个
以上来自于百度翻译 以下为原文 ... or maybe this void __interrupt(irq(TMR1),high_priority) Timer1Int(void) { BEEPER1 = 0; // line 17 LED1 = 0; T1CONbits.ON = 0; PIR4bits.TMR1IF = 0; T2PR = 0x72; } void __interrupt(irq(TMR0),high_priority) Timer0Int(void) { T0CON0bits.EN = 0; //line 33 PIR3bits.TMR0IF = 0; } |
|
|
|
中断(4):警告:(1316)属性/说明符“y-中断”忽略中断TytMault.C:13:错误:(984)类型RealDeCurdieDebug ToMult.C:13:错误:(1098)变量“ISR”冲突声明(StuttTyMalk.C:12),这是当我在“.h”中替换声明时所得到的用你的代码。当我使用你的第二个代码时,它只给了我最初的错误。谢谢。
以上来自于百度翻译 以下为原文 interrupt_manager.h:4: warning: (1316) attribute/specifier "__interrupt" ignored interrupt_manager.c:13: error: (984) type redeclared interrupt_manager.c:13: error: (1098) conflicting declarations for variable "ISR" (interrupt_manager.c:12) These are what I get when I replace my declaration in my ".h" by your code. When I use your second code, it just gives me the initial errors. Thanks though. |
|
|
|
最新的XC8需要MPLABX V4.20,所以更新MPLABX并再次检查。
以上来自于百度翻译 以下为原文 The latest XC8 requires MPLABX v4.20, so update your MPLABX and check again. |
|
|
|
HIA快速查看PIC18F47 K42的数据表,它显示了一个与我们以前使用的8位PICS家族有很大差异的图片。确实,TMR0IF迁移到PiR3和TMR1IF(TMR2IF)到PiR4。
以上来自于百度翻译 以下为原文 Hi A quick look at the datasheet for the PIC18F47K42 shows an arquitecture for this PIC quite different from what we are used from previous families of 8 bit PICs. Indeed the TMR0IF as migrated to PIR3 and TMR1IF (also TMR2IF) to PIR4. |
|
|
|
即使有了新的MPLABX和编译器,没有变化,我仍然会得到同样的错误。这里是一个项目文件的链接,以防你想尝试一下。
以上来自于百度翻译 以下为原文 Even with new MplabX and Compiler, No change, I still get the same errors. Here is a link to the project file, in case you want to try it out. |
|
|
|
如果我改变我的中断功能的位置,我把它放在我的蜂鸣器。C,一切都很好。
以上来自于百度翻译 以下为原文 If I change the location of my interrupt function and I put it in my beeper.c, everything works fine.... |
|
|
|
HiThen,您的页眉(.h)文件有问题。需要向其他模块(.c)发布的内容不是。
以上来自于百度翻译 以下为原文 Hi Then you have a problem with your header (.h) files. Something that needs to be published to other modules (.c) and is not. |
|
|
|
您好,我不确定您是否禁用和重新启用中断,但为了安全起见,您应该为Iutut例程中的每个中断标志测试做以下操作:如果您的中断总是启用,那么您可以跳过这个:问候。
以上来自于百度翻译 以下为原文 Hi, I'm not sure if you disable and re-enable interrupts but to be on the safe side you should do the following for each interrupt flag test you have in the interupt routine : If your interrupt are ALWAYS enabled then you may skip this : if ( (PIR4bits.TMR1IF == 1) && (PIE4bits.TMR1IE == 1) ) ... if (PIR3bits.TMR0IF == 1) && (PIE3bits.TMR0IE == 1) ) .... Regards |
|
|
|
无需检查IE中的IE或IE的OP的PIC设备是否具有中断向量表。
以上来自于百度翻译 以下为原文 No need to check IF or IE in the ISR's. OP's PIC device has interrupt vector table. |
|
|
|
这真是件好事。不理解为什么某些东西(神奇地或看起来如此)被固定了,几乎肯定会在代码被添加或修改时导致后来的问题。或者,当你继续进行其他项目时,也许我能消除一些困扰你的疑虑,即使是在一些更有经验的助手中,关于编译器头文件和其他编译器“问题”,这些代码确实是你的代码中的问题。代码:问题不在于你给我们展示了什么,而是在于你没有给我们展示什么。当我们呈现整个EngILADA时,我们可以看到它不是编译器或IDE配置“问题”。您的代码(在稍后的帖子中给了它一个链接)还包括“LCD.H”和LCD。H在BePr.h中有这个。是向编译器提交的行,这就是编译器抱怨的原因。(这就是为什么当您将中断函数移到另一个不包括LCD.H的文件时,它不会产生错误消息)也许您现在可以看到为什么下面的行也会触发编译器错误消息:注意宏。在程序中使用更可能是单色的东西,而不是在LCD中定义EN。H,也许是定义LCDGEN和使用LCDGEN,无论你想操纵LCD使能信号。还有一个重要的编程注意:输出信号应该总是使用LAT位,而不是端口位,所以FO。LLWIN将是合适的:在论坛上搜索RMW或阅读修改,在网站上的其他地方搜索解释。这个(读修改写现象)在800页数据表的第16部分中提到,但是它的重要性没有被强调。这是非常,非常(非常)重要的。所以,同样地,在您的LCDGPORT()函数中,使用LAT位,而不是端口位:底线:即使您的代码似乎正在工作(或者在几乎工作和几乎不工作之间波动),使用LAT位来输出会节省大量的头痛,并且很难调试。最后的注意事项:当你获得K42的经验时,你会发现矢量中断,如在第9页中的1and 0所建议的那样,可以使代码更加高效和可维护。这是8位PICS体系结构的一大进步,也是K42系列的一个突出特点。但这里的事情是:为了使用矢量化中断函数,必须改变MVECCENPREMA:问候,戴夫。
以上来自于百度翻译 以下为原文 It is a really Good Thing to be bothered about. Not understanding why something got (magically, or so it seems) fixed will almost certainly result in later problems as code is added or modified. Or as you go on to other projects. Maybe I can clear up a couple of nagging doubts, even among some more experienced helpers, concerning the compiler header file and other compiler "issues" that are really problems with your code. From your original post: Here's why it is important to give all of your code: The problem is not in what you showed us, but in what you didn't show us. When we are presented with the whole enchilada, we can see that it is not a compiler or IDE configuration "issue." Your code (to which you gave a link to in a later post) also includes "lcd.h" and lcd.h has this #define EN RD3 In beeper.h, BEEPER1 is defined as #define BEEPER1 PWM5CONbits.EN With this in mind, consider BEEPER1 = 0; Now, after preprocessing, this line is presented to the compiler as PWM5CONbits.RD3 = 0; That's why the compiler complains. (And that's why it did not generate an error message when you moved your interrupt function to another file that did not include lcd.h) Maybe you can now see why the following line also triggers a compiler error message T0CON0bits.EN = 0 Bottom line: Beware of MACROS. Use something that is more likely to be unique So, in your program, instead of defining EN in lcd.h, maybe #define LCD_EN and use LCD_EN wherever you want to manipulate the LCD Enable signal. Also, an important programming note: Output signals should always use the LAT bit, not the PORT bit, so the following would be appropriate: #define LCD_EN LATDbits.LATD3 Search for RMW or read-modify-write in this forum and in about a gazillion other places on the web for explanations. This (read-modify-write phenomenon) is mentioned in section 16.0 of the 800+ page Data Sheet, but its significance is not emphasized. It's really, really (really) important. So, similarly, in your Lcd_Port() function, use LAT bits, not PORT bits: void Lcd_Port(char a) { if(a & 1) LATDbits.LATD4 = 1; else LATDbits.LATD4 = 0; // etc Bottom line: Even if your code seems to be working (or fluctuating between almost working and barely working), use of LAT bits for outputs will save lots of headaches and difficult-to-debug problems later on. Final note: As you gain experience with the K42, you may find that vectored interrupts, as suggested by 1and0 in post #9, can make for vastly more efficient and maintainable code. This is a Big Deal advance in the architecture of 8-bit PICs, and is one of the outstanding features of the K42 family. But here's the thing: In order to use the vectored interrupt functions you must change the MVECEN pragma: //#pragma config MVECEN = OFF // Multi-vector enable bit->Interrupt contoller does not use vector table to prioritze interrupts #pragma config MVECEN = ON // Multi-vector enable bit (Multi-vector enabled, Vector table used for interrupts) Regards, Dave |
|
|
|
这正是我所想的。你知道吗?我已经连续两天研究这个问题而没有咨询论坛,我想没有人会像往常一样知道我的问题。你的解释如此简单明了,我觉得我欠你一个人情!谢谢你对拉塔的回复。我对这些了解很多,因为我在RMW上有很多问题。LCD库不是我的,它是我朋友的,神奇的,它在他的电脑上工作。现在我们知道为什么。非常感谢贾景晖,DaveKW7X。
以上来自于百度翻译 以下为原文 This is exactly what I thought. And you know what? I've been working on this problem for two consecutive days without consulting the forum, I thought no one would really know, as usual on my questions. Your explaination was so exact and simple, I feel like I owe you! Thank you as well for the recommandations on LATA. I know much about those since I have had many problems regarding RMW. The lcd library was not mine, it was my friend's and miraculousely, it worked on his computer. Now we know why. Thank you very much davekw7x, Marc |
|
|
|
只有小组成员才能发言,加入小组>>
5171 浏览 9 评论
2001 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3176 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
737浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
635浏览 0评论
533浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 07:52 , Processed in 1.527885 second(s), Total 81, Slave 74 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号