TP01-SE2018-PUNTO2
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 #define TIME 0.001 //en segundos, cada cuanto se hace la interrupcion (1ms) 00004 #define ENCENDIDO 1 00005 #define APAGADO 0 00006 #define APRETADO 1 00007 #define NO_APRETADO 0 00008 00009 typedef unsigned char BYTE; 00010 00011 enum{ESTADO_BAJO, ESTADO_ALTO}; 00012 00013 /* -----clases----- */ 00014 PwmOut CLOCK(PTC8); 00015 PwmOut DATA(PTA5); 00016 DigitalOut OUT(PTA4); 00017 Serial pc(USBTX, USBRX); 00018 00019 /* -----prototipos funciones----- */ 00020 void init_mcu(void); 00021 BYTE COD_Step(); 00022 00023 /* -----variables globales----- */ 00024 BYTE COD_estado; 00025 00026 int main() { 00027 init_mcu(); 00028 CLOCK.period_ms(10); 00029 CLOCK.pulsewidth_ms(5); 00030 pc.printf("CLOCK: pwm set to %.2f %%\n", CLOCK.read() * 100); 00031 DATA.period_ms(10); 00032 DATA.pulsewidth_ms(8); 00033 pc.printf("DATA: pwm set to %.2f %%\n", DATA.read() * 100); 00034 while(1) { 00035 pc.printf("SALIDA: %d\n", COD_Step()); 00036 } 00037 } 00038 00039 BYTE COD_Step(){ 00040 switch(COD_estado){ 00041 default: 00042 case ESTADO_BAJO: 00043 OUT = APAGADO; 00044 if(DATA == CLOCK){ 00045 COD_estado = ESTADO_ALTO; 00046 } 00047 break; 00048 case ESTADO_ALTO: 00049 OUT = ENCENDIDO; 00050 if(DATA != CLOCK){ 00051 COD_estado = ESTADO_BAJO; 00052 } 00053 break; 00054 } 00055 return COD_estado; 00056 } 00057 00058 void init_mcu(void){ 00059 COD_estado = ESTADO_BAJO; 00060 pc.printf("PROGRAMA INICIALIZADO\n"); 00061 }
Generated on Tue Jul 12 2022 22:07:21 by
1.7.2