EDF - OnePIC MCU
v1.1.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 "OnePIC_8bit_demo_mcp2200.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 char data_byte; 00041 char 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 } 00049 00050 } 00051 00058 void putch(uint8_t byte) { 00059 //First check to see if currently transmitting 00060 while (!TXIF) // will be set when register is empty 00061 continue; //wait until finished sending 00062 TXREG = byte; //now send the byte 00063 00064 } 00065 00070 char mcp2200_getch(void) { 00071 //First check to see if currently receiving 00072 while (!RCIF) // set when register is not empty 00073 continue; //wait until finished receiving the byte 00074 return RCREG; //we got the byte, lets return it 00075 //if RCIE is enabled, RCIF will be set and an interrupt issued now 00076 } 00077 00082 char mcp2200_getche(void) { 00083 char c; 00084 00085 putch(c = mcp2200_getch()); //wait until a byte is received and then echo it back 00086 return c; 00087 }