Category: PIC MicroController


 

 

pic2    pic3

 

PICKIT3  seems to be a DEGRADED version of PICKIT2 . PIC may be a Microcontroller Giant , but a newer version of Toolkit should be more user friendly than the previous versions.In case of PIC the design Team has never bothered this.

Following are the Changes made in PICKIT3 , which many have criticized  :

1. The little useful standalone program  PICKIT2 to fuse HEX files is scrapped now.There is no standalone program to fuse HEX files.Now you need to install MPLAB IPE along with MPLAB X IDE & use that for fusing target IC with HEX file.

2. PROGRAMMER TO GO function of PICKIT2 is scrapped in PICKIT3.

This function allows a PIC MCU memory image to be downloaded into the PICKIT 2 unit for later programming into a specific PIC MCU. No software or PC is required to program devices once the PICkit 2 unit is set up for Programming-To-Go

3. TARGET is not powered automatically in PICKIT3. In PICKIT2 Automatic Power feature is enabled by default.In case of PICKIT3 you need to CONFIGURE manually , else you get TARGET NOT FOUND error.

4.PICKIT3 does not detect DEVICE automatically.You need to select the device from drop down list.

5.PICKIT3 uses PIC24 series MCU , while PICKIT2 was designed on PIC18 series.But PICKIT2 seems to be faster than PICKIT3.

6.If you change the target IC , Firmware upgrade happens every time in PICKIT3 , an annoying feature.   

As MICROCHIP has stopped production & support to PICKIT2 we’ve to live with PICKIT3.Let us now see the solutions for common problems faced in using this “ADVANCED Device”.

You can fuse the HEX file from within MPLAB X IDE or through MPLAB IPE..

MPLAB X IDE Method :

From within MPLAB IDE click the Icon with down Arrow image “Make & Program Device Main Project”.

The project is now BUILD.

Once you get BUILD SUCCESSFUL in the OUTPUT Window , the IDE will try to connect with PICKIT3 Programmer

 

mp1

 

But you get TARGET NOT FOUND error.

 

mp2

Click on RUN –>set project configuration –>CUSTOMIZE

 

mp4

On the new window select PICKIT3

MP5

Under OPTIONS CATGEGORIES drop down select POWER

 

mp6

Tick mark “Power Target circuit from Pickit3”

& select voltage level as 5.0

 

mp7

Click OK & then click on the  “Make & Program Device Main Project” again

Now the target is detected & HEX file fused on to target.

mp9

Method 2 : Through MPLAB IPE

From MPLAB IDE click RUN –> BUILD MAIN PROJECT  to create the HEX file.

MP10

The HEX file is created inside the PROJECT File –> dist –> default –> production

Note the location of HEX file.

Image 6

Now open MPLAB IPE the Integrated Programming Environment

 

Image 17

Select the IC , here PIC16F877A , Apply & then click on CONNECT

Image 7

 

You get Target Not found ERROR.

Image 8

Click  SETTINGS –> ADVANCED MODE

Image 9

 

To enter Advanced mode you need to type in the password –     microchip

Image 1

Now a new set of buttons appear on left side.

Click on POWER button

Image 11

Select Vdd as 5.0 & then tick mark “POWER TARGET CIRCUIT FROM TOOL”

Image 12

Now click on OPERTATE button

Image 13

The target is found & connected now.

Click the browse button & navigate to select the HEX file stored.

Image 14

Click PROGRAM button to fuse the target chip with selected HEX file.

Image 15

 

Image 16

 

cooltext753793315   cooltext753790696

Advertisements

 

16 X 2 LCD is most popular in Embedded projects .16 is the number of Columns & 2 is the no. of Rows.Generally it needs 8 bits to display the data as the Data bus is of 8 bits.

In this post the LCD is used in 4 bit mode ,splitting the data Byte in Nibbles.So we can save 4 data port pins of the PIC microcontroller.

Complete datasheet of  this LCD is available here .

The Data or command is sent in nibble form (1 nibble= 4 bit) in the 4-bit mode. The higher nibble is sent first followed by the lower nibble. The function of RS, RW and EN pins remains similar to 8-bit mode.

The pin out of LCD is as follows:

