ferney alberto beltran molina
/
01-03EjercicioMemoriaArray
ejemplo de memoria
Revision 0:abf0c8974408, committed 2018-03-08
- Comitter:
- fabeltranm
- Date:
- Thu Mar 08 00:59:59 2018 +0000
- Commit message:
- ejemplo
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 08 00:59:59 2018 +0000 @@ -0,0 +1,52 @@ +#include "mbed.h" + +#define MEM_SIZE 10 +#define MEM_TYPE uint8_t +int mem_head = 0; +int mem_tail = 0; +uint8_t full = 0; + +MEM_TYPE buffer[MEM_SIZE]; +Serial command(USBTX, USBRX); + +uint32_t mem_free() +{ + mem_head=0; + full=0; +} + +uint8_t mem_put(MEM_TYPE data) +{ + + if (full) + return 1; + buffer[mem_head] = data; + mem_head += 1; + if (mem_head == MEM_SIZE) + full =1; + return 0; +} +uint8_t mem_get(MEM_TYPE* data) +{ + if (mem_head == 0) + return 1; + if (mem_head == mem_tail) + return 1; + + + *data = buffer[mem_tail]; + mem_tail += 1; + + return 0; +} + +int main(){ + + mem_put(command.getc()); + mem_put(command.getc()); + mem_put(command.getc()); + mem_put(command.getc()); + MEM_TYPE val; + mem_get(&val); + command.putc(val); + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Mar 08 00:59:59 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/aa5281ff4a02 \ No newline at end of file