Guest User

Untitled

a guest
Jan 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.08 KB | None | 0 0
  1. #include "C:\Users\Administrat0r\Desktop\Projects\BRAD_USB_CUSTOM_BOARD\b-rad.h"
  2.  
  3. unsigned int8 LEDAddr[6];
  4.  
  5. unsigned int8 LED[8];
  6. //char EPRAM[240];
  7.  
  8.  
  9.  
  10. //C7 Is Rx
  11.  
  12. void allOff(){
  13.   output_c(0x00);
  14.    output_a(0x00);
  15. }
  16.  
  17. void allOn(){
  18.    /*int i=0;
  19.    
  20.    for(i=0; i<6; i++){
  21.       output_high(LEDAddr[i]);
  22.    }*/
  23.    
  24.    output_c(0xFF);
  25.    output_a(0xFF);
  26. }
  27.  
  28. /*void writeEPR(unsigned int8 addr, unsigned int8 data){
  29.    EPRAM[addr]=data;
  30. }
  31.  
  32. unsigned int8 writeEPR(unsigned int8 addr){
  33.    return EPRAM[addr];
  34. }*/
  35.  
  36.  
  37. void main()
  38. {
  39.    unsigned int8 PWMcounter=0;
  40.    unsigned int8 phase=0, i=0,b=0;
  41.    unsigned int16 phaseCount=0, phaseCount2=0, phaseCount3=0;
  42.    
  43.    setup_adc_ports(NO_ANALOGS|VSS_VDD);
  44.    setup_adc(ADC_OFF);
  45.    setup_spi(SPI_SS_DISABLED);
  46.    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  47.    setup_timer_1(T1_DISABLED);
  48.    setup_timer_2(T2_DISABLED,0,1);
  49.    setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
  50.    setup_oscillator(OSC_8MHZ);
  51.  
  52.    // TODO: USER CODE!!
  53.    
  54.    LEDAddr[0]=PIN_C1;
  55.    LEDAddr[1]=PIN_A2;
  56.    LEDAddr[2]=PIN_C0;
  57.    LEDAddr[3]=PIN_A3;
  58.    LEDAddr[4]=PIN_A6;
  59.    LEDAddr[5]=PIN_A4;
  60.    
  61.    set_tris_c(0b10110000);
  62.    for(i=0; i<6; i++){
  63.       LED[i]=0;
  64.    }
  65.    allOn();
  66.    while(true){
  67.    
  68.       switch(phase){
  69.          case 0:{
  70.             if(phaseCount>=3){
  71.                for(i=0; i<6; i++){
  72.                   LED[i]++;
  73.                }
  74.                phaseCount=0;
  75.                if(LED[0]>=50){
  76.                   phase++;
  77.                }
  78.             }
  79.             break;
  80.          }
  81.          case 1:{
  82.             if(phaseCount>=6){
  83.                phaseCount=0;
  84.                
  85.                if(phaseCount2==0){
  86.                   for(i=0; i<6; i++){
  87.                      LED[i]--;
  88.                   }
  89.                   if(LED[0]==30) phaseCount2++;
  90.                }
  91.                else if(phaseCount2==1){
  92.                   for(i=0; i<6; i++){
  93.                      LED[i]++;
  94.                   }
  95.                   if(LED[0]==50) {
  96.                      phaseCount3++;
  97.                      phaseCount2--;
  98.                      if(phaseCount3==7){
  99.                         phase++;
  100.                         phaseCount3=0;
  101.                         phaseCount2=0;
  102.                         phaseCount=0;
  103.                      }
  104.                   }
  105.                }
  106.                
  107.             }
  108.          
  109.             break;
  110.          }
  111.          case 2:{
  112.             if(phaseCount>=3){
  113.                for(i=0; i<6; i++){
  114.                   LED[i]--;
  115.                }
  116.                phaseCount=0;
  117.                if(LED[0]==0){
  118.                   phase++;
  119.                }
  120.             }
  121.             break;
  122.          }
  123.          case 3:{
  124.             if(phaseCount3==0){
  125.                LED[0]=15;
  126.                LED[1]=15;
  127.                LED[2]=40;
  128.                LED[3]=40;
  129.                LED[4]=15;
  130.                LED[5]=15;
  131.                phaseCount3++;
  132.             }
  133.             else{
  134.                if(phaseCount==3){
  135.                   phaseCount=0;
  136.                   b=LED[5];
  137.                   LED[5]=LED[3];
  138.                   LED[3]=LED[1];
  139.                   LED[1]=b;
  140.                  
  141.                   b=LED[4];
  142.                   LED[4]=LED[2];
  143.                   LED[2]=LED[0];
  144.                   LED[0]=b;
  145.                  
  146.                  
  147.                   phaseCount2++;
  148.                   if(phaseCount2%35==0){
  149.                      for(i=0; i<6; i++){
  150.                         if(LED[i]>30)LED[i]+=1;
  151.                      }
  152.                   }
  153.                   if(phaseCount2==200){
  154.                      phaseCount3=0;
  155.                      phaseCount2=0;
  156.                      phaseCount=0;
  157.                      phase++;
  158.                      for(i=0; i<6; i++){
  159.                         LED[i]=15;
  160.                      }
  161.                      LED[0]=50;
  162.                   }
  163.                }
  164.             }
  165.            
  166.             break;
  167.          }
  168.          
  169.          case 4:{
  170.             if(phaseCount==4){
  171.                   phaseCount=0;
  172.                   b=LED[5];
  173.                   LED[5]=LED[4];
  174.                   LED[4]=LED[3];
  175.                   LED[3]=LED[2];
  176.                   LED[2]=LED[1];
  177.                   LED[1]=LED[0];
  178.                   LED[0]=b;
  179.                  
  180.                   phaseCount2++;
  181.                  
  182.                   if(phaseCount2==300){
  183.                      phaseCount3=0;
  184.                      phaseCount2=0;
  185.                      phaseCount=0;
  186.                      phase=0;
  187.                      for(i=0; i<6; i++){
  188.                         LED[i]=0;
  189.                      }
  190.                   }
  191.                }
  192.             break;
  193.          }
  194.        
  195.            
  196.       }
  197.      
  198.       for(i=0; i<6; i++){
  199.          if(PWMcounter>=LED[i]){
  200.             output_low(LEDAddr[i]);
  201.          }
  202.       }
  203.      
  204.       PWMcounter++;
  205.       if(PWMcounter>=50){
  206.          allOn();
  207.          PWMcounter=0;
  208.          phaseCount++;
  209.          //for(i=0; i<6; i++){
  210.          //   LED[i]++;
  211.          //}
  212.       }
  213.    }
  214. }
Add Comment
Please, Sign In to add comment