programming pic16f877a using ccs c compiler and us-burn
TRANSCRIPT
![Page 1: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/1.jpg)
Programming PIC16F877A
Using CCS C Compiler and US-
Burn
![Page 2: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/2.jpg)
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
![Page 3: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/3.jpg)
From .c to .hex
![Page 4: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/4.jpg)
C Compilers for Embedded Systems
� CCS C Compiler
� HI TECH Compiler
![Page 5: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/5.jpg)
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
![Page 6: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/6.jpg)
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
![Page 7: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/7.jpg)
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)
![Page 8: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/8.jpg)
![Page 9: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/9.jpg)
…\USB burn driver
�Click the Browse button to select the driver folder
![Page 10: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/10.jpg)
![Page 11: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/11.jpg)
![Page 12: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/12.jpg)
![Page 13: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/13.jpg)
![Page 14: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/14.jpg)
Succefull installation
announce
�Do the steps 2 and 3 for other USB ports.
![Page 15: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/15.jpg)
A Sample C Program:
Blinking 8 LEDs
![Page 16: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/16.jpg)
Program Description
� Make LED’s on PORTB blink every second
![Page 17: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/17.jpg)
Cable Wiring
� Use a 8 pin ribbon cable to connect PIC’s
jumpers B0 – B7 to LEDs’ jumpers L0 – L7
![Page 18: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/18.jpg)
Electronic Circuit
![Page 19: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/19.jpg)
Writing Program in PCW C
Compiler IDE
![Page 20: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/20.jpg)
Creating a .c File
![Page 21: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/21.jpg)
Creating a .c File
� File name: Blink8LEDs
� Choose the path
� Click Save
![Page 22: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/22.jpg)
Editing Blink8LEDs.c
![Page 23: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/23.jpg)
Compiling a C Program
![Page 24: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/24.jpg)
Using US-Burn to Load a .hex
File to the PIC
![Page 25: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/25.jpg)
� 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
![Page 26: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/26.jpg)
Microcontroller Setting
![Page 27: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/27.jpg)
![Page 28: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/28.jpg)
![Page 29: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/29.jpg)
![Page 30: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/30.jpg)
![Page 31: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/31.jpg)
Run program on the board
![Page 32: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/32.jpg)
� 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.
![Page 33: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/33.jpg)
Summary of the
Development
Process
PIC C
PIC C
PIC C
![Page 34: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/34.jpg)
Discussion
![Page 35: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/35.jpg)
Look at an Alternative of BlinkLEDs.c
� Is this listing better than the previous one? Why?
![Page 36: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/36.jpg)
One of the Most Important Skills in
Programming
� Reuse
![Page 37: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/37.jpg)
PIC16F877A
5/6 Programming pins
8 10-bit A/D channels
2 Oscillator Inputs
2 RS-232 inputs
33 I/O ports
2 PWM channels
![Page 38: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/38.jpg)
The PIC16F877A
� PIC: Peripheral Interface Controller
![Page 39: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/39.jpg)
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
![Page 40: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/40.jpg)
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
![Page 41: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/41.jpg)
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
![Page 42: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/42.jpg)
Exercise
� Instead of using the PORTB, use PORTA to rewrite the example
![Page 43: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/43.jpg)
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 port
Pin RA4
PIC 16F877A
Can’t work
R
VDD
![Page 44: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/44.jpg)
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
Can’t work R
VDD
Pin RA4
PIC 16F877A
Open-drain output
Pull-up Resistor
![Page 45: Programming PIC16F877A Using CCS C Compiler and US-Burn](https://reader036.vdocuments.site/reader036/viewer/2022081716/5529067f4a7959a9158b4603/html5/thumbnails/45.jpg)
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