1. Ground
2. VCC (+3.3 to +5V)
3. Display Contrast adjustment (VO)
4. Register Select (RS). RS=0: Command, RS=1: Data
5. Read/Write (R/W). R/W=0: Write, R/W=1: Read
6. Clock (Enable). Falling edge triggered
7,8,9,10   Bit 0 to bit3  (Not used in 4-bit operation)
11. D4 Bit 4
12. D5 Bit 5
13. D6 Bit 6
14. D7 Bit 7
15.Backlight Anode (+)
16.Backlight Cathode (-)

 

PIC_LCD

For interfacing LCD with microcontroller we need system-bus (data-bus, address-bus and control-bus). In our case for 4 bit mode the  data pins (D4-D7) are the ‘data and address’ bus while the 3 control pins(RS, R/W and E) are the control bus

These displays generally have a 16-wire interface, of which 11 IO lines from the PIC micro are needed. 8 of these lines are for DATA.

As we use LCD in 4 BIT Mode , only 4 lines are actually needed.

The Read/Write R/W pin is pulled to Ground making the LCD write only.

Dropping the 4 Data lines & the R/W line , we need only 6 I/O lines (4 data lines D4-D7 along with RS and Enable)  for basic operation

 

To start with create a Folder say inside F:\myprojects to store all our work.

Open the MPLABX IDE & click on File –> New Project

Choose Project –> Microchip Embedded –> Standalone Project  click on Next & select the Device as PIC16F877A

Select Tool as PICKIT2  & Compiler as XC8

Provide project name as LCD & project location as F:\myprojects ( we’ve created earlier).

Image 4

 

Click on FINISH

 

Image 1 

Inside FILE PANE you can see the default File folders created by the IDE.

For the XC compiler to understand the LCD hardware , a Header file is used.Download this file & store it inside the LCD.X folder. HEADER FILE DOWNLOAD HERE

Copy & paste the lcd.h header file into the LCD.X folder.

Right click on Header Files –> Add Existing Item  & browse to the location where you’ve stored the lcd.h  header file & select it.

Now lcd.h will appear under Header Files folder

Image 2

 

Now Right click on Source Files –> New  –>  C Main File

Provide a file name , or leave it to default name “newmain” .

Select the extension as .c from the drop down.

You can see newmain.c file created inside the LCD.X project folder.

 

Image5

 

Click on Finish to see the newmain.c file under Source Files folder .The LCD.h file is seen under Header Files folder.

Delete the generated code for now .

Image 6

Click on Window –> PIC Memory Views  –> Configuration bits & set the config bits as FOSC = HS ,WDTE =OFF ,LVP = OFF ,etc.. as seen below

Image 7

 

Click on “Generate Source code to output “ button seen at the bottom.

Image8 

 

You can copy & paste  the Configuration code on to the Editor Pane.

Or you can enter the following config. code in a single line as :

————————————————–

#include <xc.h>

#pragma config FOSC=HS , WDTE=OFF , LVP =OFF , PERTE=OFF

—————————————————

As we use an external crystal of 20 MHz on demo board , we declare FOSC as HS & other settings WatchDog, Low Voltage Programming ,etc . as OFF

Below the #include <xc.h> statement define the crystal value as

#define _XTAL_FREQ 20000000

20 followed by 6 zeroes represents 20 MHz value.

Image9

 

 

Image 10

#include “lcd.h” statement indicates that the lcd.h file resides inside the project folder.Previously you should’ve downloaded this file & stored it inside the LCD.X folder.Otherwise you’ll get red error squiggles against this statement.

PORT D pins are used to connect with the LCD.

We need only 4 pins for DATA , as we use the LCD in 4 bit mode. Pins RD4 to RD7 are used for data bits D4 to D7.

RS (Register Select)  is connected to pin RD2.

When RS = 0 , D4 to D7 value is interpreted as COMMAND by the LCD.

When RS = 1 , D4 to D7 value is interpreted as DATA by the LCD.

To initialize & set the cursor location we set this RS as 0 (Command mode) & for displaying Data we set this RS to 1.

LCD enable pin is connected to RD3.

R/W READ/WRITE pin of LCD is connected to GND as we use the LCD to display DATA.

All these connections are declared using the #define preprocessor statements.

 

———————————————–

#define _XTAL_FREQ 20000000

#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
// BEGIN CONFIG
#pragma config FOSC = HS,WDTE=OFF ,PWRTE = OFF,BOREN = OFF, LVP = OFF
//END CONFIG
#include <xc.h>

#include "lcd.h";

