[ Foro de C ]
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);
}
}
hola
no se si es lo que quieres, prueba a ver que tal te va.
lo que he hecho es unir los leds en una palabra de 16 bits, lo
mismo he hecho con los bits que quieres asignar a estos leds
creando un array con estas secuencias
así trabajo con palabras y arrays que es más rápido y sencillo.
por otro lado el indice de la secuencia y el de la espera son
cíclicos, por lo que cuando lleguen al final volverán a empezar
código: https://onlinegdb.com/80DI739-Z
espero que esto te ahorre el espació que necesitabas.
saludos ;)