Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:c2e9b51c378c, 2015-11-17 (annotated)
- Committer:
- ZirkofDGJ
- Date:
- Tue Nov 17 05:01:11 2015 +0000
- Revision:
- 0:c2e9b51c378c
Comunicacion Serial con LCD 16x2
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ZirkofDGJ | 0:c2e9b51c378c | 1 | #include "mbed.h" |
| ZirkofDGJ | 0:c2e9b51c378c | 2 | #include "TextLCD.h" |
| ZirkofDGJ | 0:c2e9b51c378c | 3 | |
| ZirkofDGJ | 0:c2e9b51c378c | 4 | TextLCD lcd(PTB2, PTB3, PTB10, PTB11, PTC11, PTC10, TextLCD::LCD16x2); // rs, e, d4-d7 |
| ZirkofDGJ | 0:c2e9b51c378c | 5 | AnalogIn V(PTC2); |
| ZirkofDGJ | 0:c2e9b51c378c | 6 | Serial PC(USBTX, USBRX); |
| ZirkofDGJ | 0:c2e9b51c378c | 7 | DigitalOut LED(PTB22); |
| ZirkofDGJ | 0:c2e9b51c378c | 8 | |
| ZirkofDGJ | 0:c2e9b51c378c | 9 | void Config_ptos(void); |
| ZirkofDGJ | 0:c2e9b51c378c | 10 | void Proceso(void); |
| ZirkofDGJ | 0:c2e9b51c378c | 11 | void Presentacion(void); |
| ZirkofDGJ | 0:c2e9b51c378c | 12 | void Lectura(void); |
| ZirkofDGJ | 0:c2e9b51c378c | 13 | |
| ZirkofDGJ | 0:c2e9b51c378c | 14 | float Vr = 3.3, Df = 0.991; |
| ZirkofDGJ | 0:c2e9b51c378c | 15 | float Vd, Vo; |
| ZirkofDGJ | 0:c2e9b51c378c | 16 | |
| ZirkofDGJ | 0:c2e9b51c378c | 17 | int main() |
| ZirkofDGJ | 0:c2e9b51c378c | 18 | { |
| ZirkofDGJ | 0:c2e9b51c378c | 19 | Config_ptos(); |
| ZirkofDGJ | 0:c2e9b51c378c | 20 | while(1) { |
| ZirkofDGJ | 0:c2e9b51c378c | 21 | Proceso(); |
| ZirkofDGJ | 0:c2e9b51c378c | 22 | } |
| ZirkofDGJ | 0:c2e9b51c378c | 23 | } |
| ZirkofDGJ | 0:c2e9b51c378c | 24 | |
| ZirkofDGJ | 0:c2e9b51c378c | 25 | void Config_ptos(void) |
| ZirkofDGJ | 0:c2e9b51c378c | 26 | { |
| ZirkofDGJ | 0:c2e9b51c378c | 27 | PC.format(8, Serial::None, 1); |
| ZirkofDGJ | 0:c2e9b51c378c | 28 | PC.baud(9600); |
| ZirkofDGJ | 0:c2e9b51c378c | 29 | LED = 1; |
| ZirkofDGJ | 0:c2e9b51c378c | 30 | } |
| ZirkofDGJ | 0:c2e9b51c378c | 31 | |
| ZirkofDGJ | 0:c2e9b51c378c | 32 | |
| ZirkofDGJ | 0:c2e9b51c378c | 33 | void Proceso(void) |
| ZirkofDGJ | 0:c2e9b51c378c | 34 | { |
| ZirkofDGJ | 0:c2e9b51c378c | 35 | //if(PC.readable()) { |
| ZirkofDGJ | 0:c2e9b51c378c | 36 | if(PC.getc()=='A') { |
| ZirkofDGJ | 0:c2e9b51c378c | 37 | LED = 1; |
| ZirkofDGJ | 0:c2e9b51c378c | 38 | } |
| ZirkofDGJ | 0:c2e9b51c378c | 39 | |
| ZirkofDGJ | 0:c2e9b51c378c | 40 | if(PC.getc()=='B') { |
| ZirkofDGJ | 0:c2e9b51c378c | 41 | LED = 0; |
| ZirkofDGJ | 0:c2e9b51c378c | 42 | } |
| ZirkofDGJ | 0:c2e9b51c378c | 43 | |
| ZirkofDGJ | 0:c2e9b51c378c | 44 | //} |
| ZirkofDGJ | 0:c2e9b51c378c | 45 | |
| ZirkofDGJ | 0:c2e9b51c378c | 46 | //if(PC.writeable()) { |
| ZirkofDGJ | 0:c2e9b51c378c | 47 | Vo = V.read(); |
| ZirkofDGJ | 0:c2e9b51c378c | 48 | Vd = Vr * Vo/ Df; |
| ZirkofDGJ | 0:c2e9b51c378c | 49 | |
| ZirkofDGJ | 0:c2e9b51c378c | 50 | lcd.locate(0,0); |
| ZirkofDGJ | 0:c2e9b51c378c | 51 | lcd.printf("V = %f V", Vd); |
| ZirkofDGJ | 0:c2e9b51c378c | 52 | |
| ZirkofDGJ | 0:c2e9b51c378c | 53 | PC.printf("V = %f V\n", Vd); |
| ZirkofDGJ | 0:c2e9b51c378c | 54 | PC.printf("\r\n"); |
| ZirkofDGJ | 0:c2e9b51c378c | 55 | |
| ZirkofDGJ | 0:c2e9b51c378c | 56 | wait_ms(500); |
| ZirkofDGJ | 0:c2e9b51c378c | 57 | lcd.cls(); |
| ZirkofDGJ | 0:c2e9b51c378c | 58 | //} |
| ZirkofDGJ | 0:c2e9b51c378c | 59 | } |