Advertisement
RuiViana

CL modificado

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