/* * File: TX_RF.c * Author: George Panagopoulos * Processor: PIC12F1822 * * Created on 06 Nov 2016, 13:00 * * */ #include #include #include #include #include // CONFIG1 #pragma config FOSC = XT // Oscillator Selection (XT Oscillator, Crystal/resonator connected between OSC1 and OSC2 pins) #pragma config WDTE = ON // Watchdog Timer Enable (WDT enabled) #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) // 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 enable_uart(int enable) { RCSTAbits.SPEN=enable; //Serial port enabled if(enable) __delay_ms(12); //let receiver adjust its gain } void init_usart(uint16_t baud_rate) { //SPBRG switch(baud_rate) { case 1200: SPBRG=207; break; case 2400: SPBRG=103; break; case 9600: SPBRG=25; break; } TXSTAbits.SYNC =0; //Async mode RCSTAbits.SPEN=1; //Serial port enabled //TXSTA TXSTAbits.TX9=0; //8 bit transmission TXSTAbits.TXEN=1; //Transmit enable TXSTAbits.BRGH=1; //High speed baud rate } void usart_write_char(char txbyte) { while(!PIR1bits.TXIF); TXREG=txbyte; } void send_preamble() { int i; for(i=0;i<5;i++) { usart_write_char(0xf8); } usart_write_char(0xfA); } void send_start_byte() { usart_write_char('@'); } void send_stop_byte() { usart_write_char('*'); } void USARTWriteString(const char *str,int length,int repeat) { int i,k=0; for(k=0;kWDT timeout = 2.3s init_usart(1200); while(1) { enable_uart(1); USARTWriteString(tx_message,16,1); __delay_ms(100); //LET UART TRANSMISSION FINISH UP! enable_uart(0); watchdog_sleep(); //enter sleep mode until WDT timeout } return (EXIT_SUCCESS); }