void main()
{
  unsigned int a;
  TRISD = 0x00;
  Lcd_Init();
  while(1)
  {
    Lcd_Clear();
    Lcd_Set_Cursor(1,1);
    Lcd_Write_String("LCD Library for");
    Lcd_Set_Cursor(2,1);
    Lcd_Write_String("MPLAB XC8");
    __delay_ms(2000);
    Lcd_Clear();
    Lcd_Set_Cursor(1,1);
    Lcd_Write_String("WWW.ALSELECTRO.COM");
    __delay_ms(2000);
    Lcd_Clear();
    Lcd_Set_Cursor(1,1);
    Lcd_Write_String("Saravana Electronics");

    for(a=0;a<15;a++)
    {
        __delay_ms(1000);
        Lcd_Shift_Left();
    }

    for(a=0;a<15;a++)
    {
        __delay_ms(1000);
        Lcd_Shift_Right();
    }

    Lcd_Clear();
    Lcd_Set_Cursor(2,1);
    Lcd_Write_Char(‘S’);
    Lcd_Write_Char(‘E’);
    __delay_ms(2000);
  }
 
}

————————————————————-

After feeding in the code as above ,

Click on Run –> Build Project

If all the syntax are correct you get BUILD SUCCESSFUL.

Finally click on Run –> Run Main Project or press F6 to execute the program & see result on the LCD.

Support  Video :

 

PIC 16F877A WITH LCD

 

IMG_4

There are 2 types of  seven segment displays – CC (Common Cathode) & CA (Common Anode).In this post we shall see how to interface CA display with PIC 16F877A.

   The display , as the name indicates , is made up of seven segments of LED.Each one of the seven LEDs in the display is given a positional segment with one of its connection pins being brought out of the  plastic package. These  LED pins are labeled from “ a “ to “ g“ representing each individual LED. The other LED pins are connected together and wired to form a common pin.

In case of CA display +5v is tied to Common pin.

The  common pin is generally used to identify which type of 7-segment display it is. As each LED has two connecting pins, one called the “Anode” and the other called the “Cathode”, there are therefore two types of LED 7-segment display called: Common Cathode (CC) and Common Anode(CA).

Common anode displays are more popular as many logic circuits can sink more current than they can source.

    

Depending upon the decimal digit to be displayed, the particular set of LEDs is forward biased. For instance, to display the numerical digit 0, we will need to light up six of the LED segments corresponding to a, b, c, d, e and f. Then the various digits from 0 through 9 can be displayed using a 7-segment display as shown.

For a Common Anode Display , the COMMON pin should be connected to HIGH & the corresponding DIGIT segments should be made LOW.Each LED segment can tolerate up to only 1.5v DC .

As the HIGH level from PIC is around 5V , a current limiting resistor of 470 ohms must be used at the common pin.

For e.g., to display digit 1 , the segments b & c should be made LOW while the COM pin is made HIGH.

To display digit 2 , the segments a,b,d,e & g are made LOW while making the COM pin HIGH.

Then for a 7-segment display, we can produce a truth table giving the individual segments that need to be illuminated in order to produce the required decimal digit from 0 through 9 as shown below.

7seg_1

CONNECTIONS :  All segment pins are Enabled by LOW (0)

RD2  –>  DIGIT 1  Common Anode pin made HIGH to display a Digit.

RB7—>  D0               RB0 –> D7    

RB3 –> D4                RB6 –> D1 

RB2 –> D5                RB5 –> D2

RB1 –> D6               RB4 –> D3

 

The Demo board I’m using has 4 PNP Transistors which is connected to Digit1,Digit2,Digit3 & Digit4.When a LOW is applied to Base of transistor,it conducts and apply HIGH to the Common pin of Display.

seg1

 

Open a New project in MPLABX & follow the initial STEPS as described in previous post.

The code to drive a single Display is given below.CONFIG statements to be replaced by the code generated for configuration bits as described in earlier post.

——————————————————————

#define _XTAL_FREQ 16000000
#include <xc.h>

// CONFIG statements here….

unsigned char hexValue[10]={0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09};
int i=0;

int main()
{
TRISB=0x00;  // Port B pins all OUTPUTs
TRISD2=0; // RD2 as OUTPUT
RD2=1;    // Disable display 1

while(1)
  {
    RD2=0;   // Enable Display 1
    for( i=0; i<10; i++)
    {
        PORTB= hexValue[i];
        __delay_ms(1000);
    }
  }
}

———————————————————————–

PNP transistors are used to drive the Enable common pin of CA displays. A LOW at the base of transistor will make it conduct & provide HIGH at the common Anode pin of Display.

According to the data pin (D0 to D7) levels , digits 0 to 9 are displayed. A LOW at data pin will make the segment GLOW & a HIGH will make it OFF.

7seg

The HEX values for the Digit to be displayed are achieved as shown in the Table above.These values are stored in an Array variable unsigned char hexValue , which is declared to store 10 values.

Port B is defined as Output by TRISB = 0x00;

Port pin D2 is declared as Output , which is used to enable the common pin of display.

Initially RD2 = 1 which makes the PNP transistor OFF & the display is disabled.

Under While loop , the  RD2 is made 0 to enable the Display & the HEX value data is loaded one by one at an interval of 1 sec.

You get display running from 0 to 9 at 1 sec interval repeatedly.

In the previous post we’ve seen the LED blinking program.In this post we shall see how to connect a push switch to a Digital Input of PIC 16F877A .

A micro switch is connected between port pin RB0 & Ground. Port pin RB0 is pulled High through a 10k resistor connected to +5v supply.On pressing the switch the LED glows & on releasing the switch the LED GOES Off.

 

Image 8

 

In the development board I’ve used , the pull up resistors are not provided.But this can be enabled internally by making the bit RBPU=0 of Option Register.

This can be achieved by declaring

OPTION_REG=0b01011110;

or   RBPU=0;   The NOT_RBPU bit (MSB) is cleared in the Option Register to apply PULL UP internally to all PORTB pins. 

opt2

The pull up resistor is mandatory to avoid floating values at digital inputs.

 

Following 10 Steps are common for all projects except the project name is different.

In future projects I will not mention the following 10 steps .These are the initial settings required for each project.Future posts will be focused on main C code straight away.

——————————————————————————-

STEP 1 :

Click on  File –> New Project

Under Choose Project select category  “Microchip Embedded “ & Projects as“ StandaloneProject

 

Image 1.1

 

STEP 2 :

Select the Target device as PIC16F877A.

Click Next

Image1.2

 

STEP 3 :

Select the TOOL as PICKIT2

Image1. 3

STEP 4 :

Select the Compiler as XC8 & click Next.

 

Image1. 5

 

STEP 5 :

Provide a name to the project & select the Project folder to store the results.

Click on FINISH

Image 2

STEP 6 :

Project folder appears in the File pane.

Right click on Source Files &  select  New  –>  C Main File

Image 3

 

STEP 7 :

Provide a name to the C file .The extension must be selected as c from the drop down below.

Click on FINISH

 

Image 4

STEP 8 :

Click on   Window  –> PIC MEMORY VIEWS –> Configuration Bits

Image 9

 

On the Task pane window you get the Configuration Bits .

Each bit can be modified as ON or OFF by the drop down menu following the bit

Set FOSC to HS for High Frequency External oscillator & other bits all OFF.

Click on “ Generate Source code to Output” button at the bottom.

 

Image 10

STEP 9 :

Configuration bit setting code is generated.

Delete the default code seen in the Editor pane on top.

Now Paste the Configuration code here.

 

Image 11

STEP 10 :

Finally add the Crystal Frequency definition to the top of #include <xc.h> statement

#define _XTAL_FREQ 16000000

Image 14

 

——————————————————————————-

——————————————————————————-

Now you can feed the following C main code below the configuration code.

Image 5

 

OPTION_REG MSB bit is cleared to enable internal PULL UP Resistors for PORTB.

Port B pin 0 is declared as INput where switch is connected

Port D Pin 2 is declared as Output where LED is connected  .

Initially LED is OFF by making RD2 pin low (RD2=0).

Under the never ending loop the condition of RB0 is verified & if the switch is pressed RD2 is made High , thus making the LED glow.

After a delay of 2 secs the LED is made OFF.

 

After feeding the Code press CTRL+SHIFT+S  to save all the project files.

Now click on RUN –> Build the Main Project 

 

Image 6

After getting BUILD SUCCESSFUL click on “Run Main Project “

The generated HEX file will be loaded on to the Target chip .

Image 7

If you press the switch at RB0 the LED at RD2 glows.

IMG_2

 

The same code can be used to check the Buzzer circuit & the Relay circuit ( if you’ve purchased the development board shown above)

