Tag Archives: pic

Making “The LCD Expansion Board” for PIC18F4520

In this tutorial I you show you how to make a very useful expansion board for our PIC development board. It will be a Do It Your self (DIY) LCD Expansion board. The expansion board can be plugged into the PIC development board to add 16×2 Alphanumeric LCD Support to it. Since LCDs are required in many projects and experiments it will be a very helpful board. I recommend you to read the LCD Interfacing Tutorial before you proceed. It will give you an Idea how LCD is connected to PIC Microcontrollers. So lets start! Schematic for LCD Expansion Board. Fig.: LCD Module Interface with PIC Microcontroller. The board is very easy to make as the MCU core unit is already done for you. So you need to just care about the LCD part. It consists of the 16×2 LCD Module and A variable resistor (10K) only! Optionally you can add a 47ohm series resistor with the LED backlight of the LCD Module, to enable the backlight. The variable resistor is used to adjust the contrast of the module. If NO text is displayed adjust this pot. All I/O ports and power supply is available at the top of expansion board. Fig.: A blank expansion. As you can see the top row in the board lists all I/O port of […]

Introduction to PIC18’s Timers – PIC Microcontroller Tutorial

Timers are common features of most microcontroller. In simplified terms a timer is just a register whose value keeps increasing (or decreasing) by a constant rate without the help of the CPU. The CPU can read or write this register any time. It reads it find out how much time has elapsed. The Timer register can have the following bit length 8 bit timers – These can count between between 0-255 16 bit timers – These can count between 0-65536 32 bit timers – These can count between 0-4294967296 A timer has a clock source, for example of the clock source of 10KHz is input to a timer then one increment will take 100uS (micro second). This clock source can be obtained from the CPU clock. The CPU clock of popular MCU ranges from 1 MHz to 20Mhz, this can be sometimes too fast. To help us out their is a thing called prescaler in the MCU. The job of prescaler is to divide the CPU clock to obtain a smaller frequency. The PIC Micro that we will use in this example has the following prescaler division factors available. 256 128 64 32 16 8 4 2 1 (Prescaler by-passed) Timers are also called Counters this is because they can be used to count external events. The following example illustrate […]

RS232 Communication using PIC18F4520’s USART – PIC Microcontroller Tutorial

Hello Friends! In this tutorial I will discuss how to practically do a simple communication over RS232 interface. For those who are completely new to this I clarify that the motive is to send and receive data between two device using a standard called RS232. RS232 is serial interface that means that data is transferred BIT by BIT at a time. Since data is transferred BIT by BIT so we need only a single wire two send data and an another one to receive data. One more common wire (called GND) is required between two separate circuit to enable current flow. So a total of three wire are required for communication. RS232 can be used to communicate between a variety of devices. Like your MCU and a GSM module or a PC. In this tutorial we will demonstrate a link between a PIC18F4520 MCU and a standard PC. On PC we will run a terminal program like RealTerm or Hyperterminal. A terminal program is used to send and receive text data. So any text send by the MCU will be visible on Terminal Screen and Any keypress you make on the PC keyboard will be send over RS232 to your MCU. This configuration is the simplest setup to test and understand RS232 communication. When you have enough knowledge you can […]

Multiplexed Seven Segment Display using PIC16F877A and HI-TECH C

#include <htc.h> #define _XTAL_FREQ 20000000UL typedef unsigned char UINT8; typedef signed char INT8; typedef unsigned int UINT16; typedef signed int INT16; //Connection of Seven segment display #define SEVEN_SEGMENT_LAT PORTD #define SEVEN_SEGMENT_TRIS TRISD //MUX Control #define MUX_PORT PORTB #define MUX_START_POS 1 //From which bit on port the select lines start //MUX settings #define MUX_DISP_COUNT 4 //Number of displays //Global Varriable UINT8 DisplayArray[MUX_DISP_COUNT];//Holds ‘data’ for each disp void SevenSegmentWrite(UINT16 n) { /* n=data to dislay example: n=1234 will display 1234 in a 4 segment display Working: This function breaks apart a given integer into separete digits and writes them to the display array i.e. digits[] */ UINT8 i=0; UINT8 j; while(n) { DisplayArray[i]=n%10; i++; if(i==MUX_DISP_COUNT) break; //We don’t have room for more digits n=n/10; } //Fill Unused area with 0 for(j=i;j<MUX_DISP_COUNT;j++) DisplayArray[j]=0; } void WriteSegment(UINT8 num) { switch (num) { case 0: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B01000000; break; case 1: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B01111001; break; case 2: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00100100; break; case 3: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00110000; break; case 4: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00011001; break; case 5: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00010010; break; case 6: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00000010; break; case 7: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B01111000; break; case 8: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00000000; break; case 9: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00010000; break; } } void Wait() { UINT8 i; for(i=0;i<1;i++) __delay_ms(10); } void main() […]

Interfacing LCD Modules with PIC Microcontrollers.

A large number of embedded project require some type of user interface. This includes displaying numerical, textual and graphical data to user. For very simple numerical display we can use 7 segment displays. If the requirement is little more than that, like displaying some alphanumeric text, we can use LCD Modules. They are cheap enough to be used in low cost projects. They come in various sizes for different requirement. A very popular one is 16×2 model. It can display 2 lines of 16 characters. Other models are 16×4,20×4, 8×1,8×2 etc. In this tutorial we will learn how we can use such modules with Microchip PIC Microcontrollers. Here I will present my LCD library which you can use to create LCD based application/projects quickly. For demo I will use PIC18F4520 Microcontroller but you can use any PIC18 MCU. But you have to calculate the CONFIG values for correct setting and CPU clock selection etc. That means the chip should be configured correctly. See datasheet for more info on CONFIG bytes. MPLAB Project Creation First create a MPLAB project as described in this tutorial. Name the project LCD. Also add a main file called "lcd_test.c". To use my LCD library you need to add it to your project. Just copy/paste the following files to your project folder. Header Files lcd.h myutils.h […]

PIC Development Board – Expansion of Board

The PIC Development board from eXtreme Electronics has the feature of connecting add-on boards, like user interface board or a motor controller board. You can also make your own expansion board. Actually the board has the ability to connect a prototyping area where you can create your project specific circuit while the "basic" environment for PIC resides on the Development board. Fig.: Replaceable Prototyping Area   In this way many project can be created and kept for future use. Each project resides in its own board when you need that simply pair it with development board and the project is up and running! No messy wiring! Preparing a Veroboard for connection Take a general purpose PCB (veroboard) and solder a 40 PIN right angled burg strip connector in one end. Fig.: Replaceable Prototyping Area Now the it is ready to plug into the Development Board. Fig.: Replaceable Prototyping Area   After you connect your prototyping area to the Dev Board all PORTs of PIC MCU and Power Supply becomes available in the veroboard. Here you can connect all sort of components required by your project. It is very easy to remove the prototyping are and replace it with a fresh new one for another project. Thus a single development board can be used for many different projects. The 40 PIN […]

PIC Development Board – Hello World Project

Hello friends, welcome to this exciting tutorial were we will begin our journey with latest PIC18F micros from Microchip Technologies. This tutorial will give you information on what software/hardware you will require and basic steps on how to get, install, configure and use them. After going through this tutorial you will have a complete setup and knowledge to experiment with these powerful chips !           What you will learn ? MPLab as a powerful IDE. HI-TECH C for PIC18 MCUs as a powerful C Compiler. Creating a new HI-TECH C project in MPLab. Write a C Code to blink LED and compile it to get a HEX code. Configure the MCU for proper oscillator selection. Basic Use for PIC development board from eXtreme Electronics Burn the HEX code to MCU using eXtreme Burner PIC from eXtreme Electronics. Use the programmed MCU to actually blink the LED ! So lets get started !!! First get these stuffs Microchip’s MPLab IDE or Integrated development Environment. This is the central tool from where you can access most of other tools, like the C Compiler. This also lets you create and edit program files and projects. Download this from Microchips Web site and Install it in your computer. Download MPLAB IDE Free. HI-TECH C Pro for PIC18 MCUs – This […]

PIC Development Board – Programming

The PIC Development Board can be easily programmed INCircuit by using our eXtreme Burner – PIC, a PIC Programmer with USB Connectivity. The firmware of a Microcontroller is normally stored in HEX files. This HEX file is generated by an assembler or a Compiler. In this section we will show you how you can transfer a HEX file from your PC to the Microcontroller. NOTE: It is assumed that eXtreme Burner – PIC (hardware) is installed as described in its documentation. It is assumed that eXtreme Burner – PIC (software) is installed as described in its documentation. Connect the PIC development board with the programmer using a six pin female to female cable as shown below. Power on both development board and the burner. Fig. Six pin female to female cable for ICSP.   Fig. 6 PIN ICSP of Development Board.   Fig. 6 PIN ICSP of eXtreme Burner – PIC. Launch eXtreme Burner – PIC from Windows Desktop or Start Menu. Fig.: eXtreme Burner – PIC, Main Screen.   The software is easy to use. First you need to load the HEX file which you want to burn to the MCU. So select Open from File Menu or From the Toolbar. Then select the hex file. Now the HEX file will be loaded and the contents (FLASH,EEPROM,Chip Settings) will […]

PIC Development Board – Introduction

Thanks for selecting PIC development board from eXtreme Electronics. Now lets get familiar with this powerful and easy to use system. Introduction This board will help you build and test any project with PIC microcontroller quickly and easily. It can be used to work with any 40 PIN PIC micros. The board provides the basic environment for the PIC to run. The great advantage of the design is replaceable prototyping area. All ports and power supply is available on 40 PIN female connecter. You can easily attach a normal veroboard with help of 40 PIN male headers. Now all PORTs of MCU is available on the veroboard where you can design the rest of your project. In this way you can create many different project with same development board, you just need a blank veroboard. By using this technique the "rest" of your project and the development board are paired firmly, both electrically and physically, yet flexibly separable! Features Incircuit Serially Programmable with eXtreme Burner – PIC. PIC 18F4550 Included USB 2.0 Support Running @ 48 MHz (12MIPS) with 20 MHz crystal. (Using on chip PLL) Inbuilt 5V regulator with reverse voltage protection Power Switch (on/off) Power LED Reset Button RS232 Interface with DB9 male connector. 2 x Extra 5v Out All ports on linear 40 pin female connector. Replaceable […]

General Purpose Digital IO with PIC Microcontrollers.

GPIO( General Purpose IO) is the most basic method of communication between MCU and external world. These are done with what is called a PORT. Ports are nothing but a set of bits physically connected to PINs of Microcontroller and available outside the chip. As we are working on PIC micros and they are 8 bits so the maximum size of a PORT is 8 bits. Some PORTs have fewer than 8 bits. You can turn each bit in a PORT on and off under program control. The bits which you set as 1 becomes HIGH and the physical PIN of Micro is at Vcc(supply voltage, usually 3.3v or 5v). And the PINs which you clear (=0) becomes low and physical level is 0v(GND). Fig.: PIC IO Port example, PORTB.   Fig.: PIC IO Port example, Using PORTB, Turning BITs on and off. You can test the operation of an IO port by using LEDs as shown below. Fig.: When the bit is set to 0 the LED remains off. When you write a value 1 to corresponding bit the LED starts glowing. Fig.: When the bit is set to 1 the LED starts glowing. PORTs are Named like PORTA,PORTB,PORTC etc. The PIC we are using PIC4550 has the following PORTs PORTA(8bit wide) PORTB(8bit wide) PORTC(7bit wide) PORTD(8bit wide) PORTE(4bit […]

Hello World Project With PIC Microcontroller – Part II

Hello Friends, Welcome back. In the last tutorial we started working with MPLab and HI-TECH C Compiler and written our first C program to blink LED. After compiling the program we got the HEX file. Now, in this tutorial we will see how to transfer(burn) the hex file to our Microcontroller chip and then power it up to actually blink the LED. We will use eXtreme Burner – PIC , which is a easy to use GUI programmer for PIC18 MCUs. The burner supports USB connectivity with PC so it is very easy to install and use. Launch eXtreme Burner – PIC from Windows Desktop or Start Menu.   Fig.: eXtreme Burner – PIC, Main Screen.   The software is easy to use. First you need to load the HEX file which was generated by MPLAB+HI-TECH C in previous tutorial. So select Open from File Menu or From the Toolbar. Then select the hex file. Now the HEX file will be loaded and the contents (FLASH,EEPROM,Chip Settings) will be available. Now connect the programmer with your PC by using standard USB Cable the programmer will be automatically detected by software (provided drivers are installed previously) . Apply power to programmer using a 12v DC adaptor. Place a PIC18F4550 chip in the ZIF socket and lock it.   Fig.: eXtreme Burner […]

Hello World Project With PIC Microcontroller – Part I

Hello friends, welcome to this exciting tutorial were we will begin our journey with latest PIC18F micros from Microchip Technologies. This tutorial will give you information on what software/hardware you will require and basic steps on how to get, install, configure and use them. After going through this tutorial you will have a complete setup and knowledge to experiment with these powerful chips !         What you will learn ? MPLab as a powerful IDE. HI-TECH C for PIC18 MCUs as a powerful C Compiler. Creating a new HI-TECH C project in MPLab. Write a C Code to blink LED and compile it to get a HEX code. Configure the MCU for proper oscillator selection. Burn the HEX code to MCU using eXtreme Burner PIC from eXtreme Electronics. Use the programmed MCU to actually blink the LED ! So lets get started !!! First get these stuffs Microchip’s MPLab IDE or Integrated development Environment. This is the central tool from where you can access most of other tools, like the C Compiler. This also lets you create and edit program files and projects. Download this from Microchips Web site and Install it in your computer. Download MPLAB IDE Free. HI-TECH C Pro for PIC18 MCUs – This is will compile the high level human readable programs (in […]