I have the following problem with BASYS MX3: When I try using BTNL or BTNU in debug mode, they are read as 1 when they are not pressed, but only sometimes, yet regularly.
This problem does not occur when I press "Make and program device Main Project" instead of "Debug main project". Other buttons are working just fine with both debug and program mode.
The code I am using:
/* assignment1_3.c */#include<xc.h>#include"assignment1_3.h"int main(){
TRISA =0x00;TRISBbits.TRISB1 =1;// RB1 (BTNU) configured as inputANSELBbits.ANSB1 =0;// RB1 (BTNU) disabled analogTRISBbits.TRISB0 =1;// RB1 (BTNL) configured as inputANSELBbits.ANSB0 =0;// RB1 (BTNL) disabled analogTRISFbits.TRISF4 =1;// RF0 (BTNC) configured as inputTRISBbits.TRISB8 =1;// RB8 (BTNR) configured as inputANSELBbits.ANSB8 =0;// RB8 (BTNR) disabled analogTRISAbits.TRISA15 =1;// RA15 (BTND) configured as input
LATA =0x00;//Turn the leds offint i =0;while(1){if(BTNL ==1){//going mad: BTNU, BTNL, Going well: BTND, BTNR, BTNC
i++;int a =0;for(a; a <100000; a++){};while(BTNL){};for(a; a <100000; a++){};
LATA = i%16;}}return(0);}
The idea of the program is to increment the counter whenever the button is pressed, which works fine in for all the buttons but BTNU and BTNL. For those two the button is read as 1 without pressing, but it is also read as 0, because while(BTNL) actually exits.
The questions are: why do programming the device works just fine for all the buttons, but debugging only for some of them? Why does it happen to up and left button only? What can I do to fix it?
This bug was also noticed by my teacher and one of my friends, so it does not seem to be related to a single board.
I am using compiler XC32 v1.44 and MPLAB X IDE v4.00
Question
MichalMikolajczyk
Good afternoon,
I have the following problem with BASYS MX3: When I try using BTNL or BTNU in debug mode, they are read as 1 when they are not pressed, but only sometimes, yet regularly.
This problem does not occur when I press "Make and program device Main Project" instead of "Debug main project". Other buttons are working just fine with both debug and program mode.
The code I am using:
The idea of the program is to increment the counter whenever the button is pressed, which works fine in for all the buttons but BTNU and BTNL. For those two the button is read as 1 without pressing, but it is also read as 0, because while(BTNL) actually exits.
The questions are: why do programming the device works just fine for all the buttons, but debugging only for some of them? Why does it happen to up and left button only? What can I do to fix it?
This bug was also noticed by my teacher and one of my friends, so it does not seem to be related to a single board.
I am using compiler XC32 v1.44 and MPLAB X IDE v4.00
Many thanks for your input,
Michał Mikołajczyk
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.