[ Foro de C ]

Resumen de codigo

06-Mar-2025 22:34
Invitado (PAPAOSO)
0 Respuestas

Estoy buscando maneras de disminuir el tamaño de un código C el cual hace un semáforo de 4 vías, es decir, uno al Norte, Sur, Este y Oeste. Lo malo es que me ocupa el 68% del Pic16f84a y quiero disminuir el código sin afectar aún funcionalidad.
#include <semaforopic.h>
#define led_vn pin_a0
#define led_an pin_a1
#define led_rn pin_a2
#define led_vs pin_a3
#define led_as pin_b0
#define led_rs pin_b1
#define led_vo pin_b2
#define led_ao pin_b3
#define led_ro pin_b4
#define led_ve pin_b5
#define led_ae pin_b6
#define led_re pin_b7

void main()
{

  while(TRUE)
  {
   output_high(led_vn);
   output_low(led_an);
   output_low(led_rn);
   output_low(led_vs);
   output_low(led_as);
   output_high(led_rs);
   output_low(led_vo);
   output_low(led_ao);
   output_high(led_ro);
   output_low(led_ve);
   output_low(led_ae);
   output_high(led_re);
   delay_ms(5000);
   
   output_low(led_vn);
   output_high(led_an);
   output_low(led_rn);
   output_low(led_vs);
   output_low(led_as);
   output_high(led_rs);
   output_low(led_vo);
   output_low(led_ao);
   output_high(led_ro);
   output_low(led_ve);
   output_low(led_ae);
   output_high(led_re);
   delay_ms(1000);
   
   output_low(led_vn);
   output_low(led_an);
   output_high(led_rn);
   output_low(led_vs);
   output_low(led_as);
   output_high(led_rs);
   output_low(led_vo);
   output_low(led_ao);
   output_high(led_ro);
   output_low(led_ve);
   output_low(led_ae);
   output_high(led_re);
   delay_ms(500);
   
   output_low(led_vn);
   output_low(led_an);
   output_high(led_rn);
   output_high(led_vs);
   output_low(led_as);
   output_low(led_rs);
   output_low(led_vo);
   output_low(led_ao);
   output_high(led_ro);
   output_low(led_ve);
   output_low(led_ae);
   output_high(led_re);
   delay_ms(5000);

   output_low(led_vn);
   output_low(led_an);
   output_high(led_rn);
   output_low(led_vs);
   output_high(led_as);
   output_low(led_rs);
   output_low(led_vo);
   output_low(led_ao);
   output_high(led_ro);
   output_low(led_ve);
   output_low(led_ae);
   output_high(led_re);
   delay_ms(1000);
   
    output_low(led_vn);
   output_low(led_an);
   output_high(led_rn);
   output_low(led_vs);
   output_low(led_as);
   output_high(led_rs);
   output_low(led_vo);
   output_low(led_ao);
   output_high(led_ro);
   output_low(led_ve);
   output_low(led_ae);
   output_high(led_re);
   delay_ms(500);
   
   output_low(led_vn);
   output_low(led_an);
   output_high(led_rn);
   output_low(led_vs);
   output_low(led_as);
   output_high(led_rs);
   output_high(led_vo);
   output_low(led_ao);
   output_low(led_ro);
   output_low(led_ve);
   output_low(led_ae);
   output_high(led_re);
   delay_ms(5000);
   
   output_low(led_vn);
   output_low(led_an);
   output_high(led_rn);
   output_low(led_vs);
   output_low(led_as);
   output_high(led_rs);
   output_low(led_vo);
   output_high(led_ao);
   output_low(led_ro);
   output_low(led_ve);
   output_low(led_ae);
   output_high(led_re);
   delay_ms(1000);
   
    output_low(led_vn);
   output_low(led_an);
   output_high(led_rn);
   output_low(led_vs);
   output_low(led_as);
   output_high(led_rs);
   output_low(led_vo);
   output_low(led_ao);
   output_high(led_ro);
   output_low(led_ve);
   output_low(led_ae);
   output_high(led_re);
   delay_ms(500);
   
   output_low(led_vn);
   output_low(led_an);
   output_high(led_rn);
   output_low(led_vs);
   output_low(led_as);
   output_high(led_rs);
   output_low(led_vo);
   output_low(led_ao);
   output_high(led_ro);
   output_high(led_ve);
   output_low(led_ae);
   output_low(led_re);
   delay_ms(5000);
   
   output_low(led_vn);
   output_low(led_an);
   output_high(led_rn);
   output_low(led_vs);
   output_low(led_as);
   output_high(led_rs);
   output_low(led_vo);
   output_low(led_ao);
   output_high(led_ro);
   output_low(led_ve);
   output_high(led_ae);
   output_low(led_re);
   delay_ms(1000);
   
    output_low(led_vn);
   output_low(led_an);
   output_high(led_rn);
   output_low(led_vs);
   output_low(led_as);
   output_high(led_rs);
   output_low(led_vo);
   output_low(led_ao);
   output_high(led_ro);
   output_low(led_ve);
   output_low(led_ae);
   output_high(led_re);
   delay_ms(500);
   
  }

}




Si ya eres usuario del sistema, puedes contestar desde tu cuenta y así ganar prestigio.

Si sólo eres un visitante, puedes optar por...