Remove the wire at LED point & connect it to Relay input (connector CN12 ) which is seen near the yellow sugar cube relay on top right of the board.Now by pressing the switch the relay gets ON ,just like the LED.

To test the buzzer , connect the  wire from  RD2 port pin to CN21 .The buzzer is with a white round sticker on its top , seen  just above the LCD.Pressing the key will activate the buzzer now.

For availability of this development board contact :

cooltext753793315   cooltext753790696

http://www.alselectro.com/pic-development-kit-with-lcd.html

 

In this post we shall work with the HELLO WORLD program ,blinking an LED.

Port Pin RD7 is declared as output where an LED is connected through a current limiting resistor of 470 ohms.External crystal of 16MHZ is used in the circuit & this is defined in the configuration settings.

led1

Open the MPLABX IDE.

Click on File – > New Project

1.NEW

 

A New Project window opens.Select the category “Microchip Embedded “ & under projects select “Standalone Project” . Click on Next.

 

2.CHOOSE

 

Next step is to select your target device.Under Device bar you can type in PIC16F877A or you can select from the  list of drop down menu.

 

3.IC_SELECT

 

Now select the Tool as PICKIT2 . Other options are PICKIT3,REAL ICE & Simulator.In this demo we’re using a PICKIT2 hardware.

 

4.PICKIT2

 

Next is the selection of Compiler.You can see a list of compilers installed including MPASM (assembly language) . MPLABX allows usage of old HITECH C compiler also.

The XC8 will show up in the list if you had installed it correctly.

Select the XC8 compiler.

  

5.COMPILER

 

Now provide a Project name “LedBlink” & click on Browse to select a location to store the Project.

Click on Finish.

 

6.projnme

 

The MPLAB project IDE opens with 4 panes.FILE pane, Navigation pane, Editor pane & Task pane.

Inside FILE pane you can see your project LedBlink.

 

7.panes

 

To write the C code we need to create a C main file.

Right click on Source Files & click on New—> C Main File

 

8.CFILE

 

Provide a File name & ensure that the Extension is .c

Do not add the .c extension next to your filename.It is selected from the drop down menu of Extension, seen below the Filename.

 

9..cfile

Click on Finish to see the code window on Editor pane.

