PARA IRDA
Dependents: irda irda1 Tarea5 irda ... more
Fork of Pulse by
Pulse1.cpp@1:48651f86a80c, 2013-11-07 (annotated)
- Committer:
- tony63
- Date:
- Thu Nov 07 03:34:00 2013 +0000
- Revision:
- 1:48651f86a80c
ESTE PROGRAMA SIRVE PARA LEER EL ANCHO DE PULSO EN MICROSEGUNDOS DE UNA SE?AL APLICADA A UN PUERTO DEL MODULO FRDM_KL25Z, USELO TAMBIEN PARA GENERAR ANCHOS DE PULSO POR ALGUN PIN DE SALIDA. ES POSIBLE PROGRAMAR UN TIME OUT A LA ENTRADA Y DEVOLVER -1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 1:48651f86a80c | 1 | |
tony63 | 1:48651f86a80c | 2 | #include "Pulse1.h" |
tony63 | 1:48651f86a80c | 3 | |
tony63 | 1:48651f86a80c | 4 | PulseInOut::PulseInOut(PinName pin): |
tony63 | 1:48651f86a80c | 5 | startval(0), pulsetime(), runtime(), io(pin) { |
tony63 | 1:48651f86a80c | 6 | } |
tony63 | 1:48651f86a80c | 7 | |
tony63 | 1:48651f86a80c | 8 | |
tony63 | 1:48651f86a80c | 9 | PulseInOut::~PulseInOut() { |
tony63 | 1:48651f86a80c | 10 | } |
tony63 | 1:48651f86a80c | 11 | |
tony63 | 1:48651f86a80c | 12 | void PulseInOut::write(int val) { |
tony63 | 1:48651f86a80c | 13 | io.output(); |
tony63 | 1:48651f86a80c | 14 | io = val; |
tony63 | 1:48651f86a80c | 15 | } |
tony63 | 1:48651f86a80c | 16 | |
tony63 | 1:48651f86a80c | 17 | void PulseInOut::write_us(int val, int time) { |
tony63 | 1:48651f86a80c | 18 | io.output(); |
tony63 | 1:48651f86a80c | 19 | io = val; |
tony63 | 1:48651f86a80c | 20 | wait_us(time); |
tony63 | 1:48651f86a80c | 21 | io = !val; |
tony63 | 1:48651f86a80c | 22 | } |
tony63 | 1:48651f86a80c | 23 | |
tony63 | 1:48651f86a80c | 24 | int PulseInOut::read_high_us() { |
tony63 | 1:48651f86a80c | 25 | pulsetime.reset(); |
tony63 | 1:48651f86a80c | 26 | io.input(); |
tony63 | 1:48651f86a80c | 27 | while (io == 1) { |
tony63 | 1:48651f86a80c | 28 | } |
tony63 | 1:48651f86a80c | 29 | while (io == 0) { |
tony63 | 1:48651f86a80c | 30 | } |
tony63 | 1:48651f86a80c | 31 | pulsetime.start(); |
tony63 | 1:48651f86a80c | 32 | while (io == 1) { |
tony63 | 1:48651f86a80c | 33 | } |
tony63 | 1:48651f86a80c | 34 | pulsetime.stop(); |
tony63 | 1:48651f86a80c | 35 | return pulsetime.read_us(); |
tony63 | 1:48651f86a80c | 36 | } |
tony63 | 1:48651f86a80c | 37 | |
tony63 | 1:48651f86a80c | 38 | int PulseInOut::read_high_us(int timeout) { |
tony63 | 1:48651f86a80c | 39 | runtime.reset(); |
tony63 | 1:48651f86a80c | 40 | runtime.start(); |
tony63 | 1:48651f86a80c | 41 | pulsetime.reset(); |
tony63 | 1:48651f86a80c | 42 | io.input(); |
tony63 | 1:48651f86a80c | 43 | while (io == 1) { |
tony63 | 1:48651f86a80c | 44 | if (runtime.read_us() > timeout) return -1; |
tony63 | 1:48651f86a80c | 45 | } |
tony63 | 1:48651f86a80c | 46 | while (io == 0) { |
tony63 | 1:48651f86a80c | 47 | if (runtime.read_us() > timeout) return -1; |
tony63 | 1:48651f86a80c | 48 | } |
tony63 | 1:48651f86a80c | 49 | pulsetime.start(); |
tony63 | 1:48651f86a80c | 50 | while (io == 1) { |
tony63 | 1:48651f86a80c | 51 | if (runtime.read_us() > timeout) return -1; |
tony63 | 1:48651f86a80c | 52 | } |
tony63 | 1:48651f86a80c | 53 | pulsetime.stop(); |
tony63 | 1:48651f86a80c | 54 | return pulsetime.read_us(); |
tony63 | 1:48651f86a80c | 55 | } |
tony63 | 1:48651f86a80c | 56 | |
tony63 | 1:48651f86a80c | 57 | int PulseInOut::read_low_us() { |
tony63 | 1:48651f86a80c | 58 | pulsetime.reset(); |
tony63 | 1:48651f86a80c | 59 | io.input(); |
tony63 | 1:48651f86a80c | 60 | while (io == 0) { |
tony63 | 1:48651f86a80c | 61 | } |
tony63 | 1:48651f86a80c | 62 | while (io == 1) { |
tony63 | 1:48651f86a80c | 63 | } |
tony63 | 1:48651f86a80c | 64 | pulsetime.start(); |
tony63 | 1:48651f86a80c | 65 | while (io == 0) { |
tony63 | 1:48651f86a80c | 66 | } |
tony63 | 1:48651f86a80c | 67 | pulsetime.stop(); |
tony63 | 1:48651f86a80c | 68 | return pulsetime.read_us(); |
tony63 | 1:48651f86a80c | 69 | } |
tony63 | 1:48651f86a80c | 70 | |
tony63 | 1:48651f86a80c | 71 | int PulseInOut::read_low_us(int timeout) { |
tony63 | 1:48651f86a80c | 72 | runtime.reset(); |
tony63 | 1:48651f86a80c | 73 | runtime.start(); |
tony63 | 1:48651f86a80c | 74 | pulsetime.reset(); |
tony63 | 1:48651f86a80c | 75 | io.input(); |
tony63 | 1:48651f86a80c | 76 | while (io == 0) { |
tony63 | 1:48651f86a80c | 77 | if (runtime.read_us() > timeout) return -1; |
tony63 | 1:48651f86a80c | 78 | } |
tony63 | 1:48651f86a80c | 79 | while (io == 1) { |
tony63 | 1:48651f86a80c | 80 | if (runtime.read_us() > timeout) return -1; |
tony63 | 1:48651f86a80c | 81 | } |
tony63 | 1:48651f86a80c | 82 | pulsetime.start(); |
tony63 | 1:48651f86a80c | 83 | while (io == 0) { |
tony63 | 1:48651f86a80c | 84 | if (runtime.read_us() > timeout) return -1; |
tony63 | 1:48651f86a80c | 85 | } |
tony63 | 1:48651f86a80c | 86 | pulsetime.stop(); |
tony63 | 1:48651f86a80c | 87 | return pulsetime.read_us(); |
tony63 | 1:48651f86a80c | 88 | } |
tony63 | 1:48651f86a80c | 89 | |
tony63 | 1:48651f86a80c | 90 | int PulseInOut::read_us() { |
tony63 | 1:48651f86a80c | 91 | pulsetime.reset(); |
tony63 | 1:48651f86a80c | 92 | io.input(); |
tony63 | 1:48651f86a80c | 93 | startval = io; |
tony63 | 1:48651f86a80c | 94 | while (io == startval) { |
tony63 | 1:48651f86a80c | 95 | } |
tony63 | 1:48651f86a80c | 96 | pulsetime.start(); |
tony63 | 1:48651f86a80c | 97 | while (io != startval) { |
tony63 | 1:48651f86a80c | 98 | } |
tony63 | 1:48651f86a80c | 99 | pulsetime.stop(); |
tony63 | 1:48651f86a80c | 100 | return pulsetime.read_us(); |
tony63 | 1:48651f86a80c | 101 | } |
tony63 | 1:48651f86a80c | 102 | |
tony63 | 1:48651f86a80c | 103 | int PulseInOut::read_us(int timeout) { |
tony63 | 1:48651f86a80c | 104 | runtime.reset(); |
tony63 | 1:48651f86a80c | 105 | runtime.start(); |
tony63 | 1:48651f86a80c | 106 | pulsetime.reset(); |
tony63 | 1:48651f86a80c | 107 | io.input(); |
tony63 | 1:48651f86a80c | 108 | startval = io; |
tony63 | 1:48651f86a80c | 109 | while (io == startval) { |
tony63 | 1:48651f86a80c | 110 | if (runtime.read_us() > timeout) return -1; |
tony63 | 1:48651f86a80c | 111 | } |
tony63 | 1:48651f86a80c | 112 | pulsetime.start(); |
tony63 | 1:48651f86a80c | 113 | while (io != startval) { |
tony63 | 1:48651f86a80c | 114 | if (runtime.read_us() > timeout) return -1; |
tony63 | 1:48651f86a80c | 115 | } |
tony63 | 1:48651f86a80c | 116 | pulsetime.stop(); |
tony63 | 1:48651f86a80c | 117 | return pulsetime.read_us(); |
tony63 | 1:48651f86a80c | 118 | } |