Advertisement
Electgpl

PIC - Cartel Futbol Entra Sale

Jun 19th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.81 KB | None | 0 0
  1. #include <16F628A.h>
  2. #FUSES NOWDT                    //No Watch Dog Timer
  3. #FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
  4. #FUSES NOPUT                    //No Power Up Timer
  5. #FUSES NOPROTECT                //Code not protected from reading
  6. #FUSES NOBROWNOUT               //No brownout reset
  7. #FUSES MCLR                     //Master Clear pin enabled
  8. #FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
  9. #FUSES NOCPD                    //No EE protection
  10. #use delay(int=4000000)
  11. #int_timer0
  12. void timer0_mux(int8 minD, int8 minU, int8 segD, int8 segU){
  13.    output_a(0b00001110);
  14.    output_b(minD);
  15.    delay_ms(10);
  16.    output_a(0b00001101);
  17.    output_b(minU);
  18.    delay_ms(10);
  19.    output_a(0b00001011);
  20.    output_b(segD);
  21.    delay_ms(10);
  22.    output_a(0b00000111);
  23.    output_b(segU);
  24.    delay_ms(10);  
  25.    set_timer0(0);
  26. }
  27. void main(){
  28.    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
  29.    set_timer0(0);
  30.    enable_interrupts(INT_TIMER0);
  31.    enable_interrupts(GLOBAL);
  32.    int cuentaRojo,
  33.        decenasRojo,
  34.        unidadesRojo,
  35.        cuentaVerde,
  36.        decenasVerde,
  37.        unidadesVerde;
  38.    timer0_mux(10,10,10,10);    
  39.    while(TRUE){    
  40.       if(input(PIN_B4)==1){
  41.          delay_ms(50);
  42.          if(input(PIN_B4)==1)
  43.             if(cuentaVerde<100)
  44.                cuentaVerde++;
  45.             else
  46.                cuentaVerde=0;
  47.       }  
  48.       if(input(PIN_B5)==1){
  49.          delay_ms(50);
  50.          if(input(PIN_B5)==1)
  51.             if(cuentaVerde<1)
  52.                cuentaVerde=0;
  53.             else
  54.                cuentaVerde--;
  55.       }  
  56.       decenasVerde=cuentaVerde/10;
  57.       unidadesVerde=cuentaVerde%10;
  58.       if(decenasVerde==0 && unidadesVerde==0){
  59.          decenasVerde=10;
  60.          unidadesVerde=10;
  61.       }
  62.       if(decenasVerde>9){
  63.          decenasVerde=10;
  64.          unidadesVerde=10;
  65.       }      
  66.       if(decenasVerde==0)
  67.          decenasVerde=10;
  68.       timer0_mux(decenasRojo,unidadesRojo,decenasVerde,unidadesVerde);
  69.       if(input(PIN_B6)==1){
  70.          delay_ms(50);
  71.          if(input(PIN_B6)==1)
  72.             if(cuentaRojo<100)
  73.                cuentaRojo++;
  74.             else
  75.                cuentaRojo=0;
  76.       }  
  77.       if(input(PIN_B7)==1){
  78.          delay_ms(50);
  79.          if(input(PIN_B7)==1)
  80.             if(cuentaRojo<1)
  81.                cuentaRojo=0;
  82.             else
  83.                cuentaRojo--;
  84.       }  
  85.       decenasRojo=cuentaRojo/10;
  86.       unidadesRojo=cuentaRojo%10;
  87.       if(decenasRojo==0 && unidadesRojo==0){
  88.          decenasRojo=10;
  89.          unidadesRojo=10;
  90.       }
  91.       if(decenasRojo>9){
  92.          decenasRojo=10;
  93.          unidadesRojo=10;
  94.       }
  95.       if(decenasRojo==0)
  96.          decenasRojo=10;
  97.       timer0_mux(decenasRojo,unidadesRojo,decenasVerde,unidadesVerde);      
  98.    }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement