1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
零件号是PIC24HJ128GP502插入MICROStiCKIII已经做了太多RTFM,我想我需要从I/O端口应用笔记。即使App Note告诉你读PIN,代码示例也不显示它。这个中断没有发生,而且我有一个漂亮的3.3V方波在针上敲击。我也尝试过CN13,这里的代码例子是CN14。如果有人看到我看不到的东西,我很感激,谢谢。
以上来自于百度翻译 以下为原文 part number is PIC24HJ128GP502 plugged into the MicrostickII I've done as much RTFM as I think I need from the I/O Ports App Notes. Even though the App Note tells you to read the pin, the code examples don't show it. This interrupt just is not occurring, and I've got a nice 3.3V square wave banging away on the pin. I've tried CN13 as well, the code example here is CN14. Grateful if someone sees what I'm not seeing, thank you. void __attribute__ ((__interrupt__, no_auto_psv)) _CNInterrupt(void) { if (T1CONbits.TON) // timer is running bitcounter++; IFS1bits.CNIF = 0; //clear this interrupt LATBbits.LATB5 = 1; // lemme know bitstate = PORTBbits.RB12; // same as CN14 } void setup_changenotification(void) { int bitstate; CNEN1bits.CN14IE = 1; //interrupt on CN14 CNPU1bits.CN14PUE = 1; //use a pull up on CN14 IPC4bits.CNIP = 3; // priority 3 TRISBbits.TRISB12 = 1; //same as change notification pin CN14 IEC1bits.CNIE = 1; // enable CN interrupt IFS1bits.CNIF = 0; // clear int flag bitstate = PORTBbits.RB12; } |
|
相关推荐
17个回答
|
|
当然,我会用这个:
以上来自于百度翻译 以下为原文 Just to be sure, I'd use this: LATBbits.LATB5 ^= 1; // lemme know |
|
|
|
您禁用了PIN上的任何模拟功能吗?
以上来自于百度翻译 以下为原文 Have you disabled any analog features on that pin? |
|
|
|
谢谢,我以前见过这个答案…我该怎么做呢?
以上来自于百度翻译 以下为原文 jtemples, thanks, I've seen this answer before... how would I do that? |
|
|
|
谢谢,我以前看过这个答案,我如何禁用那个引脚上的模拟特性?
以上来自于百度翻译 以下为原文 jtemples, thanks, I've seen this answer before, how do I disable analog features on that pin? |
|
|
|
|
|
|
|
在数据表/AD1PCFGL寄存器中配置“模拟端口引脚”部分。
以上来自于百度翻译 以下为原文 "Configuring Analog Port Pins" section in the data sheet / AD1PCFGL register. |
|
|
|
谢谢,我ADAD1PCFGL=0;现在我正在寻找任何来自任何地方的样例代码,没有别的东西可以让任何CN工作在这个PIC24芯片的任何引脚上,我将从那里开始。谢谢
以上来自于百度翻译 以下为原文 Thanks, I had AD1PCFGL=0; now I'm looking for any sample code from anywhere and nothing else to get any CN working on any pin for this PIC24 chip and I'll start from there. thanks |
|
|
|
清醒检查。确保自己的代码可以读取PIN,并将其复制到另一个PIN。
以上来自于百度翻译 以下为原文 Sanity check. Make sure your own code can read the pin and copy it to another pin. |
|
|
|
现在我把所有的东西都放在这个代码上测试一个PIC24HJ64 PG502,测试不同的引脚。这个设置有一些根本错误,这将阻止我做一个hello World更改通知测试。我没有进入中断。我可以读/写每一个密码,但是这个中断并不快乐。我不是新手,但我的自尊心受到了打击。我已经阅读了MPLAB IDE用户指南,看我能否确认PIC芯片在代码中有中断。
以上来自于百度翻译 以下为原文 I've now dropped everything down to this code testing a PIC24HJ64PG502, testing different pins. There is something fundamentally wrong with this setup that would prevent me from doing a Hello World Change Notification test. I'm getting no entry to the interrupt. I can read/write to each pin, but this interrupt ain't happnin'. I'm not a novice at this, but my ego is taking a hit. I've read through the MPLAB IDE User Guide to see if I can confirm that the PIC chip has the interrupt in the code. #include #include #include #include void __attribute__((__interrupt__, no_auto_psv)) _CNInterrupt(void) { LATBbits.LATB5 ^= 1; // lemme know IFS1bits.CNIF = 0; //clear this interrupt } int main(int argc, char** argv) { TRISBbits.TRISB5 = 0; // want this pin to go high in the interrupt routine LATBbits.LATB5 = 0; TRISBbits.TRISB3 = 1; // B port input, it's change notification pin CN7 CNEN1 = 0; //clearing the CNEN1 register first CNEN1bits.CN7IE = 1; //interrupt on CN7 CNPU1bits.CN7PUE = 1; //use a pull up on CN7 IPC4bits.CNIP = 2; // priority 3 IEC1bits.CNIE = 1; // enable CN interrupt IFS1bits.CNIF = 0; //clear the interrupt flag PMCON = 0; //clear parallel port AD1PCFGL = 0; //clear analog pins while(1); return (EXIT_SUCCESS); } Attached Image(s) |
|
|
|
为了确保PIC正在运行,你能在主回路中添加另一个闪烁的LED(还有一些延迟)吗?
以上来自于百度翻译 以下为原文 Just to be sure PIC is running, can you add another blinking led in main loop (and some delay too) ? |
|
|
|
不要写那些你不知道他们想要什么的东西。
以上来自于百度翻译 以下为原文 //#include //#include #include //#include void __attribute__((__interrupt__, no_auto_psv)) _CNInterrupt(void) { LATBbits.LATB5 ^= 1; // lemme know PORTB; // dummy port read to re-enable the CN functionality IFS1bits.CNIF = 0; //clear this interrupt } int main() { //int argc, char** argv) { - what for? TRISBbits.TRISB5 = 0; // want this pin to go high in the interrupt routine LATBbits.LATB5 = 0; TRISBbits.TRISB3 = 1; // B port input, it's change notification pin CN7 CNEN1 = 0; //clearing the CNEN1 register first CNEN1bits.CN7IE = 1; //interrupt on CN7 CNPU1bits.CN7PUE = 1; //use a pull up on CN7 IPC4bits.CNIP = 2; // priority 3 IFS1bits.CNIF = 0; //clear the interrupt flag IEC1bits.CNIE = 1; // enable CN interrupt //PMCON = 0; //clear parallel port - what for? AD1PCFGL = 0; //clear analog pins while(1); //return (EXIT_SUCCESS); - what for? } Do not write the things you have no idea what are they for. |
|
|
|
我有闪烁的LED在MICROSTICK板上,同时(1){LababIT.LATA0^=1;γ-DelayyMS(500);}
以上来自于百度翻译 以下为原文 I've got the blinking LED on the Microstick board with this while(1) { LATAbits.LATA0 ^= 1; __delay_ms(500); } |
|
|
|
在第一版本代码的某个地方,来自PoLTB的读取已经就位…@ OP:那么,现在您有主循环闪烁和中断代码两种情况了吗?
以上来自于百度翻译 以下为原文 Somewhere around the 1st version of code, the Read from PORTB was in place... @OP: so, now you have both main loop blinking AND interrupt code? |
|
|
|
礼貌更新:让它工作(颠簸)切换到CN1。这应该是一个重要的职位,任何人采取相同的路径,我做了。这意味着它现在是一个科学项目来找出其他别针的竞争特征需要被禁用。我很感激大家的支持。谢谢您!!
以上来自于百度翻译 以下为原文 Courtesy update: Got it working by (thrashing) switching to CN1. This should be an important post to anyone who took the same path I did. This means that it's now a science project to figure out what competing feature on the other pins need to be disabled. I'm grateful for the support from everyone. thank you!! |
|
|
|
如果你希望PIN是数字的,你需要设置它们,而不是清除它们。
以上来自于百度翻译 以下为原文 If you want pins to be digital, you need to set them, not clear them. |
|
|
|
|
|
|
|
GWAYSANDIGIO,这里的代码实现了您所要求的。这不是一个“科学项目”来完成这项工作,但是它确实需要仔细阅读Microchip文档。我试图显式地设置或清除设置变更通知和GPIO状态所需的每个比特来获得BEHA。你需要的。许多状态是所涉及位的上电复位状态。这导致代码有点迂腐。最后一点是,该代码与MPLABX模拟器一起工作,但还没有在真正的MICROStICKII中进行测试。
以上来自于百度翻译 以下为原文 @gwa_SanDiego, The code here implements what you asked for. It is not a "science project" to make this work but it does take a lot of careful reading of the Microchip documentation. I tried to explicitly set or clear each bit required to setup the change notification and the GPIO state to get the behavior you need. Many of the states are the Power-On-Reset state of the bits involved. This results in code that is somewhat pedantic. One last note is that this code works with the MPLABX simulator but has not been tested in a real MicroStickII. /* * File: main.c * Author: * Target: PIC24HJ128GP502 in a MicroStickII (DM240013-1, DM330013-2) * * Created on June 17, 2018, 11:39 AM * * Description: * Detect change on RB12 input and assert a CN interrupt. * Toggle LED on each interrupt. * * PIC24HJ128GP502 * +--------------------------:_:--------------------------+ * S4/VPP -> : 1 MCLR AVDD 28 : <- 3v3 * LED <> : 2 RA0/CN2/AN0 AVSS 27 : <- GND * <> : 3 RA1/CN3/AN1 RP15/AN9/CN11/RB15 26 : <> * PGD <> : 4 RB0/CN4/PGED1/AN2/RP0 RP14/AN10/RTCC/CN12/RB14 25 : <> * PGC <> : 5 RB1/CN5/PGEC1/AN3/RP1 RP13/AN11/CN13/RB13 24 : <> * RXD <> : 6 RB2/CN6/AN4/RP2 RP12/AN12/CN14/RB12 23 : <> CN_Input * <> : 7 RB3/CN7/AN5/RP3 RP11/PGEC2/CN15/RB11 22 : <> * GND <> : 8 VSS RP10/PGED2/CN16/RB10 21 : <> * <> : 9 RA2/CN30/OSCI VCAP 20 : <- 10uF capcitor * <> : 10 RA3/CN29/OSCO VSS 19 : <- GND * <> : 11 RB4/CN1/RP4 RP9/SDA1/CN21/RB9 18 : <> * <> : 12 RA4/CN0 RP8/SCL1/CN22/RB8 17 : <> * 3v3 <> : 13 VDD RP7/INT0/CN23/RB7 16 : <> TXD * <> : 14 RB5/CN27/PGD3/RP5 RP6/PGEC3/CN24/RB6 15 : <> * +-------------------------------------------------------+ * DIP-28 */ // PIC24HJ128GP502 Configuration Bit Settings // FBS #pragma config BWRP = WRPROTECT_OFF // Boot Segment Write Protect (Boot Segment may be written) #pragma config BSS = NO_FLASH // Boot Segment Program Flash Code Protection (No Boot program Flash segment) #pragma config RBS = NO_RAM // Boot Segment RAM Protection (No Boot RAM) // FSS #pragma config SWRP = WRPROTECT_OFF // Secure Segment Program Write Protect (Secure segment may be written) #pragma config SSS = NO_FLASH // Secure Segment Program Flash Code Protection (No Secure Segment) #pragma config RSS = NO_RAM // Secure Segment Data RAM Protection (No Secure RAM) // FGS #pragma config GWRP = OFF // General Code Segment Write Protect (User program memory is not write-protected) #pragma config GSS = OFF // General Segment Code Protection (User program memory is not code-protected) // FOSCSEL #pragma config FNOSC = FRC // Oscillator Mode (Internal Fast RC (FRC)) #pragma config IESO = OFF // Internal External Switch Over Mode (Start-up device with user-selected oscillator source) // FOSC #pragma config POSCMD = NONE // Primary Oscillator Source (Primary Oscillator Disabled) #pragma config OSCIOFNC = ON // OSC2 Pin Function (OSC2 pin has digital I/O function) #pragma config IOL1WAY = OFF // Peripheral Pin Select Configuration (Allow Multiple Re-configurations) #pragma config FCKSM = CSECMD // Clock Switching and Monitor (Clock switching is enabled, Fail-Safe Clock Monitor is disabled) // FWDT #pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler (1:32,768) #pragma config WDTPRE = PR128 // WDT Prescaler (1:128) #pragma config WINDIS = OFF // Watchdog Timer Window (Watchdog Timer in Non-Window mode) #pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog timer enabled/disabled by user software) // FPOR #pragma config FPWRT = PWR128 // POR Timer Value (128ms) #pragma config ALTI2C = OFF // Alternate I2C pins (I2C mapped to SDA1/SCL1 pins) // FICD #pragma config ICS = PGD1 // Comm Channel Select (Communicate on PGC1/EMUC1 and PGD1/EMUD1) #pragma config JTAGEN = OFF // JTAG Port Enable (JTAG is Disabled) /* * Required header files */ #include #include /* * Instruction clock frequency target is (7372800 * 43) / (2 * 2 * 2) = 39628800 Hz * Note: Maximum instruction clock frequency is 40 MHz. */ #define FOSC 7372800L #define PLL_M 43L #define PLL_N1 2L #define PLL_N2 2L #define FCYC ((FOSC * PLL_M) / (PLL_N1 * PLL_N2 * 2L)) /* * Global memory */ uint16_t gPORTA_CN_status; uint16_t gPORTB_CN_status; /* * Interrupt on change handler */ void __attribute__ ((__interrupt__, no_auto_psv)) _CNInterrupt(void) { uint16_t PORTA_CN_status,PORTA_CN_changed; uint16_t PORTB_CN_status,PORTB_CN_changed; PORTA_CN_status = PORTA; // Read all ports with CN inputs PORTB_CN_status = PORTB; // to update changed latches. IFS1bits.CNIF = 0; // clear CN interrupt LATAbits.LATA0 ^= 1; // Toggle MicroStickII LED on CN interrupt PORTA_CN_changed = gPORTA_CN_status ^ PORTA_CN_status; PORTB_CN_changed = gPORTB_CN_status ^ PORTB_CN_status; gPORTA_CN_status = PORTA_CN_status; gPORTB_CN_status = PORTB_CN_status; } /* * Setup interrupt on change input */ void CN_Init(void) { IEC1bits.CNIE = 0; // disable CN interrupt _RP12R = 0; // unmap RB12/RP12/CN14/AN12 output, Note may require a PPS unlock. AD1PCFGLbits.PCFG12 = 1; // make AN12 digital I/O TRISBbits.TRISB12 = 1; // make RB12 an input CNPU1bits.CN14PUE = 1; // enable the weak pull-up on CN14 CNEN1bits.CN14IE = 1; // interrupt on CN14 IPC4bits.CNIP = 3; // priority 3 gPORTA_CN_status = PORTA; // Read all ports with CN inputs gPORTB_CN_status = PORTB; // to update changed latches. IFS1bits.CNIF = 0; // clear CN interrupt request IEC1bits.CNIE = 1; // enable CN interrupt } /* * Initialize this PIC */ void PIC_Init(void) { /* * Disable all interrupt sources */ __builtin_disi(0x3FFF); /* disable interrupts for 16383 cycles */ IEC0 = 0; IEC1 = 0; IEC2 = 0; IEC3 = 0; IEC4 = 0; __builtin_disi(0x0000); /* enable interrupts */ AD1PCFGL = 0xffff; /* Set for digital I/O */ _NSTDIS = 1; /* disable interrupt nesting */ /* * Switch to clock source required by this implementation */ if(!OSCCONbits.CLKLOCK) { uint16_t Timeout; __builtin_write_OSCCONH(0x00); // select FRC as primary oscillator __builtin_write_OSCCONL(OSCCON | _OSCCON_OSWEN_MASK); // Request oscillator change for(Timeout = 60000; Timeout; --Timeout) if (!OSCCONbits.OSWEN) break; // Wait for oscillator to switch /* * Configure the PLL */ #if ((PLL_M >= 2) && (PLL_M <= 513)) PLLFBD = PLL_M-2; #else #error "PLL Multiplier selection is out of range. Must be from 2 to 513." #endif #if (PLL_N2 == 2) CLKDIVbits.PLLPOST=0; // N2=2 #elif (PLL_N2 == 4) CLKDIVbits.PLLPOST=1; // N2=4 #elif (PLL_N2 == 8) CLKDIVbits.PLLPOST=3; // N2=8 #else #error "PLL Output divisor selection is out of range. Must be 2,4 or 8 only." #endif #if ((PLL_N1 >= 2) && (PLL_N1 <= 33)) CLKDIVbits.PLLPRE=PLL_N1-2; // N1 #else #error "PLL Input divisor selection is out of range. Must be from 2 to 33." #endif __builtin_write_OSCCONH(0x01); // select FRC+PLL as primary oscillator __builtin_write_OSCCONL(OSCCON | _OSCCON_OSWEN_MASK); // Request oscillator change for(Timeout = 60000; Timeout; --Timeout) if (!OSCCONbits.OSWEN) break; // Wait for oscillator to switch for(Timeout = 60000; Timeout; --Timeout) if (OSCCONbits.LOCK) break; // Wait for PLL to lock /* * Map the MicroStickII UART pins */ _U1RXR = 2; // Map UART1 RX input to RB2 _RP7R = _RPOUT_U1TX; // Map UART1 TX output to RB7 } } /* * Main application */ int main(void) { /* * Application initialization */ PIC_Init(); CN_Init(); /* * Configure MicroStickII LED for debug use. * Note: J3 must be installed to connect LED to RA0 */ CNPU1bits.CN2PUE = 0; // disable the weak pull-up on RA0/AN0/CN2 CNEN1bits.CN2IE = 0; // disable interrupt on CN2 AD1PCFGLbits.PCFG0 = 1; // Make AN0 digital I/O TRISAbits.TRISA0 = 0; // Make RA0 an output LATAbits.LATA0 = 0; // Turn off MicroStickII LED /* * Application loop */ for(;;) { /* This infinite loop is here because embedded applications never return from main */ } return 0; } |
|
|
|
只有小组成员才能发言,加入小组>>
5242 浏览 9 评论
2031 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3207 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2256 浏览 5 评论
778浏览 1评论
669浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
596浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
679浏览 0评论
577浏览 0评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 23:09 , Processed in 1.945668 second(s), Total 108, Slave 92 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号