cherif bend ahmane
/
EX2
chif la base
Fork of EX2 by
main.cpp@0:0457be6f6998, 2017-02-06 (annotated)
- Committer:
- Ruinedbot
- Date:
- Mon Feb 06 12:27:30 2017 +0000
- Revision:
- 0:0457be6f6998
- Child:
- 1:83047cac10cc
ex27
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ruinedbot | 0:0457be6f6998 | 1 | #include "mbed.h" |
Ruinedbot | 0:0457be6f6998 | 2 | #include "C12832.h" |
Ruinedbot | 0:0457be6f6998 | 3 | #define T_tab 10 |
Ruinedbot | 0:0457be6f6998 | 4 | |
Ruinedbot | 0:0457be6f6998 | 5 | Serial pc(USBTX, USBRX, 4800); |
Ruinedbot | 0:0457be6f6998 | 6 | C12832 lcd(PA_7,PA_5,PA_6,PA_8,PB_6); |
Ruinedbot | 0:0457be6f6998 | 7 | DigitalOut Led1 (D8); |
Ruinedbot | 0:0457be6f6998 | 8 | |
Ruinedbot | 0:0457be6f6998 | 9 | char Octet [T_tab] = {0}; // Tableau des stockage des caracteres |
Ruinedbot | 0:0457be6f6998 | 10 | char ready = 0; // Flag qui permet de savoir quand le tableau est rempli |
Ruinedbot | 0:0457be6f6998 | 11 | |
Ruinedbot | 0:0457be6f6998 | 12 | void rxCallback() |
Ruinedbot | 0:0457be6f6998 | 13 | { |
Ruinedbot | 0:0457be6f6998 | 14 | static char cpt = 0; // Permet de parcourir getc et de savoir quand il est rempli |
Ruinedbot | 0:0457be6f6998 | 15 | |
Ruinedbot | 0:0457be6f6998 | 16 | Led1=!Led1; |
Ruinedbot | 0:0457be6f6998 | 17 | |
Ruinedbot | 0:0457be6f6998 | 18 | if (ready != 1) { |
Ruinedbot | 0:0457be6f6998 | 19 | Octet [cpt] = pc.getc(); // Stock le cractere recu dans Octet |
Ruinedbot | 0:0457be6f6998 | 20 | cpt++; |
Ruinedbot | 0:0457be6f6998 | 21 | |
Ruinedbot | 0:0457be6f6998 | 22 | if (cpt == 8) { // Si le tableau est rempli |
Ruinedbot | 0:0457be6f6998 | 23 | ready = 1; // On met le flag a 1 |
Ruinedbot | 0:0457be6f6998 | 24 | cpt = 0; // On remet le compteur a 0 |
Ruinedbot | 0:0457be6f6998 | 25 | } |
Ruinedbot | 0:0457be6f6998 | 26 | } |
Ruinedbot | 0:0457be6f6998 | 27 | } |
Ruinedbot | 0:0457be6f6998 | 28 | |
Ruinedbot | 0:0457be6f6998 | 29 | int main() |
Ruinedbot | 0:0457be6f6998 | 30 | { |
Ruinedbot | 0:0457be6f6998 | 31 | char i = 0; //compteur qui permet de parourir Octet |
Ruinedbot | 0:0457be6f6998 | 32 | pc.attach( &rxCallback, pc.RxIrq); // attach de l'isr de reception |
Ruinedbot | 0:0457be6f6998 | 33 | |
Ruinedbot | 0:0457be6f6998 | 34 | |
Ruinedbot | 0:0457be6f6998 | 35 | while (1) { |
Ruinedbot | 0:0457be6f6998 | 36 | if (ready == 1) |
Ruinedbot | 0:0457be6f6998 | 37 | { |
Ruinedbot | 0:0457be6f6998 | 38 | for (i = 0; i <8; i++) { |
Ruinedbot | 0:0457be6f6998 | 39 | lcd.printf("%c", Octet[i]); |
Ruinedbot | 0:0457be6f6998 | 40 | pc.printf("%c", Octet[i]); |
Ruinedbot | 0:0457be6f6998 | 41 | } |
Ruinedbot | 0:0457be6f6998 | 42 | ready = 0;// Remise a 0 du flag |
Ruinedbot | 0:0457be6f6998 | 43 | lcd.printf ("\n"); |
Ruinedbot | 0:0457be6f6998 | 44 | pc.putc('\n'); |
Ruinedbot | 0:0457be6f6998 | 45 | } |
Ruinedbot | 0:0457be6f6998 | 46 | |
Ruinedbot | 0:0457be6f6998 | 47 | } |
Ruinedbot | 0:0457be6f6998 | 48 | } |