6678359 Programming PIC16F877A Using CCS C Compiler and USBurn

Embed Size (px)

Citation preview

  • Programming PIC16F877A

    Using CCS C Compiler and US-

    Burn

  • Why Use C for Embedded Programming?

    1. Portable code can be retargeted to different processors

    2. Clarity C is easier to understand than assembly

    3. Compilers produce code that is close to manually-tweaked assembly language in both code size and performance

  • From .c to .hex

  • C Compilers for Embedded Systems

    CCS C Compiler HI TECH Compiler

  • CCS vs. HI TECH

    The CCS Compiler has an extensive range of inbuilt functions Save time and speed up the learning process

    The HI TECH Compiler is based towards those who are following a company policy specifying the ANSI standard with hardware functions sometimes resembling Assembler more than C

  • Installing CCS C Compiler IDE

    Copy CCS C directory to your hard drive Run pcwhupd.exe (in this directory) Copy the following files to installed directory

    : PCM.CRG for 16-bit PIC , PCH.CRG, PCB.CRG

    Run Patch.exe file Run Pcw.exe file

  • Installing US-Burn

    1. Copy USB burn driver directory to your harddrive

    2. Plug USB cable (connected to the USB port of SaigonTech PIC Board) to computer USB port

    3. Turn on the power switch on the PIC board (see the next slides)

  • \USB burn driver

    Click the Browse button to select the driver folder

  • Succefull installation announce

    Do the steps 2 and 3 for other USB ports.

  • A Sample C Program:

    Blinking 8 LEDs

  • Program Description

    Make LEDs on PORTB blink every second

  • Cable Wiring

    Use a 8 pin ribbon cable to connect PICs jumpers B0 B7 to LEDs jumpers L0 L7

  • Electronic Circuit

  • Writing Program in PCW C

    Compiler IDE

  • Creating a .c File

  • Creating a .c File

    File name: Blink8LEDs Choose the path Click Save

  • Editing Blink8LEDs.c

  • Compiling a C Program

  • Using US-Burn to Load a .hex

    File to the PIC

  • Put 16F877A in the USB Programmer socket (pay attention to the PIC direction on the socket, otherwise you will damage the PIC)

    Plug the USB cable to the PC and to the PIC board

    Turn on the power switch of PIC Board Run Usburn14.exe

  • Microcontroller Setting

  • Run program on the board

  • Turn off the power switch on the PIC board Put the programmed PIC in the Run socket

    on the board (pay attention to the PIC direction on the socket, otherwise you will damage the PIC)

    Turn on the power switch on the PIC board to see the LEDs blink.

  • Summary of the

    Development

    Process

    PIC C

    PIC C

    PIC C

  • Discussion

  • Look at an Alternative of BlinkLEDs.c

    Is this listing better than the previous one? Why?

  • One of the Most Important Skills in

    Programming

    Reuse

  • PIC16F877A

    5/6 Programming pins8 10-bit A/D channels2 Oscillator Inputs2 RS-232 inputs33 I/O ports2 PWM channels

  • The PIC16F877A

    PIC: Peripheral Interface Controller

  • Pin Functions

    MCLR to reset the PIC VDD power supply VSS ground OSC1, OSC2 connect to oscillator The pins having the notation R can all be

    used as digital inputs or outputs The pins that are labeled as AN can be used

    as analog inputs The pins CCP1 and CCP2 are used for PWM

  • Exercise

    1. Delete NOLVP from #fuses and rerun the program. What is the effect of this action?

    2. Instead of using the PORTB, use PORTC to rewrite the example

    Try to use NOLVP and without it

  • Why is NOLVP Needed?

    In Single Supply Programming or Low Voltage Programming mode (using single voltage VDD 5V to programming): The LVP bit will be set Pin B3 will have PGM function B3 is cleared

    To make RB3 become a normal I/O pin, LVP has to be disabled #fuses NOLVP

  • Exercise

    Instead of using the PORTB, use PORTA to rewrite the example

  • More Details on PORTA In the PIC16 series Port A is the analog port

    connected to the analog to digital converters By default this port is configured as analog You will not be able to output or input data reliably

    on Port A until you configure it as a digital portPin RA4

    PIC 16F877A

    Cant work

    R

    VDD

  • How to Make RA4 Work Properly

    RA4 is made to be an open-drain output A pull-up resistor is needed to make it work

    properly

    Pin RA4

    PIC 16F877A

    Cant work R

    VDD

    Pin RA4

    PIC 16F877A

    Open-drain output

    Pull-up Resistor

  • References

    Microcontroller. http://www.electronics.netmyne.com/microcontroller.html

    Programming PIC Microcontrollers in BASIC. mikroElektronika 1998 2004. http://www.mikroelektronika.co.yu/english/product/books/picbasicbook/00.htm#preface

    http://www.picvietnam.com/forum//showthread.php?t=357

    PICC. An introduction to programming the Microchip PIC in C. Nigel Gardner. Bluebird Electronics 1998