/* * File: TX_RF.c * Author: George Panagopoulos * Processor: PIC12F1822 * * Created on 25 May 2014, 11:15 * * */ #include #include #include #include // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. // CONFIG1 #pragma config FOSC = XT // Oscillator Selection (XT Oscillator, Crystal/resonator connected between OSC1 and OSC2 pins) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = ON // Power-up Timer Enable (PWRT enabled) #pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input) #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) #pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled) #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset enabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) //#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled) //#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config PLLEN = OFF // PLL Enable (4x PLL disabled) #pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will not cause a Reset) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming) #define _XTAL_FREQ 4000000 //4MHZ external oscillator used in _delay() void USARTWriteString(const char *,int); void USARTWriteChar(char); void USART_Init(uint16_t baud_rate); void USART_Init(uint16_t baud_rate) { //SPBRG switch(baud_rate) { case 1200: SPBRG=207; break; case 2400: SPBRG=103; break; case 9600: SPBRG=25; break; } //TXSTA TXSTAbits.TX9=0; //8 bit transmission TXSTAbits.TXEN=1; //Transmit enable TXSTAbits.SYNC=0; //Async mode TXSTAbits.BRGH=1; //High speed baud rate //RCSTA RCSTAbits.SPEN=1; //Serial port enabled RCSTAbits.RX9=0; //8 bit mode } void USARTWriteChar(char ch) { while(!PIR1bits.TXIF); TXREG=ch; } void USARTWriteString(const char *str,int length) { int cnt=0; for(cnt=0;cnt