16f628a Simple Programming



Simple

I built a jdm type (multipic 5.2) and cannot get winpic to initalize it. I am very new to these things and may build another for just the 16f628a since thats my 'beginner' chip. Any one know of a simple one for that chip?

The recent trends in the advanced technology are helpful in developing most advanced electronic gadgets. Most of these electronic devices are developed using microcontrollers. The microcontroller is an electronic component, which is programmed to perform various control operations. There are various kinds of microcontrollers available, such as 8051, AVR, ARM, and PIC microcontrollers, etc., which are programmed by using the integrated development tools.

  1. This is because the pic 16f648a / 16f628a is an 8-bit microcontroller this means that we can store any binary number from all zeros 00000000 to all ones 11111111 (all zeros in binary 0000000 is equal to zero decimal 0) and (all ones in binary 11111111 is equal to 255 decimal) this means that there are 256 combinations within each 8-bit variable.
  2. Now, the breadboard module is ready and its a time to test it. I have written a small application program to chase 8 LEDs that are connected to the PORTB pins of the PIC16F628A microcontroller. The circuit diagram is not shown here as it is very simple.

PIC Microcontroller

The PIC is a family of the microcontroller, which is manufactured by the different companies such as NXP, microchip, etc. The PIC stands for “peripheral interface controller”, which contains memories, timers/counters, serial communication, interrupts and ADC converters built into a single integrated chip.


The PIC microcontrollers are found in most electronic devices such as alarm systems, traffic control systems and RFID based security systems, etc. The PIC microcontroller programming can be carried out to perform the huge range of tasks. Even though there are many types of PIC microcontrollers , the best and basic microcontroller is PIC16f877a.

PIC Microcontroller Programming Procedure

The PIC microcontrollers is programmed by the embedded C language or assembly language by using appropriate dedicated software. Before going to build a PIC microcontroller project, we must become aware of developing a basic microcontroller (like 8051) based project. Once you get the idea, this controller based project building becomes easy, so let us look at the basic steps to build a PIC microcontroller based project.

Before going to program the PIC microcontroller, first we have to select the right project that you are going program the microcontroller. As of now, consider the LEDs flash light system.

Theory:


The LEDs flashlight uses a set of light emitting diodes, and these are advanced to the traditional incandescent lights which consumes more energy and have very less life time. The LED lights on the other hand, consume less energy and have longer life.

Basic Idea of this Project Behind the Design:

The microcontroller generates the output logic pulses so that the LED light is switched ON and OFF at certain intervals. It is a 40 pin microcontroller. The Crystal interfaced to the input pins of the microcontroller provides accurate clock signals at the crystal frequency.

Circuit Designing

16f628a Simple Programming

The PIC microcontroller transmit and receive the data with respect to clock pulses, the PIC microcontroller operates with 4MHz crystal frequency. Two capacitors are connected to the crystal oscillator with range of 20pf to 40pf which is used to stabilize the clock signals. At some times, the PIC microcontroller goes to block state or missing time calculation,at that time we need to reset the microcontroller. If a microcontroller is reset for 3sec time delay, 10k resistor and 10uf capacitor are connected to the respective pins.

Circuit Components

Hardware Components

  • Yellow LEDs
  • Crystal
  • Reset
  • PIC Microcontroller
  • Capacitors
  • Resistors

Software Components

  • MPLAB Compiler
  • Proteus software

Circuit Connections

The 5v DC supply is given to the 11 pin of the microcontroller which drives the circuit. The crystal is connected to the 13 and 14 pins of the microcontroller. The reset circuit is interfaced at 1 pins of the microcontroller. The Yellow LEDs is connected to the PORTB of the microcontroller.

Circuit Diagram

This circuit is designed with the help of Proteus software. The Proteus is a circuit designing software that contains a database of components, which we can use to build the circuit. Each and every component is available in the component library.

  • Open the Proteus software. A window with a menu bar appears.
  • Click the file menu.
  • Select ‘new design’ from the drop-down menu.
  • Click the library menu.
  • Select ‘pick devices/symbol’ from the drop-down menu.
  • Select the relevant comment by double clicking it, so that the electronic components list appear on the window.
  • Add all the components and draw the circuit with the proper connections as shown above.

Program the PIC Microcontroller

The PIC microcontroller programming is performed through ‘MP-Lab’ software. First instal the MP-Lab software, then select and install the compiler like CCS, GCC compiler, etc. Here ‘CCS C compiler’ is used for building the program.

  • First open the MPLAB software. This shows the menu bar with file, edit, view, project and tools option.
  • Select the project option and select the ‘project wired option’ from the drop-down menu. This will show the project wired window.
  • Select a microcontroller for your project. Here ‘PIC16f877A’ microcontroller is selected.
  • Select the compiler and path location for your project. Here ‘CCS C compiler’ is selected for the PIC microcontroller, then select the ‘browse’ option from the project wired window to select the ‘ccsloader’ in the PICC folder from the program files. A folder with the name ‘source group’ is created in the ‘target’ folder.
  • Give a name to the project and click on ‘NEXT’ button to save the project. A folder with the name ‘source group’ is created in the ‘target’ folder.. Click on the ‘file’ menu on the menu bar. Select ‘new file’ from the drop- down menu.

The LED Flash Program:

#include<pic16f877x.h>
void delay(int);
sbit a=PB^2;
sbit b=PB^3;
sbit c=PB^4;
sbit d=PB^5;
void main()
{

16f628a Simple Programming Instructions

TRISB=0x00;
a=b=c=d=0x00;
delay(10);
a=b=c=d=0xFF;
}
void delay(int a )
{
unsigned char c;
for(c=0;c<a;c++)
for(c=0;c<250;c++);
}

16f628a Simple Programming Language

Load the Code to PIC Microcontroller

The code loading process of microcontroller is called dumping. The microcontrollers understand only the machine level language, which contains ‘0 or 1s’. So we need to load the hex code into the microcontroller. There are many softwares available in the market for loading the code to the microcontroller. Here we have used ‘PICFLSH’ programmer software to dump the code to the PIC microcontroller. The programmer kit comes with the hardware kit along with the software.

This software needs to be installed into the computer. The microcontroller placed in the hardware kit, which comes with the socket. Here are the steps to load the code onto the microcontroller.

  • Interface the hardware (programmer kit) to the computer through a serial cable
  • Place the microcontroller in the socket of the hardware kit. Press the lock button to ensure the microcontroller is connected to the board.
  • Open the software installed in the computer. This shows the menu bar with file, functions, open, save and setting options.
  • Select the ‘open’ option from the drop-down menu and select the ‘load file’ .
  • Click on the ‘load’ button so that the hex file is loaded into the microcontroller.

Simulating the Circuit

16f628a simple programming language

The simulation is a decision analysis and support tool, which is used to know the performance of the circuit. The hardware is the cost-effective equipment, so the proposed action cannot be directly observed by the hardware. The simulation software allows you to know the circuit performance and find & rectify the errors of the program. There are different types of simulating softwares available in the market for checking the circuit performance. Here Proteous software is used to check the circuit performance.

  • Open the project in the Proteus software.
  • Click on the ‘Debug’ menu.
  • Select the ‘start debugging’ option. The LED starts blinking, which indicates the circuit is running.
  • After some time, select the ‘stop debugging’ option. The LED will now stop blinking.

These are the necessary steps for PIC microcontroller programming to develop simple project. Hope that you might have got a basic idea on this topic. Any further assistance to build the PIC based projects or any microcontroller based projects you can contact us by commenting below.

Related Content

In this tutorial we will discuss how to access the PIC16F877A internal EEPROM memory to store and retrieve the data. Eeprom is basically used to store the non volatile data which is required to be stored even if there is power loss or controller resets.

16f628a Simple Programming

PIC16F877A comes with three memories Flash,RAM and EEPROM. Below table shows the memory capacity of PIC16F877A:

Memory Size Description
FLASH 8k-bytes Used to store the programs
RAM 368-bytes Temporary/ScratchPad memory used during program execution.
EEPROM 256-bytes Used to store the non-volatile data across power cycles


16f628a Simple Programming

The below table shows the registers associated with PIC16F877A UART.

Register Description
EECON1 Eeprom read/Write Control register
EECON2 Used to execute special instruction sequence(0x55-0xAA) during write
EEDATA Holds the data to be Written/Read to/from Eeprom.
EEADR Hold the Eeprom memory address from where the data needs to be read/written.

EEPCON1
7 6 5 4 3 2 1 0
EEPGD - - - WRERR WREN WR RD

EEPGD: Program/Data EEPROM Select bit
1 = Accesses program memory
0 = Accesses data memory

WRERR: EEPROM Error Flag bit
1 = A write operation is prematurely terminated
0 = The write operation completed

WREN: EEPROM Write Enable bit
1 = Allows write cycles
0 = Inhibits write to the EEPROM

WR: Write Control bit
1 = Initiates a write cycle. The bit is cleared by hardware once write is complete. The WR bit can only be set (not cleared) in software.
0 = Write cycle to the EEPROM is complete

RD: Read Control bit
1 = Initiates an EEPROM read; RD is cleared in hardware. The RD bit can only be set (not cleared) in software.
0 = Does not initiate an EEPROM read

  1. Check the WR bit to see if a write is in progress and wait till it becomes zero.
  2. Write the address to EEADR. Make sure that the address is not larger than the memory size of the device.
  3. Write the 8-bit data value to be programmed in the EEDATA register.
  4. Clear the EEPGD bit to point to EEPROM data memory.
  5. Set the WREN bit to enable program operations.
  6. Disable interrupts (if enabled).
  7. Write 55h to EECON2
  8. Write AAh to EECON2
  9. Set the WR bit
  10. Restore the Interrupts.
  11. Clear the WREN bit to disable program operations.

16f628a Programmer


  1. Check the WR bit to see if a write is in progress and wait till it becomes zero.
  2. Write the address to EEADR from where the data needs to be read. Make sure that the address is not larger than the memory size of the device.
  3. Set the RD bit to start the read operation
  4. Read the data from the EEDATA register.


Lets put all together whatever we have discussed and write a simple program to write the data(A-Z) to eeprom and then read it back.


Download the complete project folder from the below link:
Hardware design Files and Code Library


Have a opinion, suggestion , question or feedback about the article let it out here!

Please enable JavaScript to view the comments powered by Disqus.