Advertisement
apollw

sistema_carro_freio_acc

Jul 12th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.21 KB | None | 0 0
  1. /** ###################################################################
  2. **     Filename  : Events.c
  3. **     Project   : Project_9
  4. **     Processor : MC9S12C128CFU16
  5. **     Component : Events
  6. **     Version   : Driver 01.04
  7. **     Compiler  : CodeWarrior HC12 C Compiler
  8. **     Date/Time : 12/07/2018, 15:09
  9. **     Abstract  :
  10. **         This is user's event module.
  11. **         Put your event handler code here.
  12. **     Settings  :
  13. **     Contents  :
  14. **         No public methods
  15. **
  16. ** ###################################################################*/
  17. /* MODULE Events */
  18.  
  19.  
  20. #include "Cpu.h"
  21. #include "Events.h"
  22.  
  23. /* User includes (#include below this line is not maintained by Processor Expert) */
  24.  
  25. #pragma CODE_SEG DEFAULT
  26.  
  27. /*
  28. ** ===================================================================
  29. **     Event       :  AD1_OnEnd (module Events)
  30. **
  31. **     Component   :  AD1 [ADC]
  32. **     Description :
  33. **         This event is called after the measurement (which consists
  34. **         of <1 or more conversions>) is/are finished.
  35. **         The event is available only when the <Interrupt
  36. **         service/event> property is enabled.
  37. **     Parameters  : None
  38. **     Returns     : Nothing
  39. ** ===================================================================
  40. */
  41.  
  42. unsigned int d=0,aux,aux1,acc=0,fr=0,acionador,acionador2; //aux global de comparação
  43.  
  44. void AD1_OnEnd(void)
  45. {
  46.   /* Write your code here ... */
  47.  
  48.  unsigned int i;
  49.  
  50.  aux=aux1;
  51.  
  52.  AD1_GetChanValue16(0x00,&aux1);
  53.  
  54.  
  55.  if(d>10000)
  56.  {
  57.     LED1_SetVal();
  58.     LED2_SetVal();
  59.     LED3_SetVal();
  60.  }
  61.  
  62.  if(d>8000&&d<10000)
  63.  {
  64.     LED1_ClrVal();
  65.     LED2_SetVal();
  66.     LED3_SetVal();
  67.  
  68.  }
  69.  if(d>6000&&d<8000)
  70.  {
  71.     LED1_ClrVal();
  72.     LED2_ClrVal();
  73.     LED3_SetVal();
  74.  }
  75.  if(d<6000)
  76.  {
  77.     LED1_ClrVal();
  78.     LED2_ClrVal();
  79.     LED3_ClrVal();
  80.  }
  81.  
  82.  
  83.  if(aux1<6000)
  84.     aux1=5500;
  85.  
  86.  if(aux1>10000)
  87.     aux1=11500;
  88.  
  89.   d = acc + aux1 - fr;
  90.  
  91.  
  92.   //**********SENSOR DE APROXIMAÇÃO************
  93. for(i=0;i<1000;i++){
  94.  
  95.   if(aux>aux1)
  96.    LED4_ClrVal();
  97.   else
  98.    LED4_SetVal();
  99. }
  100.  
  101.  
  102.  
  103.  
  104. }
  105.  
  106. /*
  107. ** ===================================================================
  108. **     Event       :  TI1_OnInterrupt (module Events)
  109. **
  110. **     Component   :  TI1 [TimerInt]
  111. **     Description :
  112. **         When a timer interrupt occurs this event is called (only
  113. **         when the component is enabled - <Enable> and the events are
  114. **         enabled - <EnableEvent>). This event is enabled only if a
  115. **         <interrupt service/event> is enabled.
  116. **     Parameters  : None
  117. **     Returns     : Nothing
  118. ** ===================================================================
  119. */
  120. void TI1_OnInterrupt(void)
  121. {
  122.   /* Write your code here ... */
  123.   if(!(ACELERADOR_GetVal()))
  124.  {
  125.  
  126.    acionador=1;
  127.    acc=acc+100;
  128.    
  129.    if(acc>5500)
  130.       acc=5500;
  131.    
  132.  } else{
  133.  
  134.     acionador=0;
  135.  
  136.  }
  137.  
  138.  if((acc<5500&&acc>0||acc==5500)&&acionador==0)
  139.  {
  140.    acc=acc-100;
  141.  
  142.  }
  143.  
  144.   if(acc<0)
  145.   acc=0;
  146.  
  147. }
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. /*
  155. ** ===================================================================
  156. **     Event       :  TI2_OnInterrupt (module Events)
  157. **
  158. **     Component   :  TI2 [TimerInt]
  159. **     Description :
  160. **         When a timer interrupt occurs this event is called (only
  161. **         when the component is enabled - <Enable> and the events are
  162. **         enabled - <EnableEvent>). This event is enabled only if a
  163. **         <interrupt service/event> is enabled.
  164. **     Parameters  : None
  165. **     Returns     : Nothing
  166. ** ===================================================================
  167. */
  168. void TI2_OnInterrupt(void)
  169. {
  170.   /* Write your code here ... */
  171.  
  172.    if(!(FREIO_GetVal()))
  173.  {
  174.  
  175.    acionador2=1;
  176.    fr=fr+100;
  177.    
  178.    if(fr>5500)
  179.       fr=6000;
  180.    
  181.  } else{
  182.  
  183.     acionador2=0;
  184.  
  185.  }
  186.  
  187.  if((fr<6000&&fr>0||fr==6000)&&acionador2==0)
  188.  {
  189.    fr=fr-100;
  190.  
  191.  }
  192.  
  193.   if(fr<0)
  194.   fr=0;
  195.  
  196.  
  197.  
  198.  
  199.  
  200. }
  201.  
  202. /* END Events */
  203.  
  204. /*
  205. ** ###################################################################
  206. **
  207. **     This file was created by Processor Expert 3.02 [04.44]
  208. **     for the Freescale HCS12 series of microcontrollers.
  209. **
  210. ** ###################################################################
  211. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement