Autor Tema: USE_AND_MASKS  (Leído 1714 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
USE_AND_MASKS
« en: 09 de Febrero de 2014, 18:41:02 »
Hola, he estado buscando para que se usa el #define USE_AND_MASKS sin resultado alguno, alguien podría explicarme que función cumple en este código o en cualquiera que se use.
Código: C
  1. #include <xc.h>
  2. #include "config.h"
  3. #include <plib/usart.h>
  4.  
  5. #define _XTAL_FREQ 8000000 //The speed of your internal(or)external oscillator
  6. #define USE_AND_MASKS
  7.  
  8. int i = 0;
  9. unsigned char UART1Config = 0, baud = 0;
  10. unsigned char MsgFromPIC[] = "PIC Rocks\r";
  11.  
  12. void SetupClock(void);
  13. void Delay1Second(void);
  14.  
  15. void main(int argc, char** argv) {
  16.  
  17.     SetupClock(); // Internal Clock to 8MHz
  18.  
  19.     TRISCbits.RC6 = 0; //TX pin set as output
  20.     TRISCbits.RC7 = 1; //RX pin set as input
  21.  
  22.     UART1Config = USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_BRGH_HIGH ;
  23.     baud = 51;
  24.     OpenUSART(UART1Config,baud);
  25.  
  26.    
  27.     while(1) //infinite loop
  28.     {
  29.        putsUSART(MsgFromPIC);
  30.        Delay1Second();
  31.     }
  32. }
  33.  
  34. void SetupClock()
  35. {
  36.     OSCCONbits.IRCF0 = 1;
  37.     OSCCONbits.IRCF1 = 1;
  38.     OSCCONbits.IRCF2 = 1;
  39. }
  40.  
  41. void Delay1Second()
  42. {
  43.     for(i=0;i<100;i++)
  44.     {
  45.          __delay_ms(10);
  46.     }
  47. }


Gracias.
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: USE_AND_MASKS
« Respuesta #1 en: 10 de Febrero de 2014, 18:23:31 »
Hola de nuevo, creo entender que el funcionamiento de USE_AND_MASKS es configurar los bits de una rutina en concreto
Código: C
  1. //------------AND MASK------------------------------------------------
  2. #else
  3. #define USART_TX_INT_ON         0b10000000  // Transmit interrupt on
  4. #define USART_TX_INT_OFF        0b00000000  // Transmit interrupt off
  5. #define USART_TX_INT_MASK      (~USART_TX_INT_ON)   //Mask Trnasmit Interrupt select bit
  6.  
  7. #define USART_RX_INT_ON         0b01000000  // Receive interrupt on
  8. #define USART_RX_INT_OFF        0b00000000  // Receive interrupt off
  9. #define USART_RX_INT_MASK      (~USART_RX_INT_ON)   //Mask Receive Interrupt select bit
  10.  
  11. #define USART_ADDEN_ON          0b00100000  // Enables address detection
  12. #define USART_ADDEN_OFF         0b00000000  // Disables address detection
  13. #define USART_ADDEN_MASK      (~USART_ADDEN_ON)   //Mask address detection select bit
  14.  
  15. #define USART_BRGH_HIGH         0b00010000  // High baud rate
  16. #define USART_BRGH_LOW          0b00000000  // Low baud rate
  17. #define USART_BRGH_MASK         (~USART_BRGH_HIGH)   //Mask baud rate select bit
  18.  
  19. #define USART_CONT_RX           0b00001000  // Continuous reception
  20. #define USART_SINGLE_RX         0b00000000  // Single reception
  21. #define USART_CONT_RX_MASK      (~USART_CONT_RX)    //Mask Continuous Reception select bit
  22.  
  23. #define USART_SYNC_MASTER       0b00000100  // Synchrounous master mode
  24. #define USART_SYNC_SLAVE        0b00000000  // Synchrounous slave mode
  25. #define USART_SYNC_MASK         (~USART_SYNC_MASTER)   //Mask usart mode select bit
  26.  
  27. #define USART_NINE_BIT          0b00000010  // 9-bit data
  28. #define USART_EIGHT_BIT         0b00000000  // 8-bit data
  29. #define USART_BIT_MASK          (~USART_NINE_BIT)      //Mask 9 bit transmit  select bit
  30.  
  31. #define USART_SYNCH_MODE        0b00000001  // Synchronous mode
  32. #define USART_ASYNCH_MODE       0b00000000  // Asynchronous mode
  33. #define USART_MODE_MASK         (~USART_SYNCH_MODE)    //Mask sync/async mode select bit
  34.  
  35. #endif
Pero de no usar dicho #define ¿Como quedan configurados sus registros? ¿Es mejor el uso de dicho #define? ¿Viendo los binarios como se a cual registro se refiere?
Por ejemplo #define USART_BRGH_HIGH         0b00010000  // High baud rate no coincide con el registro TXSTA

Gracias.
« Última modificación: 10 de Febrero de 2014, 18:44:46 por Miquel_S »
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re: USE_AND_MASKS
« Respuesta #2 en: 10 de Febrero de 2014, 21:38:19 »
  Yo entiendo que esas definiciones son para utilizar con la función OpenUsart y para el primer parámetro de dicha función. Todavía no utilicé nada de ello pero supondría que si no se utiliza AND_MASK  dichas definiciones se combinarían con "|"

Código: C
  1. OPENUSART(USART_TX_INT_ON | USART_RX_INT_ON | USART_EIGTH_BIT bla bla bla);

En cambio al utilizar AND_MASK la combinación habría que hacerla con "&"
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: USE_AND_MASKS
« Respuesta #3 en: 11 de Febrero de 2014, 05:12:48 »
Gracias AngelGris  por molestarte en contestar.

Saludos!
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.


 

anything