3552 views|1 replies

7

Posts

0

Resources
The OP

PIC1939 About I/O port configuration and priority configuration [Copy link]

Thanks for your support! RC0 is used as key input. The key is valid when it is low. The problem is that my key is invalid. In order to verify whether the key is valid, I added LED_Error2 and LED_Error1 in the key processing. They should be displayed alternately as I press and lift the key, but in fact only LED_Error1 is always on. I think there is no problem with the key processing (the same method has been tried with RA6 port, and the function can be realized). I suspect that it is a problem with the priority of RC0 port, but I don’t know where the specific problem is. How to configure the I/O priority? Please advise. I would be more grateful if you attach a short code explanation! I didn't understand the data sheet, so I'll continue reading~~ My code is as follows: The configuration is as follows: #define ON_SW RC0 //On/Off key __CONFIG(FOSC_INTOSC&PWRTE_ON&MCLRE_OFF&WDTE_OFF&CP_OFF&CPD_OFF&BOREN_OFF&IESO_ON&FCMEN_OFF); __CONFIG(WRT_ALL&PLLEN_OFF&BORV_25&LVP_OFF); #define ON_SW RC0 //On/Off key void GPIO_Init() { TRISC = 0b00000001;//PORTC data direction register, 1 input, 0 output PORTC = 0b11111110; } void main() { while (1) { GPIO_Init(); KEY_SCAN(); } } void KEY_SCAN(void) { if (FLAG.KeyScan == 1)//Generated by time sharing, { FLAG.KeyScan = 0; if( ON_SW )//================== Power on and off keys======================= { LED_Error2_ON; LED_Error1_OFF; ON_SW_L_CNT = 0; if(ON_SW_H_CNT > KeyJitterTime) { Key_Old.On = HIGH; KeyClick.On = Release; } else { ON_SW_H_CNT++; } } else { LED_Error1_ON; LED_Error2_OFF; ON_SW_H_CNT = 0; if(ON_SW_L_CNT > KeyJitterTime) { if(Key_Old.On == HIGH) { KeyClick.On = Presd; } Key_Old.On = LOW; KeyIdleCNT = 0; } else { ON_SW_L_CNT++; } }
This post is from Microchip MCU

Latest reply

PIC's IO operations are read, modify and write. If two LEDs are configured as one port, an error will occur (when the CPU speed is high). LED_Error2_ON; LED_Error1_OFF; If the problem is here, you can add a delay between them. Ports have no concept of priority.  Details Published on 2012-12-28 09:34

50

Posts

0

Resources
2
PIC's IO operations are read, modify and write. If two LEDs are configured as one port, an error will occur (when the CPU speed is high). LED_Error2_ON; LED_Error1_OFF; If the problem is here, you can add a delay between them. Ports have no concept of priority.
This post is from Microchip MCU

Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

    Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list