aboutsummaryrefslogtreecommitdiffstats
path: root/uart.c
diff options
context:
space:
mode:
authorWilliam Harrington <kb0iic@berzerkula.org>2019-07-27 22:16:27 -0500
committerWilliam Harrington <kb0iic@berzerkula.org>2019-07-27 22:16:27 -0500
commite6bffe23c87a9f6de8abdec747600f674b9cab62 (patch)
tree1da4dc68a918f969f3354f1d70c2aa58b588fabd /uart.c
parent1dd364ccc6fb4447d89cbc965655b895def8e97b (diff)
Copy project files into repo
Diffstat (limited to 'uart.c')
-rwxr-xr-xuart.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/uart.c b/uart.c
new file mode 100755
index 0000000..5670530
--- /dev/null
+++ b/uart.c
@@ -0,0 +1,70 @@
+//***Initializing UART module for PIC16F887***//
+
+#include "uart.h"
+#include "conf.h"
+
+void Initialize_UART(void) {
+ //****Setting I/O pins for UART****//
+ TRISC6 = 0; // TX Pin set as output
+ TRISC7 = 1; // RX Pin set as input
+ //________I/O pins set __________//
+
+ /**Initialize SPBRG register for required
+ baud rate and set BRGH for fast baud_rate**/
+ SPBRG = ((_XTAL_FREQ / 16) / Baud_rate) - 1;
+ BRGH = 1; // for high baud_rate
+ //_________End of baud_rate setting_________//
+
+ //****Enable Asynchronous serial port*******//
+ SYNC = 0; // Asynchronous
+ SPEN = 1; // Enable serial port pins
+ //_____Asynchronous serial port enabled_______//
+
+ //**Lets prepare for transmission & reception**//
+ TXEN = 1; // enable transmission
+ CREN = 1; // enable reception
+ //__UART module up and ready for transmission and reception__//
+
+ //**Select 8-bit mode**//
+ TX9 = 0; // 8-bit reception selected
+ RX9 = 0; // 8-bit reception mode selected
+ //__8-bit mode selected__//
+}
+//________UART module Initialized__________//
+
+
+
+//**Function to send one byte of date to UART**//
+
+void UART_send_char(char bt) {
+ while (!TXIF); // hold the program till TX buffer is free
+ TXREG = bt; //Load the transmitter buffer with the received value
+}
+//_____________End of function________________//
+
+
+
+//**Function to get one byte of date from UART**//
+
+char UART_get_char() {
+ if (OERR) // check for Error
+ {
+ CREN = 0; //If error -> Reset
+ CREN = 1; //If error -> Reset
+ }
+
+ while (!RCIF); // hold the program till RX buffer is free
+
+ return RCREG; //receive the value and send it to main function
+}
+//_____________End of function________________//
+
+
+
+//**Function to convert string to byte**//
+
+void UART_send_string(char* st_pt) {
+ while (*st_pt) //if there is a char
+ UART_send_char(*st_pt++); //process it as a byte data
+}
+//___________End of function______________// \ No newline at end of file