c - GPIO interrupt for different pins in PSoC 1 -
I have encountered a problem with GPIO interrupt. The task is to create a simple UI interface, so I use 3 buttons. The problem is that I do not understand how to use GPIO interrupts for different pins and all my buttons work in the same way.
Here is the code:
#include & lt; m8c.h & gt; // Part Specific Constants and Macros # Include "PSoCAPI.h" // Include PSOC API Definitions # for all user modules & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; Typedef Structure {int value; // Actual value in which the module is used in four strings [16]; // string that is printed in LCD for user) UI_ELEMENT; #define FIRST_LEVEL3 #define SECOND_LEVEL 3 #define PWM 0 #define PGA1 #define ADC 2 #define PWM_STATE 0 #define PWM_PERIOD # 1 defined PWM_WIDTH 2 #define PWM_STATE_OFF 0 # defined PWM_STATE_ON 1 volatile int buttonmate = 0; #pragma interrupt_handlerButtonButtonButtonRightInt (zero) {// disable button is blocking the M8C_DisableIntMask (INT_MSK0, INT_MSK0_GPIO); Press the buttonline = 1; } Zero initialize_LCD (zero) {LCD_Position (0,0); LCD_PrCString ("PWM"); LCD_Position (1,0); LCD_PrCString ("& lt; Select & gt;"); } Zero update_LCD (int * lvl1) {if (* lvl1 == PWM || * lvl1 == 3) {LCD_Position (0,0); LCD_PrCString ("PWM"); * Lvl1 = 0; } And if (* lvl1 == PGA) {LCD_Position (0,0); LCD_PrCString ("PGA"); } And if (* lvl1 == ADC) {LCD_Position (0,0); LCD_PrCString ("ADC"); }} Zero main (zero) {UI_ELEMENT User Interface [FIRST_LEVEL] [SECOND_LEVEL]; Int level_1_steper = PWM; Int i; M8C_EnableGInt; // Delete this line to enable global interrupts PWM8_EnableInt (); LCD_Start (); M8C_EnableIntMask (INT_MSK0, INT_MSK0_GPIO); initialize_LCD (); // Set the 'PWM' for the upper line, & lt; Select & gt; 'For the following line while (1) {if (press buttonRight == 1} {for (i = 0; i & lt; 350; i ++); Level_1_steper ++; Update_LCD (& level_1_steper); Press the buttonline = 0; // Enable button repeat M8C_EnableIntMask (INT_MSK0, INT_MSK0_GPIO); }}}}
The problem is resolved! As the solution is usually quite simple: hinder the use of GPIO, but check which button is pressed. GPIO Interface:
Zero Button End (Zero) {// Disable Button M8C_DisableIntMask (INT_MSK0, INT_MSK0_GPIO); If (Right_Data_ADDR & Right_MASK) button is reset = 1; If (Left_Data_ADDR & Left_MASK) Button LieftPressed = 1; If selected (Select_Data_ADDR and Select_MASK) button = 1; }
Comments
Post a Comment