int tics, cant_bits; int salida; int act; int buffer[8]; void main() { for (act = 0; act ++; act < 8) { buffer[act] = 0 ; } act = 0; tics = 0; cant_bits=0; enable(); while(TRUE) {}; } void interrupt timer() { //Si PULSO está en 1 aumento tics if( out(PULSO) & 0x01 == 0x01) then { if (tics < 50) then tics = tics + 1; } } //end timer() void interrupt flanco() { if (tics == 50) then { buffer[act] = 1; act = (act + 1) % 8; cant_bits= cantbits + 1;} if (tics == 30) then { buffer[act] = 0; act = (act + 1) % 8; cant_bits= cantbits + 1;} if (tics < 30) then { // proceso buffer salida = 0; if cant_bits <= 8 then j=0 else j = act; for ( i = 1, i = i*2 , i <= 128) do { salida = salida + i* buffer[j]; j = (j + 1) % 8; } // escribo salida en SALIDA OUT(SALIDA, salida); // Limpio el buffer for (act=0 , act ++, act < 8) {buffer[act]= 0} act = 0; cant_bits=0; } //end if(tics<30) tics = 0; } //end flanco()