/* 
 * File:   newmain.c
 * Author: drthom
 *
 * Created on April 10, 2015, 6:12 AM
 */

#include <stdio.h>
#include <stdlib.h>
// PIC12F1840 Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG1
#pragma config FOSC = INTOSC    // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF        // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON       // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#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 = ON       // 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 = OFF       // Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)

// CONFIG2
#pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON       // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = ON         // Low-Voltage Programming Enable (Low-voltage programming enabled)



/*
 * 
 */
void delayzz(void)
        {              int i, j;
                        for(i=0;i<5000;i++)
                {
                          for(j=0;j<2;j++)
                      {           /* Well its Just a Timer */            }    }   }

void putch(char c)
{
    TXREG = c;
}
void main(void) {
    unsigned char oldval;

    APFCON = 0b1001100;
    
    TRISA = 0x00;
	//TXSTA REG
	TXEN=1;
        SYNC=0;
        SPEN=1;
	BRGH=1;

	//RCSTA
	SPEN=1;
	CREN=0;	//Enable Receiver (RX)

	//BAUDCON
	BRG16=0;

    //TXSTA = 0b00100010;            // set BRGH bit in TXSTA register = 1 for High speed
//    SPBRGH = 0x00;
 //   SPBRGL = 32; // assume 4 MHz Internal Osc, setup baud rate for 9600
                // http://www.microcontrollerboard.com/pic_serial_communication.html#EnabComm
    SPBRG=32;
    
    // send a string
    while (1) {
        TXREG='H';
    //printf("Hello World\n");

    
    delayzz();
    }


    return;
}

