EDF - OnePIC MCU
Preliminary v0.7.0
|
00001 00009 #include <htc.h> //PIC specific hardware 00010 #include <stdio.h> //Used for printf 00011 #include <string.h> //Used for sprintf 00012 00013 #include "bsp.h" //XTAL Frequ 00014 #include "mcp2200_uart.h" //prototypes 00015 00016 00021 void mcp2200_init(void){ 00022 MCP2200_RX_TRIS = 1; //hardware UART module requires RX/TX to be inputs 00023 MCP2200_TX_TRIS = 1; //MUST be an input 00024 00025 SPBRG = DIVIDER; 00026 SYNC = 0; 00027 BRGH = 0; 00028 BRG16 = 0; 00029 SPBRG = 51; //9600 baud 00030 RCSTA = (0x90); 00031 SPEN = 1; 00032 TXEN = 1; 00033 TX9 = 0; 00034 RCIE = 1; //enable RX interrupt 00035 } 00039 void mcp2200_prompt(void) { 00040 uint8_t data_byte; 00041 uint8_t buffer[12]; 00042 00043 printf("\rPress a key and I will echo it back:\n"); 00044 while (1) { 00045 data_byte = mcp2200_getch(); // read a response from the user 00046 printf("\rI detected [%c]", data_byte); // echo it back 00047 sprintf(buffer, "Number: %c", data_byte); 00048 //lcd_clear(); //clear the LCD 00049 //lcd_goto(0); //select first line 00050 //lcd_puts(buffer); //print to the LCD 00051 } 00052 00053 } 00054 00061 void putch(uint8_t byte) { 00062 //First check to see if currently transmitting 00063 while (!TXIF) // will be set when register is empty 00064 continue; //wait until finished sending 00065 TXREG = byte; //now send the byte 00066 00067 } 00068 00073 uint8_t mcp2200_getch(void) { 00074 //First check to see if currently receiving 00075 while (!RCIF) // set when register is not empty 00076 continue; //wait until finished receiving the byte 00077 return RCREG; //we got the byte, lets return it 00078 //if RCIE is enabled, RCIF will be set and an interrupt issued now 00079 } 00080 00085 uint8_t mcp2200_getche(void) { 00086 uint8_t c; 00087 00088 putch(c = mcp2200_getch()); //wait until a byte is received and then echo it back 00089 return c; 00090 }