完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好论坛,这让我困惑了一天左右。我已经做了一个超级简单的程序,作为一个踏脚石,更大的一个将进入16F873A。我有许多这些。对于代码配置工具中没有的部分,我从未使用过XC8。我成功地使用了它,很多项目,没有问题。基本上,我想要一个按钮上的RB1,将切换引脚RC0。先是低,然后按下按钮,RC0变高,再按一次,变低等等。它不会运行,我使用模拟器,它在第一个IF语句处停止!现在我用代码配置器在16F1938上创建了一个相同的项目,它在模拟器中工作得很好。我没有芯片可以尝试,但肯定会的。我不介意切换到另一个芯片,只是想了解为什么它不能在16F83A上工作!谢谢你帮我解决这个难题。它可能非常简单,我没有看到它。//CON.#pragma配置FOSC=HS//振荡器选择位(HS振荡器)#pragma配置WDTE=OFF//看门狗定时器启用位(WDT禁用)#pragma配置PWRTE=OFF//上电定时器启用位(PWRT禁用)#pragma配置BOREN=ON//Brown-Brown-dog输出复位启用位(BOR启用)#pragma配置LVP=ON//低压(单电源)在线串行编程启用位(RB3/PGM引脚具有PGM功能;低压编程启用)#pragma配置CPD=OFF//Data EEPROM内存代码保护位(数据EEPROM代码保护关闭)#pragm配置WRT=OFF//Flash程序存储器写启用位(写保护关闭;所有程序存储器可由EECON控制写入)#pragma配置CP=OFF//Flash程序存储器代码保护位(代码保护关闭)._XTAL_FREQ 4000000//Foscinclude
以上来自于百度翻译 以下为原文 Hello Forum, This has been puzzling me for a day or so. I have made a super simple program as a stepping stone to a larger one that will go into a 16F873A. I have many of these. I have never used XC8 for parts that are not in the code configurator tool. I used it successfully for many projects, no issues. Basically I want a pushbutton on RB1 that will toggle PIN RC0. First low, then push button, RC0 goes HIGH, push again, goes LOW, etc. It won't run, I use the simulator and it stops at the first IF statement! Now I create the same project on a 16F1938 using the Code Configurator and it works perfect in the simulator. I don't have a chip to try, but sure it will. I don't mind switching to the other chip, just want to understand why it won't work on the 16F873A! Thanks for any help with this puzzle. Its most likely simple and I am not seeing it. // CONFIG #pragma config FOSC = HS // Oscillator Selection bits (HS oscillator) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled) #pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled) #pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off) #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control) #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off) #define _XTAL_FREQ 4000000 //Fosc #include #include #include /* Main application */ void main(void) { // initialize the device TRISA = 0x01; TRISB = 0xFF; TRISC = 0x00; //PORTBbits.RB1 = 0; //OPTION_REGbits.nRBPU = 0x00; //********** Program Main Loop *********************************************** while(1) if(PORTBbits.RB1==1) { PORTCbits.RC0 = 1; } if(PORTBbits.RB1==0) { PORTCbits.RC0 = 0; } } |
|
相关推荐
11个回答
|
|
哦,是的,我忘了提及我正在使用MPLABX V2.26,XC8版本1.32I安装了MPLABX V3.xx,但对我来说仍然很奇怪。我需要适应它。
以上来自于百度翻译 以下为原文 Oh yes I forgot to mention I am using MPLABX V2.26, XC8 version 1.32 I installed MPLABX V3.xx but seems strange to me still. I need to get used to it. |
|
|
|
您缺少一些while(1)语句的括号。
以上来自于百度翻译 以下为原文 You are missing some braces for the while(1) statement. // CONFIG #pragma config FOSC = HS // Oscillator Selection bits (HS oscillator) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled) #pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled) #pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off) #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control) #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off) #define _XTAL_FREQ 4000000 //Fosc #include #include #include /* Main application */ void main(void) { // initialize the device TRISA = 0x01; TRISB = 0xFF; TRISC = 0x00; //PORTBbits.RB1 = 0; //OPTION_REGbits.nRBPU = 0x00; //********** Program Main Loop *********************************************** while(1) { // Add missing brace if(PORTBbits.RB1==1) { PORTCbits.RC0 = 1; } if(PORTBbits.RB1==0) { PORTCbits.RC0 = 0; } } // Add missing brace } |
|
|
|
好发现!“DAN1138@ SASALE 16F83A”被标记为“不推荐用于新设计”。它也有太多的硅勘误表,如果你可以切换到16F1933(或者任何16F1xxx),那么你应该(IMHO)
以上来自于百度翻译 以下为原文 Good spotting! @dan1138 @scasale 16F873A is marked as "Not Recommended for new designs". It also has too many silicon errata, if you can switch to 16F1933 (or any 16F1XXX) then you should (IMHO) |
|
|
|
这也是一种糟糕的代码方式,你可能会以竞争状态告终。像这样的情况会更好,所以在发布代码时总是使用代码标签。
以上来自于百度翻译 以下为原文 Also that is a bad way to code that, you could end up with a race condition. something like this would be better while( 1 ) { if( PORTBbits.RB1 == 1 ) { PORTCbits.RC0 = 1; } else { PORTCbits.RC0 = 0; } } or this PORTCbits.RC0 = PORTBbits.RB1; also always use code tags when posting code. |
|
|
|
就是这样!呸!我是怎么错过的?谢谢DA1138!我知道这是件简单的事。是的,当我耗尽了少数的83A我的,我要搬到1933或38个感谢的家伙!斯卡塞尔
以上来自于百度翻译 以下为原文 That was it! DOH! How did I miss that? Thanks Dan1138! Well I knew it was a simple thing. And yes, when I deplete the few 873A's I have, I am moving to the 1933 or 38's Thanks Guys! scasale |
|
|
|
好吧,TJ2015。有趣。它也更有效吗?我自学的东西,所以信息是有帮助的,当谈到编码。谢谢。
以上来自于百度翻译 以下为原文 Okay TJ2015. Interesting. Is it more efficient as well? I am self taught on this stuff, so info is helpful when it comes to coding. Thank you. |
|
|
|
不推荐新设计,因为它是旧的,不是因为它有缺陷。较新的芯片将更便宜,并具有更多的功能。这一系列是一个流行的芯片在它的一天。众所周知,它是一个坚固的CPU。
以上来自于百度翻译 以下为原文 It is not recommended for new designs becuse it is old, not becuse it is defective. A newer chip would be cheaper and have more features. That series was a popular chip in its day. It was known to be a solid CPU. |
|
|
|
使用免费版本的XC8时,效率是一个相对的术语。在这种情况下,它不是关于效率,而是关于确保代码不会做奇怪的事情。
以上来自于百度翻译 以下为原文 Efficiency is a relative term when using the free version of XC8. In this case it's not about efficiency, it's about making sure your code doesn't do weird things. |
|
|
|
效率是使用免费版本XC8时的一个相对术语。在这种情况下,它并不是关于效率,而是关于确保代码不会做奇怪的事情。C中防御性编码的主要指导原则是所有可能使用括号的构造都应该使用括号。
以上来自于百度翻译 以下为原文 Efficiency is a relative term when using the free version of XC8. In this case it's not about efficiency, it's about making sure your code doesn't do weird things. Prime directive of defensive coding in C is that all constructs that may use braces should use braces. |
|
|
|
是的,对我来说真的是一匹工作马。我要移动到1938个相同的引脚,所以我的板仍然工作!
以上来自于百度翻译 以下为原文 Yes, Has been a real work horse for me. I am moving to the 1938 which has same pin out so my boards will still work! |
|
|
|
是的,绝对可以。我把这些薯片塞进了一点!我一直使用MelBasePro的Melabs,但已经慢慢迁移到XC8。我注意到PBP,PWM信号有抖动,并且我不能用它去低频。使用XC8,PWM是岩石固体,我可以降到100Hz没有问题,没有抖动!所以我很可能把我的PBP编程风格带入我的C风格,我知道我需要在迁移方面做得更好。
以上来自于百度翻译 以下为原文 Yes, absolutely. I have packed quite a bit into these chips! I have been using PICBASIC PRO by MELABS, but have been migrating to XC8 slowly. I noticed with PBP, PWM signals have jitter in them and I can not go to low frequencies with it. Using XC8, PWM is rock solid and I can get down to 100HZ no problem, and no jitter! So I am most likely carrying my PBP programming style into my C style, and I know I need to do a better job of migration. |
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3174 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
734浏览 1评论
615浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
506浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
631浏览 0评论
528浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 21:57 , Processed in 1.685478 second(s), Total 119, Slave 102 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号