UART Lib for PIC18 in HTPIC18 compiler

by admin on May 23, 2009

I am a PIC programmer, so I would like to share this library I made before and hopy you can improve to make it better and to be perfect.

This souces is made under PIC18 compiler. I have tested this lib under some chips and it works well.

UART Library description and source

1. sysdef.h

The sysdef.h includes some constant values or defined values which are used in the library, you can change it to fit your system.

#ifndef SYSDEF_H
#define SYSDEF_H

// Crystal
#define	Fosc	20000000	

// UART Module
#define TX		RC6
#define RX 		RC7

#define TRIS_TX		TRISC6
#define TRIS_RX		TRISC7

// UART Data temporary
#define	UART_Data	TMR1H
#endif    // EOF

2. UART.h

  • UART.h includes some needed functions:
  • UART_Init: initialize the UART module. For example: UART_Init(9600)
  • UART_PrChar: to put a char to the RS232 port. For example: UART_PrChar(‘a’)
  • UART_PrString: to put a string to the RS232 port. For example: UART_PrString(“I love you”)
  • UART_detectBaudRate: to auto detect the PIC baudrate. After calling this function, the peripheral should send one special character U to the UART port to let PIC18 detect the baudrate. It is a new feature compared to PIC16.

You can download this library here: PIC18_UART_LIb (103). Password: ngohaibac.com

How to use this library

Simply you can copy all library files into your project directory and include the header file in every file you want to use this library.

# include "uart.h"

In this library, I already enable UART receive interrupt so you should clear the RCIF flag in the interrupt service routine.

Get fun!

VN:F [1.9.3_1094]
Rating: 10.0/10 (1 vote cast)
UART Lib for PIC18 in HTPIC18 compiler, 10.0 out of 10 based on 1 rating

Related posts:

  1. Tutorials how to work with Drupal I took those tutorials for Drupal website since I am studying how to use Drupal and how to customize it to my Group website. I think that will be useful for everyone who are using Drupal as beginner, even for the professional Drupal person. Part 1: Introduction and overview July 2006 This first article introduces [...]...
  2. The best CHM Viewer in Ubuntu Linux What is CHM ? Let’s have a look at Wikipedia: Microsoft Compiled HTML Help is a proprietary format for online help files, developed by Microsoft and first released in 1997 as a successor to the Microsoft WinHelp format. It was first introduced with the release of Windows 98, and is still supported and distributed through [...]...
  3. Introduce Qt – A cross-platform application and UI framework Homepage: http://www.qtsoftware.com/ What is Qt? Qt is a cross-platform application and UI framework. It includes a cross-platform class library, integrated development tools and a cross-platform IDE. Using Qt, you can write applications once and deploy them across many desktop and embedded operating systems without rewriting the source code. As you know that in the Information [...]...
  4. How to install RTAI, ComediLib in Ubuntu 8.10, Ubuntu 9.04 Last several months ago, I have done to install RTAI, ComediLib in Ubuntu 8.04. Actually, I have spent a lot of time to config Ubuntu system. It faces a lot of problems but finally it has finished. Now new RTAI package version 3.7 which supports Linux kernel 2.6.28 has been released with a lot of [...]...

Leave a Comment

Previous post:

Next post: