Advertisement
apollw

pong-game_hsc12

Jun 28th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.60 KB | None | 0 0
  1. /** ###################################################################
  2. **     Filename  : Events.c
  3. **     Project   : jogo_pong
  4. **     Processor : MC9S12C32CFU16
  5. **     Component : Events
  6. **     Version   : Driver 01.04
  7. **     Compiler  : CodeWarrior HC12 C Compiler
  8. **     Date/Time : 14/06/2018, 15:08
  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. ** ===================================================================
  30. **     Event       :  TI1_OnInterrupt (module Events)
  31. **
  32. **     Component   :  TI1 [TimerInt]
  33. **     Description :
  34. **         When a timer interrupt occurs this event is called (only
  35. **         when the component is enabled - <Enable> and the events are
  36. **         enabled - <EnableEvent>). This event is enabled only if a
  37. **         <interrupt service/event> is enabled.
  38. **     Parameters  : None
  39. **     Returns     : Nothing
  40. ** ===================================================================
  41. */
  42.   unsigned int a=0,b=0,c=0,d=0,somatotal=0,somatotal2=0, cont1,cont2;
  43.   unsigned int e=0,f=0,g=0,h=0;
  44.   unsigned int acionador1,acionador2, jogador1=0,jogador2=0;
  45.  
  46. void TI1_OnInterrupt(void)
  47. {
  48.   /* Write your code here ... */
  49.  
  50.  
  51.   //ACIONADOR 1
  52.  
  53.   if(!(SW2_GetVal())){
  54.    
  55.         acionador1=1;
  56.        
  57.   }
  58.  
  59.   if(acionador1==1){
  60.    
  61.  
  62.         LED04_ClrVal();
  63.        
  64.         a=a+10;
  65.         if(a>1000)
  66.        
  67.         {
  68.        
  69.         a=1500;
  70.                  
  71.         LED04_SetVal();
  72.         LED03_ClrVal();
  73.         }
  74.          
  75.                
  76.         b=b+10;
  77.         if(b>2000)
  78.         {
  79.        
  80.         b=2500;
  81.            
  82.         LED03_SetVal();
  83.         LED02_ClrVal();
  84.         }
  85.        
  86.         c=c+10;
  87.         if(c>3000)
  88.         {
  89.        
  90.         c=3500;
  91.                
  92.         LED02_SetVal();
  93.         LED01_ClrVal();
  94.         }
  95.  
  96.        
  97.         d=d+10;
  98.         if(d>4000)
  99.         {
  100.        
  101.         d=4500;
  102.         LED01_SetVal();
  103.        
  104.         }
  105.   }
  106.  
  107.      somatotal=a+b+c+d;
  108.  
  109.   if(somatotal>=12000)
  110.   {
  111.    acionador1=0;
  112.    a=0;
  113.    b=0;
  114.    c=0;
  115.    d=0;
  116.    }
  117.    
  118.  
  119. }
  120.  
  121. /*
  122. ** ===================================================================
  123. **     Event       :  TI2_OnInterrupt (module Events)
  124. **
  125. **     Component   :  TI2 [TimerInt]
  126. **     Description :
  127. **         When a timer interrupt occurs this event is called (only
  128. **         when the component is enabled - <Enable> and the events are
  129. **         enabled - <EnableEvent>). This event is enabled only if a
  130. **         <interrupt service/event> is enabled.
  131. **     Parameters  : None
  132. **     Returns     : Nothing
  133. ** ===================================================================
  134. */
  135. void TI2_OnInterrupt(void)
  136. {
  137. //ACIONADOR 2
  138.      
  139.   if(!(SW1_GetVal())){
  140.    
  141.         acionador2=1;
  142.        
  143.   }
  144.  
  145.    if(acionador2==1){
  146.    
  147.  
  148.         LED01_ClrVal();
  149.        
  150.         e=e+10;
  151.         if(e>1000)
  152.        
  153.         {
  154.        
  155.         e=1500;
  156.                  
  157.         LED01_SetVal();
  158.         LED02_ClrVal();
  159.         }
  160.          
  161.                
  162.         f=f+10;
  163.         if(f>2000)
  164.         {
  165.        
  166.         f=2500;
  167.            
  168.         LED02_SetVal();
  169.         LED03_ClrVal();
  170.         }
  171.        
  172.         g=g+10;
  173.         if(g>3000)
  174.         {
  175.        
  176.         g=3500;
  177.                
  178.         LED03_SetVal();
  179.         LED04_ClrVal();
  180.         }
  181.  
  182.        
  183.         h=h+10;
  184.         if(h>4000)
  185.         {
  186.        
  187.         h=4500;
  188.         LED04_SetVal();
  189.        
  190.         }
  191.   }
  192.  
  193.      somatotal2=e+f+g+h;
  194.  
  195.   if(somatotal2>=12000)
  196.   {
  197.    acionador2=0;
  198.    e=0;
  199.    f=0;
  200.    g=0;
  201.    h=0;
  202.   }
  203.  }
  204.  
  205.  
  206. /*
  207. ** ===================================================================
  208. **     Event       :  TI3_OnInterrupt (module Events)
  209. **
  210. **     Component   :  TI3 [TimerInt]
  211. **     Description :
  212. **         When a timer interrupt occurs this event is called (only
  213. **         when the component is enabled - <Enable> and the events are
  214. **         enabled - <EnableEvent>). This event is enabled only if a
  215. **         <interrupt service/event> is enabled.
  216. **     Parameters  : None
  217. **     Returns     : Nothing
  218. ** ===================================================================
  219. */
  220. void TI3_OnInterrupt(void)
  221. {
  222.   //CONTAGEM JOGADOR 1
  223.  
  224.  
  225.   cont1=0;
  226.  
  227.   if(acionador2==1){ //colocar accionador
  228.  
  229.   cont1=-1;
  230.  
  231.   }
  232.  
  233.   if(somatotal==12000){
  234.  
  235.   jogador1=jogador1+1+cont1;
  236.  
  237.  
  238.   }
  239.  
  240.   //CONTAGEM JOGADOR 2
  241.  
  242.   cont2=0;
  243.  
  244.   if(acionador1==1){ //colocar accionador
  245.  
  246.   cont2=-1;
  247.  
  248.   }
  249.  
  250.   if(somatotal2==12000){
  251.  
  252.   jogador2=jogador2+1+cont2;
  253.  
  254.  
  255.   }
  256.  
  257.  
  258.  
  259.   //PLACAR 1
  260.   if(jogador1==3)
  261.   {
  262.  
  263.         LED01_ClrVal();
  264.         LED02_ClrVal();
  265.         LED03_ClrVal();
  266.         LED04_ClrVal();
  267.  
  268.  
  269.  
  270.   }
  271.  
  272.    //PLACAR 2
  273.   if(jogador2==3)
  274.   {
  275.  
  276.         LED01_ClrVal();
  277.         LED02_ClrVal();
  278.         LED03_ClrVal();
  279.         LED04_ClrVal();
  280.  
  281.  
  282.  
  283.   }
  284.  
  285.  
  286.  
  287.  
  288.    
  289. }
  290.  
  291.  /* END Events */
  292.  
  293. /*
  294. ** ###################################################################
  295. **
  296. **     This file was created by Processor Expert 3.02 [04.44]
  297. **     for the Freescale HCS12 series of microcontrollers.
  298. **
  299. ** ###################################################################
  300. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement