Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. #define _XTAL_FREQ 8000000 //The speed of your internal(or)external oscillator
  2. #include <p18cxxx.h>
  3. #include <usart.h>
  4. int i = 0;
  5.  
  6. // CONFIG1L
  7. #pragma config WDTEN = OFF // Watchdog Timer (Disabled - Controlled by SWDTEN bit)
  8. #pragma config PLLDIV =3 // PLL Prescaler Selection bits - Divide by 3 (12 MHz oscillator input)
  9. #pragma config STVREN = ON // Stack Overflow/Underflow Reset (Enabled)
  10. #pragma config XINST = OFF // Extended instruction set disabled
  11.  
  12. // CONFIG1H
  13. #pragma config CPUDIV = OSC1 // CPU System Clock Postscaler (No CPU system clock divide)
  14. #pragma config CP0 = OFF // Code Protect (Program memory is not code-protected)
  15.  
  16. // CONFIG2L
  17. #pragma config OSC = HSPLL //HS oscillator, PLL enabled, HSPLL used by USB
  18. #pragma config T1DIG = ON // T1OSCEN Enforcement (Secondary Oscillator clock source may be selected)
  19. #pragma config LPT1OSC = OFF // Low-Power Timer1 Oscillator (High-power operation)
  20. #pragma config FCMEN = OFF //Fail-Safe Clock Monitor disabled
  21. #pragma config IESO = OFF //Two-Speed Start-up disabled
  22.  
  23. // CONFIG2H
  24. #pragma config WDTPS = 32768 // Watchdog Postscaler (1:32768)
  25.  
  26. // CONFIG3L
  27. #pragma config DSWDTOSC = INTOSCREF // DSWDT Clock Select (DSWDT uses INTRC)
  28. #pragma config RTCOSC = T1OSCREF // RTCC Clock Select (RTCC uses T1OSC/T1CKI)
  29. #pragma config DSBOREN = OFF // Zero-Power BOR disabled in Deep Sleep
  30. #pragma config DSWDTEN = OFF // Deep Sleep Watchdog Timer (Disabled)
  31. #pragma config DSWDTPS = 8192 //1:8,192 (8.5 seconds)
  32.  
  33. // CONFIG3H
  34. #pragma config IOL1WAY =OFF //IOLOCK bit can be set and cleared
  35. #pragma config MSSP7B_EN = MSK7 // MSSP address masking (7 Bit address masking mode)
  36.  
  37. // CONFIG4L
  38. #pragma config WPFP = PAGE_1 // Write/Erase Protect Page Start/End Location (Write Protect Program Flash Page 0)
  39. #pragma config WPEND = PAGE_0 //Start protection at page 0
  40. #pragma config WPCFG = OFF //Write/Erase last page protect Disabled
  41.  
  42. // CONFIG4H
  43. #pragma config WPDIS = OFF //WPFP[5:0], WPEND, and WPCFG bits ignored
  44.  
  45. #define USE_AND_MASKS
  46.  
  47. unsigned char Txdata[] = "MICROCHIP_USART";
  48. void Delay1Second(void);
  49.  
  50. void main (void)
  51. {
  52. unsigned char spbrg=0,baudconfig=0,i=0;
  53.  
  54. // REMAPE ID PORT
  55.  
  56. PPSCON = 0x00; // unlock peripheral Pin select register
  57. RPOR19 = 0x05; // assign USART2 TX to RP19/RD2
  58. RPINR16 = 0x14; // assign USART2 RX to RP20/RD3
  59. PPSCON = 0x01; // lock peripheral Pin select register
  60.  
  61. TRISDbits.TRISD2 = 0; // TX2 output
  62. TRISDbits.TRISD3 = 1; // RX2 input
  63. //------USART Setup ----
  64.  
  65. Close2USART(); //turn off usart if was previously on
  66.  
  67. spbrg = 51;
  68.  
  69. Open2USART(USART_TX_INT_OFF &
  70. USART_RX_INT_OFF &
  71. USART_ASYNCH_MODE &
  72. USART_EIGHT_BIT &
  73. USART_CONT_RX &
  74. USART_BRGH_HIGH, spbrg);
  75.  
  76. baudconfig = BAUD_8_BIT_RATE & BAUD_AUTO_OFF;
  77. baud2USART (baudconfig);
  78.  
  79. PORTB = 0x03;
  80.  
  81. while(1){
  82.  
  83. //------USART Transmission ----
  84. while(Busy2USART()); //Check if Usart is busy or not
  85. puts2USART((char *)Txdata); //transmit the string
  86. Delay1Second();
  87. Close2USART();
  88. }
  89. }
  90.  
  91. void Delay1Second()
  92. {
  93. for(i=0;i<100;i++)
  94. {
  95. __delay_ms(10);
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement