Advertisement
Wistaro

APP2- GEII- IUT Tarbes

Mar 28th, 2016
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.94 KB | None | 0 0
  1. /*
  2.  * File:   main.c
  3.  * Author: Chambrin
  4.  *
  5.  * Created on 21 janvier 2016, 19:18
  6.  */
  7.  
  8. //header files
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <xc.h>
  12. #include <pic18f46j50.h>
  13. #include "bitsconfig.h"
  14.  
  15. //sources files
  16. #include "Hardware.c"
  17. #include "myFunctions.c"
  18. #include "oled.c"
  19.  
  20. /* Variables globales */
  21.  
  22. short Etat = 0;
  23. short AppuitBP = 0;
  24. char secondes = '0';
  25. unsigned char heure_j1[] = "00:00";
  26. unsigned char heure_j2[] = "00:00";
  27.  
  28. void gestionBP(void);
  29. void gestionEtats(void);
  30. void gestionActions(void);
  31. void DisplayTime(void);
  32. void afficherHorloges(void);
  33. void IncrementTime(short Player);
  34.  
  35. /*****************************************
  36.  * programme principal
  37.  ****************************************/
  38. int main(void) {
  39.      
  40.    
  41.    
  42.     while(1)
  43.     {
  44.        
  45.         afficherHorloges();
  46.        
  47.        
  48.         gestionEtats();
  49.         gestionActions();
  50.        
  51.     }
  52.      
  53. }
  54.  
  55. /* Programme d'interruption non prioritaire */
  56. void interrupt low_priority low_isr (void)
  57. {  
  58.    
  59. }
  60.  
  61. /* Programme d'interruption prioritaire */
  62. void interrupt high_priority high_isr (void)
  63. {  
  64.  
  65. }
  66.  
  67.  
  68.  
  69. void gestionEtats(void){
  70.    
  71.     if(Etat == 0){
  72.        
  73.         /*Initlisation materielle: pins, oled*/
  74.         InitHardware();
  75.         TRISCbits.TRISC0=0;
  76.         LATCbits.LATC0=0;
  77.         DelayMs(500);
  78.         ResetDevice();
  79.         FillDisplay(0x00);
  80.    
  81.          /*Initilision timer: mode 16 bits, valeur à 15536 pour 1 seconde*/
  82.         T0CONbits.TMR0ON = 0; // Timer O off
  83.         T0CONbits.T08BIT = 0; // mode 8 bits
  84.         T0CONbits.T0CS = 0; // source Hl interne
  85.         T0CONbits.PSA = 0; // autorisation des prédivisions
  86.         T0CONbits.T0PS0 = 1; //
  87.         T0CONbits.T0PS1 = 1; // prédivision par 256
  88.         T0CONbits.T0PS2 = 1; //
  89.         TMR0H = 0x3C; //premier registre du timer (15536 = 0x3CB0)
  90.         TMR0L = 0xB0; //second registre du timer
  91.        
  92.         /*Initlisation terminée, état 1*/
  93.         Etat = 1;
  94.        
  95.     }
  96.    
  97.    
  98.    
  99. }
  100. void gestionBP(void){
  101.    
  102.     if(PORTDbits.RD0 == 0){
  103.        
  104.         AppuitBP = 1;
  105.     }else{
  106.        
  107.         AppuitBP = 0;;
  108.        
  109.     }
  110.        
  111.    
  112. }
  113. void gestionActions(void){
  114.    
  115.     if(Etat == 0){
  116.        
  117.         oledPutString("We are in state 0",1,1);
  118.                
  119.     }
  120.     if(Etat == 1){
  121.        
  122.        
  123.         IncrementTime(Etat); // Incrémente le compteur. Etat = 1== incrémentation du j1, Etat = 2== incrémentation du j1
  124.          
  125.                    
  126.         T0CONbits.TMR0ON = 1;
  127.        
  128.         if(INTCONbits.TMR0IF==1){
  129.            
  130.             secondes = secondes+1;
  131.             INTCONbits.TMR0IF=0;
  132.             TMR0H = 0x3C;
  133.             TMR0L = 0xB0;
  134.                    
  135.         }
  136.        
  137.        
  138.        
  139.     }
  140.    
  141. }
  142. void afficherHorloges(void){
  143.    
  144.      oledPutString("\\/ Horloge d'echec \\/",1,1);
  145.    
  146.     oledPutString(heure_j1,6,1);
  147.     oledPutString(heure_j2,6,90);
  148.    
  149.    oledPutString("<J1>",4,1);
  150.     oledPutString("<J2>",4,90);
  151.    
  152. }
  153. void IncrementTime(short Player){
  154.    
  155.   if(Player == 1){
  156.      
  157.     heure_j1[4]=secondes;
  158.    
  159.     if(heure_j1[4] == ':'){ //: est le caractère après le 9
  160.        
  161.         heure_j1[4]='0';
  162.         heure_j1[3]++; //incrementation des dizaines de secondes
  163.         secondes = '0';
  164.        
  165.     }
  166.      if(heure_j1[3] == '6'){ //: est le caractère après le 9
  167.        
  168.         heure_j1[4]='0';
  169.         heure_j1[3]='0';
  170.         heure_j1[1]++; //incrémentation des unités de minutes
  171.         secondes = '0';
  172.        
  173.     }
  174.     if(heure_j1[1] == ':'){
  175.         heure_j1[1]='0';
  176.         heure_j1[0]++; //incrémentation des dizaines de minutes
  177.         secondes = '0';
  178.        
  179.        
  180.     }
  181.     if(heure_j1[0] == ':'){ //si le compteur atteint 99:99, ce qui n'arrivera jamais, on le reset
  182.          heure_j1[4]='0';
  183.          heure_j1[3]='0';
  184.          heure_j1[0]='0';
  185.         heure_j1[1]='0';
  186.        
  187.         secondes = '0';
  188.        
  189.        
  190.     }
  191.   }
  192.  
  193.     if(Player == 2){
  194.      
  195.     heure_j2[4]=secondes;
  196.    
  197.     if(heure_j2[4] == ':'){ //: est le caractère après le 9
  198.        
  199.         heure_j2[4]='0';
  200.         heure_j2[3]++; //incrementation des dizaines de secondes
  201.         secondes = '0';
  202.        
  203.     }
  204.      if(heure_j2[3] == '6'){ //: est le caractère après le 9
  205.        
  206.         heure_j2[4]='0';
  207.         heure_j2[3]='0';
  208.         heure_j2[1]++; //incrémentation des unités de minutes
  209.         secondes = '0';
  210.        
  211.     }
  212.     if(heure_j2[1] == ':'){
  213.         heure_j2[1]='0';
  214.         heure_j2[0]++; //incrémentation des dizaines de minutes
  215.         secondes = '0';
  216.        
  217.        
  218.     }
  219.     if(heure_j2[0] == ':'){ //si le compteur atteint 99:99, ce qui n'arrivera jamais, on le reset
  220.          heure_j2[4]='0';
  221.          heure_j2[3]='0';
  222.          heure_j2[0]='0';
  223.         heure_j2[1]='0';
  224.        
  225.         secondes = '0';
  226.        
  227.        
  228.     }
  229.   }
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement