CCS PIC 'C' Compiler Tutorial

April 5, 2017 | Author: adeel_anwar | Category: N/A
Share Embed Donate


Short Description

Download CCS PIC 'C' Compiler Tutorial...

Description

IN THE NAME OF ALLAH, THE MOST GRACIOUS, THE MOST MERCIFUL

CCS PIC “C” COMPILER TUTORIAL

Created on : 2nd

MAY 2010

ADEEL ANWAR (adeelanwr@gmail 69th E.C.com) COLLEGE OF AERONAUTICAL ENGEENERING CAE

• I am making this tutorial with the motivation that, it will be helpful for the fellow students and it’s a small contribution toward students society. • • I hope and expect that the students coming afterwards will contribute further and we will improve collectively by helping each other. COLLEGE OF AERONAUTICAL ENGEENERING CAE

CONTENTS • • • • •

Basic Tutorial Pic wizard Pic Device Selector Fuses and Interrupts list Serial Port Moniter Note : “Basic Tutorial” (for Beginners) is sufficient for creating and compiling the complete project. Next topics (Pic wizard & onwards) describe the extra utilities provided by the compiler that make some tasks easier. COLLEGE OF AERONAUTICAL ENGEENERING CAE

Basic Tutorial Creating new Project Adding Source file Writing and editing source file Compilation RAM/ROM percentage View generated assembly code (optional) • Generated files • • • • • •

COLLEGE OF AERONAUTICAL ENGEENERING CAE

ADD SOURCE FILE TO THE PROJECT

WE WANT TO CREATE A NEW PROJECT

COLLEGE OF AERONAUTICAL ENGEENERING CAE

WRITE NAME OF SOURCE

FILE

COLLEGE OF AERONAUTICAL ENGEENERING CAE

BLANK SOURCE FILE “prg2.c”

START WRITING CODE

COLLEGE OF AERONAUTICAL ENGEENERING CAE

ADER FILES SPECIFING

“CHIP NO” ,

“CRYSTAL FREQUENCY”

MAIN LOOP

INFINITE LOOP TO MAKE

u-CONTROLLER WORK FROM POWER ON TILL OFF

COLLEGE OF AERONAUTICAL ENGEENERING CAE

&

E “-” SIGNS WITH “main” “while”

AND “for”

GENERALLY THESE SYMBOLS ARE ATTACHED TO ALL THE “LOOPS STATEMENTS INSIDE “{ }”

THERE IS ALSO AN ENDING SYMBOL

COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK ON “-” SIGN

COLLEGE OF AERONAUTICAL ENGEENERING CAE

SIGN CHANGES TO “+” AND ALL THE STATEMENTS INSIDE “for” LOOP ARE MINI

USE OF THESE SMALL TIPS MAKES THE CODE MORE READABLE AND EASIER TO DEBUG COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK (1)

CLICK (2)

WE HAVE WRITTEN THE CODE NOW WE WANT

COLLEGE OF AERONAUTICAL ENGEENERING CAE

TO COMPILE IT

COMPILATION IN PROGRESS

OW MUCH RAM OR ROM OF MICROCONTROLLER, THE WRITTEN CODE WILL USE

s this is a small program and it is not consuming much

Ram/Rom of “16F628A” so, 16

COLLEGE OF AERONAUTICAL ENGEENERING CAE

IS COMPLETE ERRORS OR WARNINGS WILL APPEAR HERE. IF ANY ERROR THEN PROGRAM NEEDS

COLLEGE OF AERONAUTICAL ENGEENERING CAE

IF USER WANT TO SEE THE ASSEMBLY CODE GENERATED BY WRITTEN “C” CODE

COLLEGE OF AERONAUTICAL ENGEENERING CAE

THE “C” STATEMENT “output_D(0)” IS CONVERTED TO FOUR ASSEMBLY STA

TS (ALTHOUGH THERE ARE SOME COMMENTS LINES). DUE TO THIS REASON NOWADAYS u-CONTROL

COLLEGE OF AERONAUTICAL ENGEENERING CAE

COF

FILE

SOURCE FILE

HEX

HEADER

FILE (2ND C FILE AMONG ALL FILES)

COLLEGE OF AERONAUTICAL ENGEENERING CAE

FILE

PIC WIZARD

COLLEGE OF AERONAUTICAL ENGEENERING CAE

INTRODUCTION • Pic wizard is a useful tool that helps the user for initializing peripherals and writing code for PIC u-Controller. • • Different peripherals options/settings are presented in form of Graphical User Interface (GUI). • • It creates the basic layout of the code that include different interrupt service routines, initialization parameters for timers, interrupts and other device peripherals etc. COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK (1)

CLICK (2)

COLLEGE OF AERONAUTICAL ENGEENERING CAE

WRITE NAME OF SOURCE FILE COLLEGE OF AERONAUTICAL ENGEENERING CAE

WIZARD WINDOW

FEATURES WINDOW

FEATURES OPTIONS WINDOW

COLLEGE OF AERONAUTICAL ENGEENERING CAE

GENERAL (1)

SELECT DEVICE

NOTE : ALL FURTHER FEATURE SELECTION OPTIONS WILL BE

COLLEGE OF AERONAUTICAL ENGEENERING CAE

OSCILLATOR

TART-UP /PROGRAMMING OPTIONS

COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK (1) USER

SELECT

WANTS TO USE RS-232

RS-232 OPTIONS

COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK (1)

TIMER 1 DISABLED

TIMER 0 WITH .2 us Resol. AND 51.2

us OVERFLOW TI

TIMER 2 DISABLED

COLLEGE OF AERONAUTICAL ENGEENERING CAE