You can just delete the default code presented ( the #include declarations & int main statements)

 

10.screen

 

Before writing the main code we’ve to program the configuration bits.Click on

Window –> PIC Memory Views –> Configuration Bits

 

10.1.confign

On the Task Pane area at the bottom the Configuration options are displayed.

 

10.2

 

As we’re using an external High frequency crystal on the Demo board , select from the drop down menu against FOSC as HS .

Other options you can leave for defaults.But the LVP should be selected OFF.

Now click on the button which says “ Generate Source Code to Output”

 

10.3

 

You can now see the Configuration code generated as per your settings.

 

11.cofigcode

 

Copy the Configuration code generated & paste it on to the Code window of Editor pane .

 

12.paste

 

Before the #include <xc.h> statement you’ve to define the crystal frequency.

#define _XTAL_FREQ 16000000

In this demo an external crystal value of 16MHz is used.This must be declared by the #define statement.If you miss this statement , any Delay statements in your code will show up a red squiggly mark.

 

13.define

 

Now type in the following code just below the configuration code.

—————————————

int main()
{
    TRISD7=0;                  //RD7 declared as Output pin
    while(1)
    {
    RD7=1;                     //make RD7 pin High to glow LED
    __delay_ms(1000);  // 1 second delay
    RD7=0;                    // make RD7 pin Low to Off LED
    __delay_ms(1000);

    }
return 0;

}

——————————————–

Port pin RD7 is declared as Output by TRISD7 = 0

Never ending loop starts by while (1)

RD7 is made High by RD7=1 ,in turn makes the LED glow.

A delay of 1 second is given by __delay_ms(1000)  Note the usage of double underscore before delay statement.

RD7 pin is then made low by RD7=0 , switching OFF the LED.

Again a delay of 1 sec is given.

The never ending loop repeats , as a result you see the LED blinking at 1 sec interval.

 

14.prog

Click on Run —> Build Main Project  to build the project.

 

15.build

If you’ve followed the Syntax properly , you can see Build Successful

 

16.SUCCESS

Now click on Run –> Run Main Project 

 

17.led

MPLABX will connect to the hardware PICKIT2 & program the target IC .The .Hex file is loaded on to the Target IC & you can see the LED connected at port pin RD7 blinking.

The .hex file generated is located at folder

projects->ledblink.X->dist->default->production

Image 11

Below is the picture of Development board connected with PICKIT2 .An LED is wired to port pin RD7 .

IMG

 

Watch this Tutorial Video :

PIC TUTORIALS–MPLABX WITH XC8 & YOUR FIRST C PROGRAM

In this blog series I’ll post tutorials on using PIC16F877A .You’ll learn the basics starting from installation of the new MPLABX IDE along with the C compiler XC8 .

Further you’ll learn all demo programs like blinking LED, driving a 7 segment display, driving a relay,driving a servo motor,controlling a stepper motor, interfacing keypad matrix, interfacing 16 x 2 LCD, UART control for serial communication,etc.,

To start with we shall walk through the installation of IDE with XC8 compiler.

Download the MPLABX IDE  (375 Mb)  from :

http://www.microchip.com/mplabx-ide-windows-installer

& XC8 compiler (180 Mb) for 12F,16F,18F series of PIC controllers from :

http://www.microchip.com/mplabxc8windows

MPLAB XC Compiler licenses are available as Free editions and have the option of a 60-day PRO evaluation trial.After trial time you can continue using the compiler but without optimization .i.e your final hex  code will be larger.

Following is the screenshot of the installer files downloaded for MPLABX installation.

  Image 1

Double click on MPLABX installer application (version 2.26 at the time of this post) .

Setup window opens up.Leave the installation directory to default settings C:\ProgramFiles\Microchip\MPLABX

 

Image 2            Image 3

           

Select both the IDE and IPE .Click on Next button to start installing the IDE.

 

Image 4      Image 5

 

Once the installation is over you’ll be guided to download XC8 compiler if the XC compiler button is checked.

Image 6     Image 7

Now double click the XC8 compiler installer application

 

Image 8            Image 9

 

Leave the installation directory to default.

               Image 10    

On the next screen select all the options as Compiler settings.

      Image 11

 

 

 

Image 12           Image 13

 

Once the installation is completed you can see the MPLABXIDE & MPLABXC8 folders under All Programs.

 

Image 14      Image 15

 

Click on the MPLABX IDE v2.26 to start the IDE.

 

Image 16

 

In the next post we shall see how to blink an LED , a HELLO WORLD program to start with any Microcontroller.

To transfer the HEX file on to PIC Flash memory you need a programmer like PICKIT2 or PICKIT3.As a student you may not wish to shell out the bucks to buy one.The solution is PIC BOOTLOADER & this post is a tutorial on how to implement Boot loader on a PIC16F877A chip.

Remember that the Boot loader itself must be fused on to the Flash memory using an external programmer like PICKIT2.Once the chip is boot loaded the external programmer is not needed for further programming.

Whenever  a boot loaded chip is re started ,the program counter jumps to the boot loader section & waits for the instruction which is fed through the serial communication port.A Bootloader is the first program which executes (before the main program) whenever a system is initialized. In case there is no communication in the serial port, the program counter will jump to the preloaded program at 0000H & executes the program.

Mostly the bootloader resides in the bottom most area of the ROM but there are some cases where the boot loader can be configured in the top (like in PIC18F).The starting and ending address of the bootloader in the ROM depends on the product.

TINY BOOTLOADER is one such loader for PIC 16F & 18F ICs.

As all other bootloaders, this  consists of a Windows application running on the PC and boot loader firmware running on the target PIC chip.

Download the boot loader zip file from :

http://www.etc.ugal.ro/cchiculita/software/tinybld198.zip

 

Features of the firmware
  • Size of only 100 words; (all versions, for 16F,18F,dsPIC occupy less than 100 words);
  • Can write flash, eeprom and configuration bytes(18F);
  • On reset, waits 1 second (adjustable) for a message from the PC, if not received, launch user application;
  • The .asm file can be easily modified and adapted for any frequency (or baudrate);
    Unzip the downloaded TINY PIC BootLoader.Under the folder named “picsource” is given the Boot loader Hex files for PIC16F & PIC18F ICs.Select 16f & then select the hex file “tinybld_16F876A_20MHz.HEX “ .
    This is the boot loader firmware compatible to PIC16F877A .The selection of crystal frequency 20MHz is important & ensure that the target board uses the same value crystal 20MHz. 
    The “tinybldWin” found in the top folder is the Windows application through which you can load the HEX file on to the arget chip PIC16F877A.

New Windows application can be  downloaded from :

http://www.etc.ugal.ro/cchiculita/software/TinyBld_1_10_6_pc_beta.zip

TINY2

To fuse the Boot loader firmware on to the target chip you need PICKIT2 hardware.

 

pickit2

 

Place the PIC16F877A chip on to the ZIF socket of PICKIT2 programmer (pin 1 always near the handle).Start the application PICKIT2.

The hardware is detected automatically and  device name is displayed PIC16F877A.

Image 2

Click on File –> Import HEX

Image 3

Browse to the location where you’ve unzipped the downloaded folder & select the firmware Hex file

“tinybld_16F876A_20MHz.HEX “ .

The document of TINY BOOTLOADER says this is the matching firmware for PIC16F877A

Image 4

Click on WRITE to fuse the firmware n to the target chip.

 

Image 5

Now your PIC IC is BOOT LOADED & ready to accept your Program Hex files through the Serial port.

Image 6

To load your program HEX files you need an USB to UART converter.Here I’ve used one built on Silicon Labs CP2102.

The converter is connected to PC using USB cable.A RS232 STRAIGHT cable is used to connect the Target board with UART converter. 

photo

 

Check out the connections between PIC & MAX232 ICs on your target board.

RC6 (PIN 25) should go to pin 11 of MAX232

RC7 (PIN 26) goes to PIN 12 of MAX 232.

PIN 13 of MAX 232 goes to pin 3 of the DB9 connector.

PIN 14 of MAX232 goes to pin 2 of DB9 connector.

Double check these connections, otherwise your Target chip won’t be detected by the Windows application.

 

Image 11

 

Now start the Windows application & click on CHECK PIC button.Your target chip is detected & displayed.The default Baud rate is 115200 .

You can also check the Search button to scan for the port where the Target board is connected.

 

Image 7

Click on BROWSE & navigate to the HEX file you’ve created using MPLAB.

Click on WRITE FLASH to fuse the HEX file on to the Target.

Image 8

Now the Boot loaded chip is fused with your program.On Power On restart the chip will start the Boot loader.After  1 sec wait , it will  launch your program.

 

cooltext753793315    cooltext753790696

 

PICKIT2 Lite is a clone hardware to fuse the HEX file on to the target PIC Microcontroller.The advantage of this USB Programmer is that you can program the HEX file from within the MPLAB IDE &  no standalone PICKIT2 software is required.

It is built on PIC18F2550 IC which is loaded with PIC Firmware & Boot loader.PIC18F2550  has an inbuilt USB interface avoiding the need for an external USB-UART circuit.

PICKIT2 Lite is an ICSP – In Circuit Serial Programmer 

 

              Picture 24

 

The 5 pins on PICKIT2 namely   VPP (MCLR) , VDD (+5V) , GND , DAT (PGD) , CLK (PGC)

are used for In Circuit Programming.While programming , a 12v is generated by PICKIT2 & applied to MCLR pin of PIC controller , while data flows in through PGD pin controlled by the PGC Clock cycle.

The AUX pin is used only with PIC microcontrollers that support LVP –Low Voltage programming.

 

The PICKIT2 programmer can be connected to a PIC DEMO Board using jumper wires according to following connection details. :

Image 1

 

As per above details connections to ICSP made & shown below:

 

Picture 25

 

Now you can open the project in MPLAB IDE & from within the MPLAB IDE you can initiate PICKIT2 & Program the HEX code on to the Flash ROM of PIC chip.

Connect USB cable to PC.Open the project in MPLAB IDE.

Under Programmer –> Select Programmer –> Select PICKIT2

Image 3

 

If PICKIT2 is not detected automatically , click on Programmer – > Connect

Image 4

Your hardware will be detected .The IC placed on the ZIF socket is also detected.

 

Image 5

Now you can click on Programmer –> Program to fuse the HEX file on to the PIC microcontroller.

 

Image 6

 

Watch this support Video :

 

PICKIT2 Lite – PIC USB PROGRAMMER

cooltext753793315   cooltext1137713216

TROUBLESHOOTING GUIDE

————————————-

 

In this post we shall discuss the following common problems faced by newbies & their solutions.

1. My   .c  file is not showing under Source files.

2. After selecting HITECH UNIVERSAL TOOLSUITE from under Toolsuite Contents , there is an X mark seen near the Location.

3. I do not see the .HEX file generated.

4. My Build is successful. Fusing of HEX file is ok , but my project is not working.

5. PICKIT2 complains that there is no Configuration bits ,while importing HEX file.

 

1. When you try to add your C code file .c by right clicking Source files , it lands up under Other Files.The reason is , you’ve not selected the Tool suite for HITECH C compiler & it is in Microchip ASM tool suite for Assembly language.Unless you select the Hitech C you can’t add a .c file to Source files.

 

Image 1

Open your Project & select from

Project –> Select Language ToolSuite

Under Active Toolsuite select the HITECH UNIVERSAL TOOLSUITE

Image 3

 

Now your .c file will appear under Source Files.

 

2. You see an X mark near the Location while selecting Hitech Universal Toolsuite.

The reason is that while installing the HITECH  C Compiler you’ve selected a different location other than C:  or you might not have checked the “Set environment path “ while installing Hitech C compiler.

Click on browse next to Location bar &  go to the location where you’ve installed  the C compiler & select it.

By default it is under location

Image 3

Under /bin folder the executable C compiler file is picc.exe

 

Image 1

 

3.  Your BUILD is successful , but you do not see the HEX file.

 

Image 4

 

The HEX file generated along with other files inside the Project folder. But you do not see the extension .hex

Go to Tools –>  Folder Options  of the Windows Explorer .

 

Image 5

 

Under VIEW tab Un tick  “Hide extensions for known file types “ & click OK.

 

Image 6

 

Now you can see the .hex file.

 

Image 7

 

4 & 5 .  Setting the  Configuration bits & including it in the C code is important.

 

Under Configure select Configuration Bits.

A new window opens. Uncheck the box “Configuration Bits set in code “ to enable editing the bits.

 

Image 8

 

By default the Oscillator is set to RC Oscillator.But in your project you use an external crystal of 8 or 20MHz.From the drop down menu select HS Oscillator which stands for usage of High Frequency oscillator.

Disable Watch Dog timer,Power up timer & Brown out Reset.

 

Image9

Generally LVP (Low Voltage Programming) is not used .So select  “RB3 is Digital I/O,HV on MCLR must be used for programming “  .

The final hex value is generated & shown under Value .(3F3A)

 

Image10

This Hex value should be added in your CONFIG statement of C code.Note the usage of two underscores __ before CONFIG.

 

Image11

 

Now build your project to generate HEX code with Configuration bits.

 

Watch this support video :

 

Solution to common problems while programming PIC

cooltext1137713216

HANDS ON HARDWARE

————————————-

 

In the previous post we’ve created a .HEX file from C code.

Now we shall see how to fuse that file on to the PIC 16F877A IC using PICKIT2 clone hardware & finally displaying the result using a Demo project board.

 

Picture 15

The PICKIT2 clone hardware is shown in picture above.It has an inbuilt PIC18F2550 controller loaded with bootloader & firmware.It is an USB device and doesn’t need any external power source.

The ICSP (In Circuit Serial Programming) connector is converted to a 40 pin ZIF socket using a Flasher board.This PICKIT2 clone has also an inbuilt voltage converter to apply 12v DC to MCLR pin of PIC IC while fusing the HEX file.

You need to download the PICKIT2 standalone software from here.

Open the PICKIT2 software.If the hardware is already connected to your PC , it will automatically detect it.

You can also detect the hardware manually from Tools –> Check Communication

Image 1

Select the project IC from the drop down menu , here it is PIC16F877A.

 

Image 2

 

The supply voltage changes to 5.0 .

Place the 40 pin IC on to the ZIF SOCKET of FLASHER BOARD. Ensure that pin 1 of IC is near the handle of ZIF socket & the selection switch on flasher board is set to 40 pin.

Image 3

 

Click on Import Hex under File & browse to the location where the .HEX file is stored.This file is created in MPLAB IDE  as in previous post.

Image 4

Image 5

When you see “Hex file successfully imported “ , click on Write to fuse the HEX file on to the PIC IC.

Green LED on PICKIT2 hardware changes to RED while it is fusing the file.

 

Image 6

 

After Programming is successful you can remove the IC from the ZIF socket & use it in your project.

Picture 20

 

 

Watch this support video for this post :

 

 

Hands on Hardware–PICKIT2 & Demo Board usage

cooltext1137713216