完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,我是新手,在一个PIC单片机上进行C编程。我正在慢慢地浏览各种教程和文献,试图应用我的知识。目前我正试图使用MPLAB IDE X,特别是引脚A5,使用好奇板来闪烁带有pic16f1619的LED。我的代码如下:include
以上来自于百度翻译 以下为原文 Hi there, I am newbie to C programming on a pic microcontroller. I am slowly working my way through the various tutorials and literature available to try and apply my knowledge. I am currently trying to blink an LED with the pic16f1619 using the curiosity board using MPLAB IDE X, specifically pin A5. My code is as follows: #include #include #include #define _XTAL_FREQ 32000000 //internal oscillator of pic16f1619 is 32MHz // Above is header files - xc is for compiler, stdlib is for general function and stdio is for I/O // Below is the bit configuration - this is taken from the curiosity mcc generated bit configuration // CONFIG1 #pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin) #pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) #pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR) #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) #pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) #pragma config IESO = ON // Internal/External Switch Over (Internal External Switch Over mode is enabled) #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config PPS1WAY = ON // Peripheral Pin Select one-way control (The PPSLOCK bit cannot be cleared once it is set by software) #pragma config ZCD = OFF // Zero Cross Detect Disable Bit (ZCD disable. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON) #pragma config PLLEN = ON // PLL Enable Bit (4x PLL is always enabled) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled) #pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled) // CONFIG3 #pragma config WDTCPS = WDTCPS1F// WDT Period Select (Software Control (WDTPS)) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config WDTCWS = WDTCWSSW// WDT Window Select (Software WDT window size control (WDTWS bits)) #pragma config WDTCCS = SWC // WDT Input Clock Selector (Software control, controlled by WDTCS bits) void main(void) { TRISAbits.TRISA5= 0; // set pin as output LATAbits.LATA5 = 1; //set pin as high while(1) { LATAbits.LATA5 = 1; //set pin as high __delay_ms(1000); //delay of 1second LATAbits.LATA5 = 0; //set pin as high } } // END At the moment there is no effect on the output of pin A5. I have tried changing the function of the pin with the different registers. Any help would be greatly appreciated! I am sware of this code - LATAbits.LATA5=~ LATAbits.LATA5; // Toggle Bit of Port A5 Any help would be greatly appreciated as I am really stuck! Regards |
|
相关推荐
11个回答
|
|
你的意思是一直都在?你可能需要给它一些关闭时间(延迟后设置低)。如果它熄灭了1U,你将无法在LED上看到它。
以上来自于百度翻译 以下为原文 You mean it's always on? You probably need to give it some off time (delay after setting it low). If it goes off for 1us, you won't be able to see it on the LED. |
|
|
|
摘录末尾的下列代码是:LATAbits.LATA5=1;//set pin为high_._ms(1000);//.of 1secondLATAbits.LATA5=0;//set pin为high吗?
以上来自于百度翻译 以下为原文 Does the following code at the end of the excerpt: LATAbits.LATA5 = 1; //set pin as high __delay_ms(1000); //delay of 1second LATAbits.LATA5 = 0; //set pin as high Not change the output of A5 from high to low with a delay of 1000ms, i.e. 1second? |
|
|
|
代码,也就是说,不会闪烁一个LED。在LATA5=0之后,您还需要另1秒的延迟。
以上来自于百度翻译 以下为原文 while(1) { LATAbits.LATA5 = 1; //set pin as high __delay_ms(1000); //delay of 1second LATAbits.LATA5 = 0; //set pin as high } The code, as-is, is not going to blink a LED. You'll need another 1-sec delay after LATA5 = 0. |
|
|
|
谢谢你回来-我增加了一个额外的延迟(1000),它没有任何效果。引脚A5的LED不断高?
以上来自于百度翻译 以下为原文 Thanks for getting back - I added an additional __delay_ms(1000) and it has no effect. The LED on pin A5 is constantly high? |
|
|
|
以上来自于百度翻译 以下为原文 you have this: while(1) { LATAbits.LATA5 = 1; //set pin as high __delay_ms(1000); //delay of 1second LATAbits.LATA5 = 0; //set pin as high __delay_ms(1000); //delay of 1second } _XTAL_FREQ 32000000 there is not way you are not getting a warning that delays overflows with a 1 second delay |
|
|
|
正如NKurzman所提到的,你在回路中打开LED,等待1000毫秒,关闭LED并立即返回。如果你有一个示波器,你会看到针A5低到一个时钟周期周期(TIN)。正如前面提到的那样,Y-DELAYSIMS(1000)会给编译器带来错误。1000是太大的,对于α-DelayyMs()。我需要一个单独的“助手”函数,当我需要一个快速和肮脏的方法产生长阻塞延迟。你也知道一些端口的模拟选择功能吗?安塞尔。例如ANSELLA=0x00;将端口设置为数字IO模式。我不熟悉你正在使用的设备,但安塞尔偶尔会给我带来麻烦。我不认为这特别适用于你的设备,但值得注意。
以上来自于百度翻译 以下为原文 As mentioned in by NKurzman... You're while loop turns the LED on, waits 1000ms, turns the LED off and immediately back on. If you have an oscilloscope you will see pin A5 go low for one clock cycle period (TCY). Also as mentioned __delay_ms(1000) will be giving you a compiler error. 1000 is too big for __delay_ms(). I use a separate 'helper' function when I need a quick and dirty method of generating a long blocking delay. void delay_ms(uint16_t t) { while(t--) __delay_ms(1); } Are you also aware of the analogue select function of some ports? ANSEL. For example ANSELA = 0x00; will set port A pins to digital IO mode. I'm not familiar with the device you are using, but ANSEL trips me up ocassionally. I don't think this applies specifically to your device, but it's worth noting. |
|
|
|
前几天安塞尔在PIC18上绊倒了我,但这是一个简单的解决办法。抓了我的头一段时间试图弄清楚为什么产量仍然不高。然后我还了解了PIN函数优先级表…数字I/O总是在优先级列表的最底部,所以您可能需要在它工作之前先禁用一些外围设备。数据表很好地解释了这一切。不要只是粗略地看一眼,花大量的时间阅读它。
以上来自于百度翻译 以下为原文 ANSEL tripped me up on a PIC18 the other day, but that was an easy enough fix. Scratched my head for a while trying to work out why an output still wasnt going high. Then I also learned about the pin function priority table... Digital I/O is always at the very bottom of the priority list, so you may need to disable some peripherals first before that works. Two little gotchyas to keep in mind. The datasheet is pretty good at explaining it all. Dont just give it a cursory glance, spend a good amount of time reading it. |
|
|
|
此外,除非你特别使用低压编程模式,你应该设置为关闭。对不起,虽然这通常是正确的,我忘了好奇板运行在LVP模式。
以上来自于百度翻译 以下为原文 |
|
|
|
我怀疑你的照片没有你想象的那么快。我不能更具体,因为这个PIC有新的振荡器模块,我还不熟悉它。
以上来自于百度翻译 以下为原文 I suspect your PIC doesn't run as fast as you expect. I cannot be more specific as this PIC has new oscillator module and I am not yet familiar with it. |
|
|
|
16F1619明确地拥有ANSELX寄存器,这些寄存器必须被正确配置以在I/O端口引脚上获得数字功能(它们默认为模拟输入)。
以上来自于百度翻译 以下为原文 The 16F1619 definately has ANSELx registers which must be properly configured to get digital functions on I/O port pins (they DEFAULT to analog inputs). |
|
|
|
通过配置字(FOSC=INTOSC)选择内部振荡器,默认时钟速度为500Khz(参见数据表)。为了让32Mhz列成“#._XTAL_FREQ 32000000//pic16f1619的内部振荡器32MHz”,您必须将OSCCON寄存器中的IRCF bts的值设置为“1111”。然而,这将产生16Mhz的频率而不是32Mhz,因为这是内部振荡器的最大频率,除非启用了4x锁相环(参见数据s中的适当部分)。
以上来自于百度翻译 以下为原文 With the internal oscillator selected by the config word (FOSC = INTOSC ) the default clock speed will be 500Khz (see data sheet). In order to get the 32Mhz listed as "#define _XTAL_FREQ 32000000 //internal oscillator of pic16f1619 is 32MHz" you MUST set the value of the IRCF bts in the OSCCON register to '1111'. This however will produce a frequency of 16 Mhz NOT 32 Mhz as this is the maximum frequency of the internal oscillator UNLESS the 4x PLL is enabled (see the appropriate sections in the data s |
|
|
|
只有小组成员才能发言,加入小组>>
5228 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3199 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
770浏览 1评论
658浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
585浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
668浏览 0评论
570浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-18 09:50 , Processed in 1.905311 second(s), Total 68, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号