Alyson Castiblanco
/
Nucleo_pwm
:3
NewCalc.cpp@0:2792fd1649c8, 2018-08-17 (annotated)
- Committer:
- acastiblancoc
- Date:
- Fri Aug 17 12:46:01 2018 +0000
- Revision:
- 0:2792fd1649c8
:3 (>^w^)>
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
acastiblancoc | 0:2792fd1649c8 | 1 | #include "mbed.h" |
acastiblancoc | 0:2792fd1649c8 | 2 | #define DEBUG 1 |
acastiblancoc | 0:2792fd1649c8 | 3 | Serial pc(SERIAL_TX,SERIAL_RX); |
acastiblancoc | 0:2792fd1649c8 | 4 | int op1, op2, tp, r; |
acastiblancoc | 0:2792fd1649c8 | 5 | void f_p(int n) |
acastiblancoc | 0:2792fd1649c8 | 6 | { |
acastiblancoc | 0:2792fd1649c8 | 7 | int c=n/100; |
acastiblancoc | 0:2792fd1649c8 | 8 | int d=(n-(c*100))/10; |
acastiblancoc | 0:2792fd1649c8 | 9 | int u=(n-(c*100)-(d*10)); |
acastiblancoc | 0:2792fd1649c8 | 10 | pc.putc(c+0x30); |
acastiblancoc | 0:2792fd1649c8 | 11 | pc.putc(d+0x30); |
acastiblancoc | 0:2792fd1649c8 | 12 | pc.putc(u+0x30); |
acastiblancoc | 0:2792fd1649c8 | 13 | } |
acastiblancoc | 0:2792fd1649c8 | 14 | void debugm(int s) |
acastiblancoc | 0:2792fd1649c8 | 15 | { |
acastiblancoc | 0:2792fd1649c8 | 16 | #if DEBUG |
acastiblancoc | 0:2792fd1649c8 | 17 | pc.printf("\n%d%",s); |
acastiblancoc | 0:2792fd1649c8 | 18 | #endif |
acastiblancoc | 0:2792fd1649c8 | 19 | } |
acastiblancoc | 0:2792fd1649c8 | 20 | |
acastiblancoc | 0:2792fd1649c8 | 21 | main() |
acastiblancoc | 0:2792fd1649c8 | 22 | { |
acastiblancoc | 0:2792fd1649c8 | 23 | while(1) |
acastiblancoc | 0:2792fd1649c8 | 24 | { |
acastiblancoc | 0:2792fd1649c8 | 25 | op1=pc.getc(); |
acastiblancoc | 0:2792fd1649c8 | 26 | pc.printf("\nIngrese el primero operador"); |
acastiblancoc | 0:2792fd1649c8 | 27 | debugm(op1); |
acastiblancoc | 0:2792fd1649c8 | 28 | |
acastiblancoc | 0:2792fd1649c8 | 29 | op2=pc.getc(); |
acastiblancoc | 0:2792fd1649c8 | 30 | pc.printf("\nIngrese el segundo operador"); |
acastiblancoc | 0:2792fd1649c8 | 31 | debugm(op2); |
acastiblancoc | 0:2792fd1649c8 | 32 | |
acastiblancoc | 0:2792fd1649c8 | 33 | tp=pc.getc(); |
acastiblancoc | 0:2792fd1649c8 | 34 | pc.printf("\nIngrese el numero de la operacion"); |
acastiblancoc | 0:2792fd1649c8 | 35 | debugm(tp); |
acastiblancoc | 0:2792fd1649c8 | 36 | |
acastiblancoc | 0:2792fd1649c8 | 37 | switch(tp) |
acastiblancoc | 0:2792fd1649c8 | 38 | { |
acastiblancoc | 0:2792fd1649c8 | 39 | case 1: |
acastiblancoc | 0:2792fd1649c8 | 40 | r=op1*op2; |
acastiblancoc | 0:2792fd1649c8 | 41 | break; |
acastiblancoc | 0:2792fd1649c8 | 42 | |
acastiblancoc | 0:2792fd1649c8 | 43 | case 2: |
acastiblancoc | 0:2792fd1649c8 | 44 | r=op1/op2; |
acastiblancoc | 0:2792fd1649c8 | 45 | break; |
acastiblancoc | 0:2792fd1649c8 | 46 | |
acastiblancoc | 0:2792fd1649c8 | 47 | case 3: |
acastiblancoc | 0:2792fd1649c8 | 48 | r=op1+op2; |
acastiblancoc | 0:2792fd1649c8 | 49 | break; |
acastiblancoc | 0:2792fd1649c8 | 50 | |
acastiblancoc | 0:2792fd1649c8 | 51 | case 4: |
acastiblancoc | 0:2792fd1649c8 | 52 | r=op1-op2; |
acastiblancoc | 0:2792fd1649c8 | 53 | break; |
acastiblancoc | 0:2792fd1649c8 | 54 | } |
acastiblancoc | 0:2792fd1649c8 | 55 | //f_p(r); |
acastiblancoc | 0:2792fd1649c8 | 56 | pc.printf("\nEl resultado es.. "); |
acastiblancoc | 0:2792fd1649c8 | 57 | debugm(r); |
acastiblancoc | 0:2792fd1649c8 | 58 | } |
acastiblancoc | 0:2792fd1649c8 | 59 | } |