Advertisement
Guest User

solarwind

a guest
Feb 1st, 2009
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include <p18cxxx.h>
  2. #include <stdio.h>
  3. #include <usart.h>
  4. #include <delays.h>
  5.  
  6. #pragma config OSC = INTIO67
  7. #pragma config FCMEN = OFF
  8. #pragma config IESO = OFF
  9. #pragma config PWRT = ON
  10. #pragma config BOREN = OFF
  11. #pragma config WDT = OFF
  12. #pragma config MCLRE = OFF
  13. #pragma config PBADEN = OFF
  14. #pragma config LVP = OFF
  15.  
  16.  
  17. //This will delay 1 second at 8 MHz, if you decide to change the clock frequency, you need to recalculate this function to time it right again.
  18. void delay1s() {
  19.     Delay10KTCYx(200);
  20. }
  21.  
  22. void main() {
  23.     OSCCON = 0b01110010; //8 MHz, set this to whatever frequency you want
  24.     TRISC = 0x00; //All output, but if you want the PIC to receive data, RC7 should be input.  
  25.  
  26.     //Set up the UART, all this info is in the C18 library guide pdf file.
  27.     //See this site as well: http://electronicfr.com/index.php/Microcontrolers-programing/Memo-and-code-exemples-for-C18-programing.html
  28.     OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 12);
  29.     while(1) {
  30.         printf("Hello, printf!\n");
  31.         delay1s();
  32.     }
  33.     CloseUSART();
  34.    
  35.     while(1);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement