Categories
Examples

PIC16F676 LED Blink Program

LED Blink Program is a hello world program of microcontroller world. It not only gives us the idea of how to use the GPIOs of the microcontroller but also makes us sure that our development environment is stable and ready to use. PIC16F676 microcontroller is a 14 pin microcontroller that is very much suitable for many small IO related applications. We are going to create a first Hello world program for PIC16F676. We also call this PIC16F676 LED blink program. For the sake of simplicity and detailed explanation, we are going to use the PIC Hi-Tech Compiler with MPLAB IDE. We may also use the other compilers like PIC CCS or MikroC Pro for PIC, but we rather chose PIC Hi-Tech compiler to get a good underneath knowledge rather than just using the built-in libraries.

Brief Introduction to PIC16F676 Microcontroller

Before we jump into the coding section of the PIC16F676 microcontroller, we need to understand the basic introduction of this 16F676 microcontroller. For that, you need to look for the datasheet for the PIC16F676 microcontroller. Which says that it is a 14-Pin, Flash-Based 8-Bit CMOS Microcontroller. Other main features of the microcontroller are as follows

  • Interrupt-on-Pin Change
  • Power-Saving Sleep mode
  • Precision Internal 4 MHz oscillator factory calibrated to ±1%
  • Flash/data EEPROM retention: > 40 years
  • Individual Programmable Weak Pull-ups

Peripheral Related Features of the PIC16F676 Microcontroller

Here are the peripherally related features of the PIC16F676 Microcontroller according to the datasheet of the PIC16F676 microcontroller from the Microchip manufacturers.

  • 12 I/O Pins with Individual Direction Control
  • High Current Sink/Source for Direct LED Drive
  • 10-bit 8-channel Analog-to-Digital Converter module
  • Timer0: 8-bit Timer/Counter with 8-bit Programmable Prescaler
  • Enhanced Timer1: 16-bit timer/counter with prescaler, External Gate Input mode, Option to use OSC1 and OSC2 in LP mode as Timer1 oscillator, if INTOSC mode selected

LED Blinking Code

Here is the complete final code for the LED Blinking attached to the Bit_0 of the PORTC.

#include <htc.h>
#define _XTAL_FREQ 4000000
__CONFIG( 0x3FFC);


void main()
{

  //MAKE PORTA & PORTC OUTPUT
  TRISA=0x00;
  TRISC=0x00;
//---------------------------------
  ANSEL = 0b00000000;//MAKE ALL ANALOG PINS AS DIGITAL OUT

  CMCON=0x07;//comparator off
  ADCON1=0x10;//Fosc/8 speed

  while(1)
  { 
    PORTC |= (1<<1);
    __delay_ms(1000);

    PORTC &= ~(1<<1);
    __delay_ms(1000);
  }
}Code language: PHP (php)

By Abdul Rehman

My name is Abdul Rehman and I love to do Reasearch in Embedded Systems, Artificial Intelligence, Computer Vision and Engineering related fields. With 10+ years of experience in Research and Development field in Embedded systems I touched lot of technologies including Web development, and Mobile Application development. Now with the help of Social Presence, I like to share my knowledge and to document everything I learned and still learning.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.