PIC Microcontroller - SPI

SPI Communication with PIC Microcontroller – MPLAB XC8

SPI (Serial Peripheral Interface) is a full duplex synchronous serial communication interface used for short distance communications. It is usually used for communication between different modules in a same device or PCB. SPI devices communicates each other using a master slave architecture with a single master. SPI is called as a 4-wire bus as it requires four wires for its communication as shown above. In the case of single slave communications we need only 3 wires, as slave select (SS) is [...]

I²C Bus Logo

I²C Communication with PIC Microcontroller – MPLAB XC8

I2C or IIC or I2C stands for Inter-Integrated Circuit. It is a very popular multi-master, multi-slave serial communication interface developed by Philips. I2C uses two bidirectional open drain data lines, Serial Data (SDA) and Serial Clock (SCL) with pull up resistors as shown below. Unlike UART, you can connect and communicate to multiple devices using the same I2C bus. I2C is a master slave protocol. It means that devices connected to I2C bus will be either master or slave. The master is the [...]

Analog to Digital Converter

Using ADC of PIC Microcontroller – MPLAB XC8

In this tutorial we will learn, how to use the ADC module of a PIC Microcontroller using MPLAB XC8 compiler. For demonstration we will use the commonly available PIC 16F877A microcontroller. Every physical quantity found in nature like temperature, humidity, pressure, force is analog. We need to convert these analog quantities to digital to process it using a digital computer or a microcontroller. This is done by using Analog to Digital Converters. An Analog to Digital Converter or ADC is a [...]

PWM - Pulse Width Modulation

Generating PWM with PIC Microcontroller – MPLAB XC8

Pulse Width Modulation (PWM) is the one of the simple and most commonly used technique to produce analog voltages from digital signals. It has a wide variety of applications such as Digital to Analog Converter (DAC), DC Motor Speed Control, Sine Wave Inverters, Brightness control etc. PWM signals are ON - OFF signals (HIGH or LOW) (hence the name Pulse) whose HIGH or ON duration is changed (hence Width Modulation) in accordance with our requirements. The fraction of time period [...]

UART Communication

Using UART of PIC Microcontroller – MPLAB XC8

UART stands for Universal Asynchronous Receiver / Transmitter. It is a very popular serial communication interface which provides Full Duplex communication between two devices. UART uses two data lines for sending (TX) and receiving (RX) data. Ground/Reference of both devices should be made common. As the name indicates it is an asynchronous communication interface, which means that it doesn't need to send CLOCK along with data as in synchronous communications. UART is the communication interface used by our old [...]

16x2 Character LCD

Interfacing LCD with PIC Microcontroller – MPLAB XC8

In this tutorial we will see How to Interface a 16x2 character LCD module with PIC 16F877A Microcontroller using MPLAB X IDE and MPLAB XC8 C Compiler. 16x2 Character LCD is a very basic and low cost LCD module which is commonly used in electronic products and projects. 16x2 means it contains 2 rows that can display 16 characters. Its other variants such as 16x1 and 16x4 are also available in the market. In these displays, each character is [...]

HC-SR04 Ultrasonic Sensor

Interfacing HC-SR04 Ultrasonic Sensor with PIC Microcontroller

HC-SR04 Ultrasonic Distance Sensor is a popular and low cost solution for non-contact distance measurement function. It is able to measure distances from 2cm to 400cm with an accuracy of about 3mm. This module includes ultrasonic transmitter, ultrasonic receiver and its control circuit. HC-SR04 module has 4 pins : VCC - 5V, +ive of the power supply TRIG - Trigger Pin ECHO - Echo Pin GND - -ive of the power supply TRIG and ECHO pins can be used to interface this module with a [...]

Push Button Switch

Using Push Button Switch – MPLAB XC8

I hope that you already go through the first tutorial of MPLAB XC8, Getting Started with MPLAB XC8 - LED Blinking. In that tutorial we learn how to use an output pin by driving an LED. In this we will learn how to read an Input pin using a push button switch. We already seen that TRIS register is used to set direction of each IO pin, ie Input or Output and PORT register is used to read or [...]