Guest
Public paste!

solarwind

By: a guest | Jan 21st, 2009 | Syntax: C | Size: 1.12 KB | Hits: 188 | Expires: Never
Copy text to clipboard
  1. #include <htc.h>
  2. #include <stdio.h>
  3.  
  4. typedef unsigned char byte;
  5.  
  6. __CONFIG(MCLRDIS & LVPDIS & FCMDIS & BORDIS & PWRTDIS & WDTDIS & UNPROTECT & IESODIS & INTIO);
  7. __CONFIG(BORV21);
  8.  
  9. #define _XTAL_FREQ 4000000
  10.  
  11. byte rx = 0x00;
  12.  
  13. void putch(unsigned char byte) {       
  14.         TXREG = byte;
  15.         while(TRMT == 0); //Wait while sending
  16. }
  17.  
  18. unsigned char getch() {
  19.         while(RCIF == 0); //Wait while receiving
  20.         return RCREG;
  21. }
  22.  
  23. void wt() {
  24.         byte b;
  25.         for(b = 0; b < 30; b++)
  26.                 __delay_ms(100);
  27. }
  28.  
  29. long int i = 0;
  30.  
  31. void main() {
  32.         //All ports are output
  33.         TRISA = 0x00;
  34.         TRISB = 0x00;
  35.         TRISC = 0b10000000; //RC7 is input for RX
  36.         TRISE = 0x00;
  37.        
  38.         //Turn off analog input
  39.         ANSEL = 0x00;
  40.         ANSELH = 0x00;
  41.        
  42.         //Disable comparators
  43.         C1ON = 0;
  44.         C2ON = 0;
  45.        
  46.         //Disable A2D
  47.         ADON = 0;
  48.        
  49.         //Disable CCP
  50.         CCP1CON = 0x00;
  51.         CCP2CON = 0x00;
  52.        
  53.         //Set up UART
  54.         SPBRG = 0x19; //9600 bps
  55.         TXSTA = 0b00100100;
  56.         RCSTA = 0b10010000;
  57.        
  58.         _delay(250);
  59.        
  60.         rx = RCREG;
  61.         rx = RCREG;
  62.         rx = RCREG;
  63.        
  64.         wt();
  65.        
  66.         while(1) {
  67.                 printf("%li Hello, world!\n", i);
  68.                 __delay_ms(100);
  69.                 i++;
  70.         }
  71.        
  72.         while(1) {
  73.                 putch(getch());
  74.         }      
  75.        
  76. }