J'écris un code où l'utilisateur peut appuyer sur une touche correspondant à l'information que l'utilisateur veut connaître et l'imprimer sur l'écran LCD. Jusqu'à présent, je suis en mesure d'écrire le code pour imprimer sur LCD mais je ne suis pas en mesure de comprendre comment demander à MCU d'attendre une frappe, puis imprimer. Quelqu'un peut-il me suggérer quelle est la logique pour le faire?Interruption de touche pour microcontrôleur PIC
Microcontrôleur: PIC18F4550; MPLAB X IDE, XC8 avec PICkit3. J'utilise Windows 7. Clavier: Clavier à matrice 3x4 - MCAK304NBWB
Mon code est:
#define C1_DAT LATBbits.LATB4 //Column 1 is set portB4 as output
#define C2_DAT LATBbits.LATB5 //Column 2 is set portB5 as output
#define C3_DAT LATBbits.LATB6 //Column 3 is set portB6 as output
#define C1_DIR TRISBbits.TRISB4 //Column 1 is set portB4 as output
#define C2_DIR TRISBbits.TRISB5 //Column 2 is set portB5 as output
#define C3_DIR TRISBbits.TRISB6 //Column 3 is set portB6 as output
.....
C1_DIR = 0; //drive column 1 low
rows[0] = PORTB & 0x0f; //read all four rows1 buttons
rows[1] = 0x0f;
rows[2] = 0x0f;
DelayXLCD();
if ((rows[0] & 0b0001) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key 1 is pressed");
DelayXLCD();
//break;
if ((rows[0] & 0b0010) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key 4 is pressed");
DelayXLCD();
//break;
if ((rows[0] & 0b0100) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key 7 is pressed");
DelayXLCD();
if ((rows[0] & 0b1000) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key * is pressed");
DelayXLCD();
//break;
if ((rows[1] & 0b0001) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key 2 is pressed");
DelayXLCD();
if ((rows[1] & 0b0010) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key 5 is pressed");
DelayXLCD();
//break;
if ((rows[1] & 0b0100) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key 8 is pressed");
//break;
if ((rows[1] & 0b1000) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key 0 is pressed");
DelayXLCD();
//break;
if ((rows[2] & 0b0001) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key 3 is pressed");
DelayXLCD();
//break;
if ((rows[2] & 0b0010) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key 6 is pressed");
DelayXLCD();
//break;
if ((rows[2] & 0b0100) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key 9 is pressed");
DelayXLCD();
//break;
if ((rows[2] & 0b1000) == 0) // will be zero if the "0" button is currently pressed.
putrsXLCD("key # is pressed");
DelayXLCD();
Delay_s(20);
//if ((rows[0] & rows[1] & rows[2]) == 0x0F) // will be 0x0F if all three values are 0x0F
//putrsXLCD("no keys are pressed");
//DelayXLCD();
} while((rows[0] & rows[1] & rows[2]) != 0x0F); // wait for keys release
{putrsXLCD("no keys are pressed");
Delay_s(50);
LCD_Clear();} //end of main loop
Avez-vous essayé de google par exemple, l'interruption de bouton? – Attila
Je l'ai fait, surtout l'idée de RESTER ÉLOIGNÉE à partir d'interruptions si je ne suis pas une personne expérimentée, ce que je ne suis pas.L'alternative à elle était minuterie.Je suis à la recherche.J'ai juste curieux, comment puis-je utiliser minuterie comme des interruptions? Puis-je utiliser 2 minuteries en même temps? – EEE