完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,最近我用PIC16F1454做了一个简单的设备,这是我的第一次经历。它工作得很好,但是我发现有些奇怪的问题。第六引脚(RC4配置为输入)根本不起作用。我注意到这个引脚的工作原理就像它缩短了第5个引脚(RC5也配置为输入)。当RC5具有一些级别时,RC4也具有相同的级别。后来我用欧姆表检查了两个并且都显示~0欧姆。结果,我不得不用RA3引脚代替RC4。我想说RC4烧坏了,但是我的三个PIC都有同样的问题。这是否可能因为芯片配置错误呢?或者我有三个有错误引脚的芯片。谢谢!
以上来自于百度翻译 以下为原文 Hello, Recently I built a simple device based on PIC16F1454 - that was my first experience. It works great, but I found some weird trouble. 6th pin (RC4 configured as input) does not work at all. I noticed that this pin works like it shorted with 5th pin (RC5 configured as input too). ANSELC = 0; TRISC4 = 0; // row 2 of keyboard TRISC5 = 0; // row 3 of keyboard When RC5 has some level, RC4 has same level too. Afterwards I checked both with ohmmeter and it really shows ~0Ohm. As a result, I had to use RA3 pin instead RC4. I would say that RC4 is burned out, but all three my PICs have same problem. Is this possible because of fact that the chip is wrongly configured? Or I have three chips with faulty pin. Thanks! |
|
相关推荐
2个回答
|
|
|
|
|
|
哦,我很抱歉。上面的代码不是当前的——我把项目目录搞错了。源的最后版本,在这里是:
以上来自于百度翻译 以下为原文 Oh, I'm so sorry. The code above is not current - I mistook the project directory. The last version of the source, here it is: #include // CONFIG1 #pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = ON // Power-up Timer Enable (PWRT enabled) #pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is not digital input) #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 = OFF // Internal/External Switchover Mode (Internal/External Switchover Mode is disabled) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config CPUDIV = NOCLKDIV // CPU System Clock Selection Bit (CPU system clock divided by 1) #pragma config USBLSCLK = 48MHz // USB Low Speed Clock Selection bit (System clock expects 48 MHz, FS/LS USB CLKENs divide-by is set to 8.) #pragma config PLLMULT = 3x // PLL Multipler Selection Bit (3x Output Frequency Selected) #pragma config PLLEN = ENABLED // PLL Enable Bit (3x or 4x PLL Enabled) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will not cause a Reset) #pragma config BORV = HI // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), high trip point selected.) #pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled) #pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming) #define _XTAL_FREQ 48000000 #define IN_DATA_BUFFER_ADDRESS 0x2050 #define OUT_DATA_BUFFER_ADDRESS (IN_DATA_BUFFER_ADDRESS + HID_INT_IN_EP_SIZE) #define IN_DATA_BUFFER_ADDRESS_TAG @IN_DATA_BUFFER_ADDRESS #define OUT_DATA_BUFFER_ADDRESS_TAG @OUT_DATA_BUFFER_ADDRESS void init_osc(void) { OSCTUNE = 0x00; OSCCONbits.SPLLEN = 0b1; OSCCONbits.SPLLMULT = 0b1; OSCCONbits.IRCF = 0b1111; OSCCONbits.SCS = 0b00; OSCCON = 0b11111100; } void init_ports(void) { ANSELA = 0x00; ANSELC = 0x00; APFCONbits.CLKRSEL = 0; APFCONbits.SDOSEL = 0; APFCONbits.T1GSEL = 0; APFCONbits.P2SEL = 0; TRISA = 0x00; TRISC = 0x00; PORTA = 0x00; PORTC = 0x00; OPTION_REG = 0x00; OPTION_REGbits.nWPUEN = 0; /* RC4 and RC5 have external pull-up resistors 10K */ WPUAbits.WPUA4 = 1; WPUAbits.WPUA5 = 1; } void init_timer(void) { INTCONbits.GIE = 0b1; INTCONbits.TMR0IE = 0b1; OPTION_REGbits.PSA = 1; // prescaler - 1:2 OPTION_REGbits.PS0 = 0; OPTION_REGbits.PS1 = 0; OPTION_REGbits.PS2 = 0; } void init_kbd_cols(void) { /* cols - Z-state */ TRISC0 = 1; TRISC1 = 1; TRISC2 = 1; TRISC3 = 1; } void init_kbd(void) { /* rows */ RA4 = 1; TRISA4 = 1; RA5 = 1; TRISA5 = 1; RC4 = 1; TRISC4 = 1; RC5 = 1; TRISC5 = 1; init_kbd_cols(); LATA = 0x00; LATC = 0x00; } unsigned int key_find(unsigned char keypad) { unsigned int key = 0; if (keypad & 0x01) { switch (keypad) { case 0b00010001: key = 0x01; break; case 0b00100001: key = 0x02; break; case 0b01000001: key = 0x03; break; case 0b10000001: key = 0x04; break; default: key = 0x00; } } else if (keypad & 0x02) { switch (keypad) { case 0b00010010: key = 0x05; break; case 0b00100010: key = 0x06; break; case 0b01000010: key = 0x07; break; case 0b10000010: key = 0x08; break; default: key = 0x00; } } else if (keypad & 0x04) { switch (keypad) { case 0b00010100: key = 0x09; break; case 0b00100100: key = 0x0A; break; case 0b01000100: key = 0x0B; break; case 0b10000100: key = 0x0C; break; default: key = 0x00; } } else if (keypad & 0x08) { switch (keypad) { case 0b00011000: key = 0x0D; break; case 0b00101000: key = 0x0E; break; case 0b01001000: key = 0x0F; break; case 0b10001000: key = 0x10; break; default: key = 0x00; } } return key; } void kbd_io(void) { unsigned char keypad = 0; static unsigned int key = 0; static unsigned char column = 0; init_kbd_cols(); switch (column) { case 0x00: TRISC0 = 0; LATC0 = 0; keypad = 0x01; break; case 0x01: TRISC1 = 0; LATC1 = 0; keypad = 0x02; break; case 0x02: TRISC2 = 0; LATC2 = 0; keypad = 0x04; break; case 0x03: TRISC3 = 0; LATC3 = 0; keypad = 0x08; break; default: keypad = 0x00; } /* *** Here I'm stuck. *** When the button pressed in 4th row and 4th column, RC5 will be 0. But also at the same time RC4 will be cleared. So, the 4 and 5 bits of the port PORTC are always equals. If we change RC4 to RA3 pin, we get working code. */ keypad |= ((!RC5) << 7) | ((!RA5) << 6) | ((!RA4) << 5) | ((!RC4) << 4); init_kbd_cols(); if (keypad & 0xF0) { /* pressed some key */ key = key_find(keypad); } column++; if (column > 3) { column = 0; key = 0x00; } } void interrupt isr_code() { if ((TMR0IE == 1) && (TMR0IF == 1)) kbd_io(); } void main(void) { init_osc(); init_ports(); init_kbd(); init_timer(); while (1); } |
|
|
|
只有小组成员才能发言,加入小组>>
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 03:14 , Processed in 1.254107 second(s), Total 80, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号