Rafael Mena
/
ComunicacionDosNucleo
Tareita
Fork of UART0 by
main.cpp@1:9f10be874ce0, 2016-11-09 (annotated)
- Committer:
- a00958821
- Date:
- Wed Nov 09 18:43:15 2016 +0000
- Revision:
- 1:9f10be874ce0
- Parent:
- 0:9e15cfed60ea
- Child:
- 2:c3d5b9e7a5dd
holiwis
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hoangnguyen578 | 0:9e15cfed60ea | 1 | #include "mbed.h" |
a00958821 | 1:9f10be874ce0 | 2 | #include "TextLCD.h" |
a00958821 | 1:9f10be874ce0 | 3 | |
a00958821 | 1:9f10be874ce0 | 4 | TextLCD lcd(D2, D3, D4, D5, D6, D7); // rs, e, d4-d7 |
a00958821 | 1:9f10be874ce0 | 5 | |
a00958821 | 1:9f10be874ce0 | 6 | DigitalOut col1 (D8); |
a00958821 | 1:9f10be874ce0 | 7 | DigitalOut col2 (D9); |
a00958821 | 1:9f10be874ce0 | 8 | DigitalOut col3 (D10); |
a00958821 | 1:9f10be874ce0 | 9 | DigitalOut col4 (D11); |
a00958821 | 1:9f10be874ce0 | 10 | DigitalIn fila1 (A5); |
a00958821 | 1:9f10be874ce0 | 11 | DigitalIn fila2 (A4); |
a00958821 | 1:9f10be874ce0 | 12 | DigitalIn fila3 (A3); |
a00958821 | 1:9f10be874ce0 | 13 | DigitalIn fila4 (A2); |
hoangnguyen578 | 0:9e15cfed60ea | 14 | |
a00958821 | 1:9f10be874ce0 | 15 | RawSerial Uart1(A0, A1); // tx, rx |
a00958821 | 1:9f10be874ce0 | 16 | RawSerial Uart2(PC_10, PC_11); // tx, rx |
a00958821 | 1:9f10be874ce0 | 17 | |
a00958821 | 1:9f10be874ce0 | 18 | |
a00958821 | 1:9f10be874ce0 | 19 | |
a00958821 | 1:9f10be874ce0 | 20 | char Simbolos[4][4] = { |
a00958821 | 1:9f10be874ce0 | 21 | {'1','2','3','A'}, |
a00958821 | 1:9f10be874ce0 | 22 | {'4','5','6','B'}, |
a00958821 | 1:9f10be874ce0 | 23 | {'7','8','9','C'}, |
a00958821 | 1:9f10be874ce0 | 24 | {'*','0','#','D'} |
a00958821 | 1:9f10be874ce0 | 25 | }; |
a00958821 | 1:9f10be874ce0 | 26 | |
a00958821 | 1:9f10be874ce0 | 27 | volatile char Data[2]; |
a00958821 | 1:9f10be874ce0 | 28 | |
a00958821 | 1:9f10be874ce0 | 29 | int usrInput(); |
a00958821 | 1:9f10be874ce0 | 30 | void turnOffteclado(); |
a00958821 | 1:9f10be874ce0 | 31 | int * teclado(); |
a00958821 | 1:9f10be874ce0 | 32 | |
a00958821 | 1:9f10be874ce0 | 33 | void Uart1Rx_interrupt(); |
a00958821 | 1:9f10be874ce0 | 34 | void Uart2Rx_interrupt(); |
hoangnguyen578 | 0:9e15cfed60ea | 35 | |
hoangnguyen578 | 0:9e15cfed60ea | 36 | int main() { |
a00958821 | 1:9f10be874ce0 | 37 | lcd.cls(); |
a00958821 | 1:9f10be874ce0 | 38 | Uart1.baud(9600); |
a00958821 | 1:9f10be874ce0 | 39 | Uart2.baud(9600); |
a00958821 | 1:9f10be874ce0 | 40 | //lcd.printf("%d",Uart1.writeable()); |
a00958821 | 1:9f10be874ce0 | 41 | //lcd.printf("%d",Uart1.readable()); |
a00958821 | 1:9f10be874ce0 | 42 | while (Uart1.writeable() != 1){} |
a00958821 | 1:9f10be874ce0 | 43 | //Uart1.putc('b'); |
a00958821 | 1:9f10be874ce0 | 44 | Uart1.printf("hola amigos"); |
a00958821 | 1:9f10be874ce0 | 45 | while(Uart2.readable() != 1){} |
a00958821 | 1:9f10be874ce0 | 46 | Data[0] = Uart2.getc(); |
a00958821 | 1:9f10be874ce0 | 47 | lcd.printf("%c",Data[0]); |
a00958821 | 1:9f10be874ce0 | 48 | |
a00958821 | 1:9f10be874ce0 | 49 | /*Data[0] = 'n'; |
a00958821 | 1:9f10be874ce0 | 50 | |
a00958821 | 1:9f10be874ce0 | 51 | while(1) |
a00958821 | 1:9f10be874ce0 | 52 | { |
a00958821 | 1:9f10be874ce0 | 53 | int * Index; |
a00958821 | 1:9f10be874ce0 | 54 | Index = teclado(); |
a00958821 | 1:9f10be874ce0 | 55 | |
a00958821 | 1:9f10be874ce0 | 56 | |
a00958821 | 1:9f10be874ce0 | 57 | if (Simbolos[Index[0]][Index[1]] != '#') |
a00958821 | 1:9f10be874ce0 | 58 | { |
a00958821 | 1:9f10be874ce0 | 59 | Data[0] = Simbolos[Index[0]][Index[1]]; |
a00958821 | 1:9f10be874ce0 | 60 | lcd.cls(); |
a00958821 | 1:9f10be874ce0 | 61 | lcd.printf("%c",Data[0]); |
a00958821 | 1:9f10be874ce0 | 62 | } |
a00958821 | 1:9f10be874ce0 | 63 | else if(Simbolos[Index[0]][Index[1]] == '#' and Data[0] != 'n'){ |
a00958821 | 1:9f10be874ce0 | 64 | |
a00958821 | 1:9f10be874ce0 | 65 | while(Uart1.writeable() != 1){} |
a00958821 | 1:9f10be874ce0 | 66 | Uart1.putc(Data[0]); |
a00958821 | 1:9f10be874ce0 | 67 | |
a00958821 | 1:9f10be874ce0 | 68 | while (Uart1.readable() != 1){} |
a00958821 | 1:9f10be874ce0 | 69 | lcd.locate(0,1); |
a00958821 | 1:9f10be874ce0 | 70 | |
a00958821 | 1:9f10be874ce0 | 71 | Data[1] = Uart1.getc(); |
a00958821 | 1:9f10be874ce0 | 72 | lcd.printf("%c",Data[1]); |
a00958821 | 1:9f10be874ce0 | 73 | } |
a00958821 | 1:9f10be874ce0 | 74 | }*/ |
a00958821 | 1:9f10be874ce0 | 75 | } |
a00958821 | 1:9f10be874ce0 | 76 | |
a00958821 | 1:9f10be874ce0 | 77 | void Uart1Rx_interrupt() |
a00958821 | 1:9f10be874ce0 | 78 | { |
a00958821 | 1:9f10be874ce0 | 79 | |
a00958821 | 1:9f10be874ce0 | 80 | } |
a00958821 | 1:9f10be874ce0 | 81 | void Uart2Rx_interrupt() |
a00958821 | 1:9f10be874ce0 | 82 | { |
a00958821 | 1:9f10be874ce0 | 83 | |
a00958821 | 1:9f10be874ce0 | 84 | } |
a00958821 | 1:9f10be874ce0 | 85 | |
a00958821 | 1:9f10be874ce0 | 86 | int * teclado() |
a00958821 | 1:9f10be874ce0 | 87 | { |
a00958821 | 1:9f10be874ce0 | 88 | static int r[2]; |
a00958821 | 1:9f10be874ce0 | 89 | turnOffteclado(); |
a00958821 | 1:9f10be874ce0 | 90 | int numero; |
a00958821 | 1:9f10be874ce0 | 91 | while(1) |
a00958821 | 1:9f10be874ce0 | 92 | { |
a00958821 | 1:9f10be874ce0 | 93 | col1 = 1; |
a00958821 | 1:9f10be874ce0 | 94 | numero = usrInput(); |
a00958821 | 1:9f10be874ce0 | 95 | if (numero != 0) |
a00958821 | 1:9f10be874ce0 | 96 | { |
a00958821 | 1:9f10be874ce0 | 97 | r[0]=numero-1; |
a00958821 | 1:9f10be874ce0 | 98 | r[1]=0; |
a00958821 | 1:9f10be874ce0 | 99 | wait_ms(50); |
a00958821 | 1:9f10be874ce0 | 100 | return r; |
a00958821 | 1:9f10be874ce0 | 101 | } |
a00958821 | 1:9f10be874ce0 | 102 | turnOffteclado(); |
a00958821 | 1:9f10be874ce0 | 103 | col2 = 1; |
a00958821 | 1:9f10be874ce0 | 104 | numero = usrInput(); |
a00958821 | 1:9f10be874ce0 | 105 | if (numero != 0) |
a00958821 | 1:9f10be874ce0 | 106 | { |
a00958821 | 1:9f10be874ce0 | 107 | r[0]=numero-1; |
a00958821 | 1:9f10be874ce0 | 108 | r[1]=1; |
a00958821 | 1:9f10be874ce0 | 109 | wait_ms(50); |
a00958821 | 1:9f10be874ce0 | 110 | return r; |
a00958821 | 1:9f10be874ce0 | 111 | } |
a00958821 | 1:9f10be874ce0 | 112 | turnOffteclado(); |
a00958821 | 1:9f10be874ce0 | 113 | col3 = 1; |
a00958821 | 1:9f10be874ce0 | 114 | numero = usrInput(); |
a00958821 | 1:9f10be874ce0 | 115 | if (numero != 0) |
a00958821 | 1:9f10be874ce0 | 116 | { |
a00958821 | 1:9f10be874ce0 | 117 | r[0]=numero-1; |
a00958821 | 1:9f10be874ce0 | 118 | r[1]=2; |
a00958821 | 1:9f10be874ce0 | 119 | wait_ms(50); |
a00958821 | 1:9f10be874ce0 | 120 | return r; |
a00958821 | 1:9f10be874ce0 | 121 | } |
a00958821 | 1:9f10be874ce0 | 122 | turnOffteclado(); |
a00958821 | 1:9f10be874ce0 | 123 | col4 = 1; |
a00958821 | 1:9f10be874ce0 | 124 | numero = usrInput(); |
a00958821 | 1:9f10be874ce0 | 125 | if (numero != 0) |
a00958821 | 1:9f10be874ce0 | 126 | { |
a00958821 | 1:9f10be874ce0 | 127 | r[0]=numero-1; |
a00958821 | 1:9f10be874ce0 | 128 | r[1]=3; |
a00958821 | 1:9f10be874ce0 | 129 | wait_ms(50); |
a00958821 | 1:9f10be874ce0 | 130 | return r; |
a00958821 | 1:9f10be874ce0 | 131 | } |
a00958821 | 1:9f10be874ce0 | 132 | turnOffteclado(); |
a00958821 | 1:9f10be874ce0 | 133 | |
a00958821 | 1:9f10be874ce0 | 134 | } |
a00958821 | 1:9f10be874ce0 | 135 | } |
a00958821 | 1:9f10be874ce0 | 136 | |
a00958821 | 1:9f10be874ce0 | 137 | void turnOffteclado() |
a00958821 | 1:9f10be874ce0 | 138 | { |
a00958821 | 1:9f10be874ce0 | 139 | col1 = col2 = col3 = col4 = 0; |
a00958821 | 1:9f10be874ce0 | 140 | } |
a00958821 | 1:9f10be874ce0 | 141 | |
a00958821 | 1:9f10be874ce0 | 142 | int usrInput() |
a00958821 | 1:9f10be874ce0 | 143 | { |
a00958821 | 1:9f10be874ce0 | 144 | if (fila1 == 1) |
a00958821 | 1:9f10be874ce0 | 145 | { |
a00958821 | 1:9f10be874ce0 | 146 | return 1; |
a00958821 | 1:9f10be874ce0 | 147 | } |
a00958821 | 1:9f10be874ce0 | 148 | else if (fila2 == 1) |
a00958821 | 1:9f10be874ce0 | 149 | { |
a00958821 | 1:9f10be874ce0 | 150 | return 2; |
a00958821 | 1:9f10be874ce0 | 151 | } |
a00958821 | 1:9f10be874ce0 | 152 | else if (fila3 == 1) |
a00958821 | 1:9f10be874ce0 | 153 | { |
a00958821 | 1:9f10be874ce0 | 154 | return 3; |
a00958821 | 1:9f10be874ce0 | 155 | } |
a00958821 | 1:9f10be874ce0 | 156 | else if (fila4 == 1) |
a00958821 | 1:9f10be874ce0 | 157 | { |
a00958821 | 1:9f10be874ce0 | 158 | return 4; |
a00958821 | 1:9f10be874ce0 | 159 | } |
a00958821 | 1:9f10be874ce0 | 160 | else{ |
a00958821 | 1:9f10be874ce0 | 161 | return 0; |
a00958821 | 1:9f10be874ce0 | 162 | } |
hoangnguyen578 | 0:9e15cfed60ea | 163 | } |