solarwind
By: a guest | Jan 21st, 2009 | Syntax:
C | Size: 1.12 KB | Hits: 188 | Expires: Never
#include <htc.h>
#include <stdio.h>
typedef unsigned char byte;
__CONFIG(MCLRDIS & LVPDIS & FCMDIS & BORDIS & PWRTDIS & WDTDIS & UNPROTECT & IESODIS & INTIO);
__CONFIG(BORV21);
#define _XTAL_FREQ 4000000
byte rx = 0x00;
void putch(unsigned char byte) {
TXREG = byte;
while(TRMT == 0); //Wait while sending
}
unsigned char getch() {
while(RCIF == 0); //Wait while receiving
return RCREG;
}
void wt() {
byte b;
for(b = 0; b < 30; b++)
__delay_ms(100);
}
long int i = 0;
void main() {
//All ports are output
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0b10000000; //RC7 is input for RX
TRISE = 0x00;
//Turn off analog input
ANSEL = 0x00;
ANSELH = 0x00;
//Disable comparators
C1ON = 0;
C2ON = 0;
//Disable A2D
ADON = 0;
//Disable CCP
CCP1CON = 0x00;
CCP2CON = 0x00;
//Set up UART
SPBRG = 0x19; //9600 bps
TXSTA = 0b00100100;
RCSTA = 0b10010000;
_delay(250);
rx = RCREG;
rx = RCREG;
rx = RCREG;
wt();
while(1) {
printf("%li Hello, world!\n", i
);
__delay_ms(100);
i++;
}
while(1) {
putch(getch());
}
}