NOTE: RESOLUTION EFFECTS OVERFLOW TIME (COMP TIMER 1 ENABLED

TIMER 1 SETTINGS COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK (1)

R SETTINGS GENERATES A CODE THAT WILL BE ADDED TO SOURCE FILE AT THE END OF WIZAR

COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK (1) CURRENTLY 8-BIT

(0-255) MODE IS SELEC

LECT A/D CONVERTERS

COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK (1) SELECT INTERRUPTS

COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK (1)

AS WE HAVE SELECTED EXTERNAL INTERRUPT (PREVIOUS PAGE). THIS CODE WILL BE A

COLLEGE OF AERONAUTICAL ENGEENERING CAE

IF THERE ARE NO MORE FEATURES THAT USER WANT TO USE CLICK “OK”

COLLEGE OF AERONAUTICAL ENGEENERING CAE

WRITE EXTERNAL INTERRUPT SERVICE ROUTINE

INITILIZATION CODE

GENERATED BY WIZARD TO SET

REQUIRED PARAMETERS OF TIMER/INTE

COLLEGE OF AERONAUTICAL ENGEENERING CAE

THERE IS AN INCLUDE FILE (HEADER FILE) AT THE BEGINNING OF E

START WRITING CODE HERE (MAIN LOOP etc.)

COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK

(1) CLICK

(2)

HEADER FILE HAS INFORMATION

ABOUT THE SELECTED DEVICE,CLOCK,RS-232 PIN

COLLEGE OF AERONAUTICAL ENGEENERING CAE

ECOND “C FILE” IN THE LIST IS HEADER FILE (CLICK)

COLLEGE OF AERONAUTICAL ENGEENERING CAE

“prog1.h” IS HEADER FILE.

:

THIS FILE IS CREATED SEPERATELY SO THAT READABILITY OF THE “source file” IS IM COLLEGE OF AERONAUTICAL ENGEENERING CAE

CCS PICC DEVICE SELECTOR

COLLEGE OF AERONAUTICAL ENGEENERING CAE

INTRODUCTION • A large PIC family provides user, the flexibility to select the chip which fulfill the requirement optimally.

• • The devices which have large features are more costly. So, from Economical point of view, select the device which only has those features that the design requires.

• • Device Selection Tool is helpful in selecting the appropriate chip which meets the COLLEGE OF AERONAUTICAL ENGEENERING CAE design requirement .

CLICK

CLICK

(1)

(2)

COLLEGE OF AERONAUTICAL ENGEENERING CAE

“SELECTED”

SHOWS THE CHIPS WHICH FULFILL

ITERIA” CONSISTS OF THE MINIUM FEATURES THE CHIP SHOULD

SPECIFY

HAVE

THE PIC FAMILY THE SELECTED CHIP SHOULD BELONG. COLLEGE OF AERONAUTICAL ENGEENERING CAE

PORT SO, WE CHANGE “Don’t Care” TO

“Yes”

SELECTED DEVICES ALL HAVE USB PORT AND THEY BELONG TO PIC 14-16 BIT COLLEGE OF AERONAUTICAL ENGEENERING CAE

Min.

256 Byte RAM AND 8 KB ROM (8192 Bytes) IS REQUIRED

ANOTHER REQUIREMENT

IS OF 8-12 A/D CONVERTERS ALL THESE CHIPS

COLLEGE OF AERONAUTICAL ENGEENERING CAE

SHOWN FULFILL

ED” LIST ARE LIMITED. IF WE WANT

SEE ALL THE FEATURES OF A PARTICULAR CHIP e.g. 16

COLLEGE OF AERONAUTICAL ENGEENERING CAE

ALL

FEATURES OF 16F877

CLICK (1)

COLLEGE OF AERONAUTICAL ENGEENERING CAE

16F877 HAVE

TIMER 1 & 2 ONLY . ALL PIC CHIPS HAVE T

COLLEGE OF AERONAUTICAL ENGEENERING CAE

FUSES AND INTERRUPTS LIST • This tool of the compiler can be used to see the fuses and interrupts that can be used for a specific device. • • Thus, it provides a quick glance, at the fuses and interrupts options available for a particular Pic device, instead of tedious search in the device data sheet COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK (1)

CLICK (2)

COLLEGE OF AERONAUTICAL ENGEENERING CAE

SELECT DEVICE (e.g. 16F877)

COLLEGE OF AERONAUTICAL ENGEENERING CAE

ALL THESE FUSES CAN BE USED FOR SELECTED DEV

FOR FUSES DETAIL REFER TO BOOK “PROGRAMMING 8 BIT PIC u-CONTROLLER ” M. P Bates COLLEGE OF AERONAUTICAL ENGEENERING CAE

(

CLICK (1)

COLLEGE OF AERONAUTICAL ENGEENERING CAE

SELECT DEVICE

ALL THE INTERRUPTS THAT CAN BE USED F

COLLEGE OF AERONAUTICAL ENGEENERING CAE

SERIL PORT MONITER 

This tool works same as hyper terminal but in new windows (vista and later) there is no hyper terminal so this tool can be used to send/receive data to/from the computer serial port. COLLEGE OF AERONAUTICAL ENGEENERING CAE

CLICK (1)

CLICK (2)

COLLEGE OF AERONAUTICAL ENGEENERING CAE

SELECT COM PORT

BAUD RATE

COLLEGE OF AERONAUTICAL ENGEENERING CAE

RECEIVED DATA APPEAR HERE TYPE DATA TO SEND TO SERIAL PORT

COLLEGE OF AERONAUTICAL ENGEENERING CAE

END

Don't blame the unfavorable circumstances that stops you from doing what needs to be done as "the key lies in our decision not our condition" (Everyday Greatness)

COLLEGE OF AERONAUTICAL ENGEENERING CAE

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF