Advertisement
RuiViana

LEDS CL PIC12F675

Aug 15th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. #include <12F675.h>
  2. #device adc=10
  3.  
  4. #FUSES NOWDT //No Watch Dog Timer
  5. #FUSES INTRC_IO //Internal RC Osc
  6. #FUSES NOCPD //No EE protection
  7. #FUSES PROTECT //Code not protected from reading
  8. #FUSES NOMCLR //Master Clear pin enabled
  9. #FUSES NOPUT //No Power Up Timer
  10. #FUSES NOCPD
  11. #FUSES NOBROWNOUT
  12. #use delay(clock=20000000)
  13. #use fast_io (a)
  14.  
  15. #define GP1 pin_a1
  16. #define GP4 pin_a2
  17.  
  18.  
  19. int adc;
  20. unsigned int16 valor;
  21. unsigned int16 valor1;
  22. unsigned int16 valor2;
  23. int ciclos = 0;
  24. int ciclos2 = 0;
  25. const int y [7] ={0,1,1,1,1,1,1};
  26. const int x [7] ={0,1,0,1,1,1,1};
  27. const int y2 [21] ={0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
  28. const int x2 [21] ={0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
  29. static int estado_atual = 0;
  30. static int estado_atual2 = 0;
  31. #int_TIMER1
  32.  
  33. //----------------------------------------
  34. //void TIMER1_isr(void)
  35. void teste(void)
  36. {
  37. int ajuste = 35;
  38.  
  39. //clear_interrupt(INT_TIMER1);
  40.  
  41. if ( ++ ciclos > ajuste){ ciclos = 0;}
  42. if ( ++ ciclos2 > ajuste ){ ciclos2 = 0;}
  43.  
  44. //**************GERA PULSOS DUPLOS NO FIM DO CICLO*************************
  45. if ( ciclos == ajuste )
  46. {
  47. if ( x [ estado_atual++ ] )
  48. {
  49. output_high(GP1);
  50. }
  51. else
  52. {
  53. output_low(GP1 );
  54. }
  55. if ( estado_atual >=7 )
  56. {
  57. estado_atual = 0;
  58. }
  59.  
  60. }
  61. //**************** // GERA OS PULSOS AMARELO SIMPLES //************************
  62. else
  63. {
  64. if ( y [ estado_atual++ ] )
  65. {
  66. output_high(GP1);
  67. }
  68. else
  69. {
  70. output_low(GP1) ;
  71. }
  72. if ( estado_atual >=7 )
  73. {
  74. estado_atual = 0;
  75. }
  76. }
  77. //**************GERA PULSOS DUPLOS AZUL *************************
  78. if ((ciclos2 == 6) )
  79. {
  80. if ( x2 [ estado_atual2++ ] )
  81. {
  82. output_high(GP4);
  83. }
  84. else
  85. {
  86. output_low(GP4);
  87. }
  88. if ( estado_atual2 >=21 )
  89. {
  90. estado_atual2 = 0;
  91. }
  92. }
  93. //********************GERA PULSOS SIMPLES AZUL **********************
  94. else
  95. {
  96. if ( y2 [ estado_atual2++ ] )
  97. {
  98. output_high(GP4);
  99. }
  100. else
  101. {
  102. output_low(GP4) ;
  103. }
  104. if ( estado_atual2 >=21 )
  105. {
  106. estado_atual2 = 0;
  107. }
  108. }
  109. // set_timer1 (65534); // 65565=365us ideal 35us// ideal 3.15ms
  110. }
  111.  
  112. //----------------------------------------
  113.  
  114. void main()
  115. {
  116. set_tris_a( 0 );
  117. output_low(GP1);
  118. output_low(GP4);
  119. setup_adc_ports(sAN0|VSS_VDD);
  120. setup_adc(ADC_CLOCK_INTERNAL);
  121. setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  122. setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
  123. setup_comparator(NC_NC);
  124. setup_vref(FALSE);
  125. // enable_interrupts(INT_TIMER1);
  126. // enable_interrupts(GLOBAL);
  127.  
  128.  
  129. while ( TRUE )
  130. {
  131. set_adc_channel (0); //Inicia o canal 0
  132. delay_us (5); //espera ele ler o sinal
  133. adc = read_adc();
  134.  
  135. valor = adc ;
  136. valor1=valor ;
  137. valor2 = valor1*255 ;
  138. teste();
  139.  
  140. }
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement