Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.71 KB | None | 0 0
  1. // Alex Rodriguez Navas, David Marin Gutierrez, Carlos Sanson Martinez
  2.  
  3. /* Main.c file generated by New Project wizard
  4.  *
  5.  * Created:   weed dec 11 2019
  6.  * Processor: PIC18F45K22
  7.  * Compiler:  MPLAB XC8
  8.  */
  9.  
  10. #include <xc.h>
  11. #define _XTAL_FREQ 8000000
  12.  
  13. #include <string.h>
  14. #include <stdio.h>
  15. #include "config.h"
  16. #include "GLCD.h"
  17.  
  18.  // ESTRELLA: e
  19.  // TROFEO: t
  20.  // PLAYER ABAJO: s
  21.  // PLAYER ARRIBA: w
  22.  // PLAYER IZQ: a
  23.  // PLAYER DHCA: d
  24.  // BARRA IZQ LLENA: g
  25.  // BARRA INTER VACIA: h
  26.  // BARRA INTER LLENA: i
  27.  // BARRA DCHA VACIA: j
  28.  // BARRA DCHA LLENA: k
  29.  
  30. #define ROWS 7
  31. #define COLS 25
  32. char mapa[ROWS][COLS];
  33. // . <-> nada
  34. // e <-> estrella
  35. // wasd <-> player arriba, izq, abajo, dcha
  36.  
  37. int dificultad;
  38. int puntuacion;
  39. int modo_super;
  40. int recibido;
  41. struct pos {
  42.     int x;
  43.     int y;
  44. };
  45. pos jugador;
  46.  
  47. char* atoi(int num) {
  48.    char buffer[4];
  49.    sprintf(buffer, "%02d", num);
  50.    return buffer;
  51. }
  52.  
  53. void imprimir_texto(byte page, byte y, char* s) {
  54.   for(int i=0; *s!='\n' && *s!='\0'; ++i) putchGLCD(page, y+i, *(s++));
  55. }
  56.  
  57. void imprimir_hud() {
  58.    if(dificultad == 1) imprimir_texto(0, 0, "ghhj");
  59.    else if(dificultad == 2) imprimir_texto(0, 0, "gihj");
  60.    else if(dificultad == 2) imprimir_texto(0, 0, "giij");
  61.    else imprimir_texto(0, 0, "giik");
  62.    
  63.    if(modo_super) imprimir_texto(0, 4, "!");
  64.    
  65.    imprimir_texto(0, 22, "t");
  66.    imprimir_texto(0, 23, atoi(puntuacion));  
  67. }
  68.  
  69. void renderizar_mapa() {
  70.    for(int x=0; x<ROWS; ++x) {
  71.       for(int y=0; y<COLS; ++y) {
  72.      if(mapa[x][y] != '.') putchGLCD(x, y, mapa[x][y]);
  73.       }
  74.    }
  75. }
  76.  
  77. int pos_ok(pos p) {
  78.    if(p.x > 0 && p.x <= >ROWS && p.y >= 0 && p.y <= 25) return 1;
  79.    return 0;
  80. }
  81.  
  82. void mover_jugador(char dir) {
  83.    if(dir == 'w') {
  84.       if(jugador.x > 0 && jugador.x <= ROWS )
  85.    }
  86.    else if(dir == 'a') {
  87.    }
  88.    else if(dir == 's') {
  89.    }
  90.    else if(dir == 'd') {
  91.    }
  92. }
  93.  
  94. void setup(void) {
  95.      // Pins Botones
  96.      TRISA = 0xFF;   // Todos los pins del Puerto A a Input
  97.      ANSELA = 0x00;
  98.    
  99.     // Linea Serie
  100.     TXSTA1bits.BRGH = 1;    // 115200 bauds
  101.         BAUDCON1bits.BRG16 = 1;
  102.     SPBRG1 = 16;
  103.    
  104.     TXSTA1bits.SYNC = 0;    // comunicacion asincrona
  105.    
  106.     IPEN = 1;
  107.     PEIE = 1;
  108.     GIE = 1;
  109.     RC1IF = 0; // limpiar interrupt flag receiver
  110.     RC1IE = 1; // habilitar interrupt receiver
  111.    
  112.     ANSELC = 0x00; // PORTC a digital
  113.     TRISCbits.RC7 = 1; // RC7 a input
  114.    
  115.     RCSTA1bits.RX9 = 0; // 8 bit communication
  116.     RCSTA1bits.CREN = 1; // enable reception
  117.     RCSTA1bits.SPEN = 1; //start serial line
  118.    
  119.     GLCDinit();        //Inicialitzem la pantalla
  120.     clearGLCD(0,7,0,127);      //Esborrem pantalla
  121.     setStartLine(0);           //Definim linia d'inici
  122.     puntuacion = 0;
  123.     dificultad = 4;
  124.     modo_super = 0;
  125.     imprimir_hud();
  126.    
  127.     for(int x=0; x<ROWS; ++x) {
  128.        for(int y=0; y<COLS; ++y) mapa[x][y] = '.';
  129.     }
  130.     mapa[15][15] = 'e';
  131.     mapa[16][15] = 'w';
  132.  
  133.     renderizar_mapa();
  134. }
  135.  
  136. void interrupt rutina_AP(void) {
  137.    if (RC1IF && RC1IE) {
  138.       recibido = RCREG1; // Leer lo recibido
  139.       RC1IF = 0; // Clear receiver interrupt flag  
  140.    }
  141. }
  142.  
  143. int A1P = 0;
  144. int A2P = 0;
  145. int A3P = 0;
  146. int A4P = 0;
  147.  
  148. void loop(void) {
  149.    recibido = RCREG1;
  150.    
  151.    if(A1 && !A1P) {
  152.         __delay_ms(10);
  153.         if(A1) {
  154.             openChannel(FreqToCCPRx(CS));
  155.         }
  156.     }
  157.     else if(A2 && !A2P) {
  158.         __delay_ms(10);
  159.         if(A2) {
  160.             openChannel(FreqToCCPRx(D));
  161.         }
  162.     }
  163.     else if(A3 && !A3P) {
  164.         __delay_ms(10);
  165.         if(A3) {
  166.             openChannel(FreqToCCPRx(DS));
  167.         }
  168.     }
  169.     else if(A4 && !A4P) {
  170.         __delay_ms(10);
  171.         if(A4) {
  172.             openChannel(FreqToCCPRx(E));
  173.         }
  174.     }
  175.    
  176. }
  177.  
  178. void main(void) {
  179.     setup();
  180.         while(1) loop();
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement