Pic Microcontrollers The Basics Of C Programming Language-Books Pdf

PIC Microcontrollers The basics of C programming language
24 Sep 2020 | 1 views | 0 downloads | 28 Pages | 968.17 KB

Share Pdf : Pic Microcontrollers The Basics Of C Programming Language

Download and Preview : Pic Microcontrollers The Basics Of C Programming Language

Report CopyRight/DMCA Form For : Pic Microcontrollers The Basics Of C Programming Language



Transcription

PIC Microcontrollers The basics of C programming language. References http www mikroe com and the Hi Tech C Manual. Table of contents, PROGRAMMING LANGUAGES 3, ADVANTAGES OF HIGHER PROGRAMMING LANGUAGES 6. PREPROCESSOR 6, PREPROCESSOR DIRECTIVE include 7, PREPROCESSOR DIRECTIVE define 7. THE BASICS OF C PROGRAMMING LANGUAGE 8, COMMENTS 10. DATA TYPES IN C LANGUAGE 10, VARIABLES 10, Declaring Variables 10. Pointers 11, Changing individual bits 11, Declarations 11.
CONSTANTS 12, INTEGER CONSTANTS 12, FLOATING POINT CONSTANTS 13. CHARACTER CONSTANTS ASCII CHARACTERS 13, STRING CONSTANTS 13. ENUMERATED CONSTANTS 13, OPERATORS OPERATIONS AND EXPRESSIONS 14. ARITHMETIC OPERATORS 14, ASSIGNMENT OPERATORS 14, INCREMENT AND DECREMENT OPERATORS 15. RELATIONAL OPERATORS 15, LOGIC OPERATORS 15, BITWISE OPERATORS 16.
HOW TO USE OPERATORS 16, DATA TYPE CONVERSION 17, CONDITIONAL OPERATORS 18. CONDITIONAL OPERATOR if else 18, Switch OPERATION 19. PROGRAM LOOP 20, While LOOP 20, For LOOP 21, Do while LOOP 21. WRITING CODE IN ASSEMBLY LANGUAGE 22, TWO DIMENSIONAL ARRAY 24. POINTERS 25, FUNCTIONS 26, DECLARATION OF A NEW FUNCTION 28.
FUNCTION LIBRARIES 28, EPAI Fribourg Herv Page support c odt ver 1 1. PIC Microcontrollers The basics of C programming language. References http www mikroe com and the Hi Tech C Manual. PROGRAMMING LANGUAGES, The microcontroller executes the program loaded in its Flash memory This is the so called executable code. comprised of seemingly meaningless sequence of zeros and ones It is organized in 12 14 or 16 bit wide. words depending on the microcontroller s architecture Every word is considered by the CPU as a command. being executed during the operation of the microcontroller For practical reasons as it is much easier for us. to deal with hexadecimal number system the executable code is often represented as a sequence of. hexadecimal numbers called a Hex code It used to be written by the programmer All instructions that the. microcontroller can recognize are together called the Instruction set As for PIC microcontrollers the. programming words of which are comprised of 14 bits the instruction set has 35 different instructions in total. As the process of writing executable code was endlessly tiring the first higher programming language. called assembly language was created The truth is that it made the process of programming more. complicated but on the other hand the process of writing program stopped being a nightmare Instructions in. assembly language are represented in the form of meaningful abbreviations and the process of their. compiling into executable code is left over to a special program on a PC called compiler The main. advantage of this programming language is its simplicity i e each program instruction corresponds to one. memory location in the microcontroller It enables a complete control of what is going on within the chip thus. making this language commonly used today, However programmers have always needed a programming language close to the language being used in. everyday life As a result the higher programming languages have been created One of them is C The. main advantage of these languages is simplicity of program writing It is no longer possible to know exactly. EPAI Fribourg Herv Page support c odt ver 1 1, PIC Microcontrollers The basics of C programming language. References http www mikroe com and the Hi Tech C Manual. how each command executes but it is no longer of interest anyway In case it is a sequence written in. assembly language can always be inserted in the program thus enabling it. Similar to assembly language a specialized program in a PC called compiler is in charge of compiling. program into machine language Unlike assembly compilers these create an executable code which is not. always the shortest possible, Figures above give a rough illustration of what is going on during the process of compiling the program from.
higher to lower programming language, EPAI Fribourg Herv Page support c odt ver 1 1. PIC Microcontrollers The basics of C programming language. References http www mikroe com and the Hi Tech C Manual. Here is an example of a simple program written in C language. EPAI Fribourg Herv Page support c odt ver 1 1, PIC Microcontrollers The basics of C programming language. References http www mikroe com and the Hi Tech C Manual. ADVANTAGES OF HIGHER PROGRAMMING LANGUAGES, If you have ever written a program for the microcontroller in assembly language then you probably know that. the RISC architecture lacks instructions For example there is no appropriate instruction for multiplying two. numbers but there is also no reason to be worried about it Every problem has a solution and this one. makes no exception thanks to mathematics which enable us to perform complex operations by breaking. them into a number of simple ones Concretely multiplication can be easily substituted by successive. addition a x b a a a a And here we are just at the beginning of a very long story Don t worry. as far as the higher programming languages such as C are concerned because somebody has already. solved this and many other similar problems for you It will do to write a b. PREPROCESSOR, A preprocessor is an integral part of the C compiler and its function is to recognize and execute preprocessor. instructions These are special instructions which do not belong to C language but are a part of software. package coming with the compiler Each preprocessor command starts with Prior to program compilation. C compiler activates the preprocessor which goes through the program in search for these signs If any. encountered the preprocessor will simply replace them by another text which depending on the type of. command can be a file contents or just a short sequence of characters Then the process of compilation. may start The preprocessor instructions can be anywhere in the source program and refer only to the part. of the program following their appearance up to the end of the program. EPAI Fribourg Herv Page support c odt ver 1 1, PIC Microcontrollers The basics of C programming language.
References http www mikroe com and the Hi Tech C Manual. PREPROCESSOR DIRECTIVE include, Many programs often repeat the same set of commands for several times In order to speed up the process. of writing a program these commands and declarations are usually grouped in particular files that can easily. be included in the program using this directive To be more precise the include command imports text from. another document no matter what it is commands comments etc into the program. PREPROCESSOR DIRECTIVE define, The define command provides macro expansion by replacing identifiers in the program by their values. define symbol sequence of characters, define PI 3 14. As the use of any language is not limited to books and magazines only this programming language is not. closely related to any special type of computers processors or operating systems C language is actually a. general purpose language However exactly this fact can cause some problems during operation as C. language slightly varies depending on its application this could be compared to different dialects of one. EPAI Fribourg Herv Page support c odt ver 1 1, PIC Microcontrollers The basics of C programming language. References http www mikroe com and the Hi Tech C Manual. THE BASICS OF C PROGRAMMING LANGUAGE, The main idea of writing program in C language is to break a bigger problem down into several smaller.
pieces Suppose it is necessary to write a program for the microcontroller that is going to measure. temperature and show results on an LCD display The process of measuring is performed by a sensor that. converts temperature into voltage The microcontroller uses its A D converter to convert this voltage. analogue value to a number digital value which is then sent to the LCD display via several conductors. Accordingly the program is divided in four parts that you have to go through as per the following order. 1 Activate and set built in A D converter, 2 Measure analogue value. 3 Calculate temperature, 4 Send data in the proper form to LCD display. As seen the higher programming languages such as C enable you to solve this problem easily by writing. four functions to be executed cyclically and over and over again. EPAI Fribourg Herv Page support c odt ver 1 1, PIC Microcontrollers The basics of C programming language. References http www mikroe com and the Hi Tech C Manual. The figure below illustrates the structure of a simple program pointing out the parts it consists of. EPAI Fribourg Herv Page support c odt ver 1 1, PIC Microcontrollers The basics of C programming language. References http www mikroe com and the Hi Tech C Manual. Page 10 28, Comments are part of the program used to clarify the operation of the program or provide more information.
about it Comments are ignored and not compiled into executable code by the compiler Simply put the. compiler can recognize special characters used to designate where comments start and terminate and. completely ignores the text inbetween during compilation There are two types of such characters One. designates long comments extending several program lines while the other designates short. comments taking up a single line Even though comments cannot affect the program execution they are. as important as any other part of the program and here is why A written program can always be improved. modified upgraded simplified It is almost always done Without comments trying to understand even the. simplest programs is waste of time, DATA TYPES IN C LANGUAGE. There are several types of data that can be used in C programming language A table below shows the. range of values which these data can have when used in their basic form. Any number changing its value during program operation is called a variable Simply put if the program adds. two numbers number1 and number2 it is necessary to have a value to represent what we in everyday life. call the sum In this case number1 number2 and sum are variables. Declaring Variables, Variable name can include any of the alphabetical characters A Z a z the digits 0 9 and the. underscore character The compiler is case sensitive and differentiates between capital and small. letters Function and variable names usually contain lower case characters while constant names. contain uppercase characters, Variable names must not start with a digit. Some of the names cannot be used as variable names as already being used by the compiler itself. Such names are called the key words, Type Size bits Arithmetic Type. bit 1 unsigned integer, char 8 signed or unsigned integer.
unsigned char 8 unsigned integer, short 16 signed integer. unsigned short 16 unsigned integer, int 16 signed integer. unsigned int 16 unsigned integer, short long 24 signed integer. unsigned short long 24 unsigned integer, long 32 signed integer. unsigned long 32 unsigned integer, float 24 real, double 24 or 32 real.
EPAI Fribourg Herv Page support c odt ver 1 1, PIC Microcontrollers The basics of C programming language. References http www mikroe com and the Hi Tech C Manual. Page 11 28, A pointer is a special type of variable holding the address of character variables In other words the pointer. points to another variable It is declared as follows. type of variable pointer name, In order to assign the address of a variable to a pointer it is necessary to use the character and write. variable name preceded by the character In the following example the pointer multiplex is declared and. assigned the address of the first out of eight LED displays. unsigned int multiplex Declare name and type of pointer multiplex. multiplex display1 Pointer multiplex is assigned the address of. variable display1, To change the value of the pointed variable it is sufficient to write the character in front of its pointer and. assign it a new value, multiplex 6 Variable display1 is assigned the number 6.
Similarly in order to read the value of the pointed variable it is sufficient to write. temp multiplex The value of variable display1 is copied to temp. Changing individual bits, There are a few ways to change only one bit of a variable The simplest one is to specify the register name. bit s position or a name and desired state, define RELAY RA0. RB3 0 Clear the bit 3 of PORTB, RELAY 1 Set the bit named RELAY. Declarations, Every variable must be declared prior to being used for the first time in the program Since variables are. stored in RAM memory it is necessary to reserve space for them one two or more bytes You know what. type of data you write or expect as a result of an operation while the compiler does not know that Don t. forget the program deals with variables to which you assigned the names gate sum minimum etc The. compiler recognizes them as registers of RAM memory Variable types are usually assigned at the beginning. of the program, unsigned int gate1 Declare name and type of variable gate1.
EPAI Fribourg Herv Page support c odt ver 1 1, PIC Microcontrollers The basics of C programming language. References http www mikroe com and the Hi Tech C Manual. Page 12 28, Apart from the name and type variables are usually assigned initial values at the beginning of the program. as well It is not a must do step but a matter of good habits In this case it looks as follows. PIC Microcontrollers The basics of C programming language References http www mikroe com and the Hi Tech C Manual Page 2 28 Table of contents

Related Books

AMPLIFICATEUR GUITARE

AMPLIFICATEUR GUITARE

l utilisation de l accordeur int gr de la p dale 04 CLASSIC ROCK 14 THRASH OVERKILL 24 VIBRA DOOM 05 DREAMY 15 CLEAN DELAY 25 SURF MUSIC 06 COUNTRY PICKING 16 OCTOBOT ONE NOTE 26 BLUES LEAD 07 SKATE PUNK 17 LITTLE CHAMP 27 ROCK A BILLY 08 SOLO MIDBOOST 18 PHASER SWIRL 28 GARAGE FUZZ 09 JAZZ AMP 19 60S FUZZ 29 SPACE TRAVEL 10 BRIT 64 RHYTHM 20 MYTHIC CRUNCH 30 ACOUSTIC SIM

OPERATING AND INSTALLATION

OPERATING AND INSTALLATION

vista classic le 220819 32 vista le vista classic le 100001219 operating and indices lectriques de soufflerie 115v 60hz 1 0 amp le fil lectrique ne doit pas tre plac sous le po te le fil lectrique ne doit pas tre plac sous le po le attention risque de temp ratures excessives gardes le tiroir de cendres ferm pendant l allumage du po te op rez

SVT 4 PRO Ampeg

SVT 4 PRO Ampeg

svt 4 pro bass guitar amplifier svt 4 pro bass guitar amplifier 3 consignes de securite importantes lire suivre toutes les instructions et les precautions d utilisation ne pas utiliser proche d une source de chaleur et ne pas bloquer ou obstruer le systeme de ventilation sur cet appareil pour une utilisation conforme cet appareil necessite environ 7cm d espace bien ventile autour

CONTRAT DE R SERVATION BOOKING CONTRACT ANN E 2020

CONTRAT DE R SERVATION BOOKING CONTRACT ANN E 2020

Entre 15h et 19h Between 3 p m and 7 p m Avant 11h Before 11 a m EMPLACEMENTS PITCHES Emplacement Premium 10 Amp Eau Electricit Inclus un point d eau et une vacuation des eaux us es un barbecue gaz un frigo 85 L avec freezer une table pique nique 2 bains de soleil parasol et 1h de WIFI par nuit r serv e

RECOMMANDATION DE BONNE PRATIQUE Syndrome du b b secou

RECOMMANDATION DE BONNE PRATIQUE Syndrome du b b secou

niveau de preuve 3 des tudes r trospectives des s ries de cas des tudes comparatives comportant des biais importants niveau de preuve 4 AE Accord d experts En l absence d tudes les recommandations sont fond es sur un accord entre experts du groupe de travail apr s consultation du groupe de lecture L absence de gradation

User s Guide Fishman Classic 4 C F Martin

User s Guide Fishman Classic 4 C F Martin

User s Guide Fishman Classic 4 www fishman com www martinguitar com User s Guide The Classic 4 system installed on this fine instrument offers the quality sound and versatile tone shaping that you expect from Fishman At the heart of the system is our classic equalizer which lets you zero in on the four key frequency bands for acoustic guitar The Classic 4 system utilizes the Fishman

ALL TUBE POWER AMP Peavey Electronics

ALL TUBE POWER AMP Peavey Electronics

CLASSIC SO 50 ALL TUBE POWER AMP A Intended to alert the user to the presence of uninsulated dangerous voltage within the product s enclosure that may be of sufficient magnitude to constitute a risk of electric shock to persons A Intended to alert the user to the presence of important operating and maintenance servicing instruc tions in the literature accompanying the product

GUITAR AMPLIFIER assets peavey com

GUITAR AMPLIFIER assets peavey com

Classic 50 212 410 GUITAR AMPLIFIER Confiez I entretien et la r paration de l appareil un r parateur Peavey agr AVIS Dans le but de reduire les risques d incendie ou de decharge electrique cet appareil ne doit pas etre expose a la pluie ou a l humidite et aucun objet rempli de liquide tel qu un vase ne doit etre pose sur celui ci Avant d utiliser de cet

Inner Manual on Concurrent Audit Banks 2016

Inner Manual on Concurrent Audit Banks 2016

thoroughly revised Manual on Concurrent Audit of Banks 2012 edition including the impact of various applicable new revised RBI Circulars issued during the period I congratulate CA Mukesh Singh Kushwah Chairman CA Anil S Bhandari Vice Chairman and other members of the Internal Audit Standards Board on issuance of this revised Manual I am sure that this revised edition would

POSB CBS Manual India Post

POSB CBS Manual India Post

POSB CBS Manual Note These rules apply to the Post Office Savings Accounts and also mutatis to 1 Post Office Savings Account 2 National Savings Recurring Deposit Account 3 National Savings Time Deposit Account 4 Public Provident Fund Account 5 National Savings Monthly Income Account 6 Senior Citizens Savings Scheme Account 7 Sukanya Samriddhi Account 8 Kisan Vikas Patra

CONTENTS NotePerformer

CONTENTS NotePerformer

SIBELIUS 6 To get NotePerformer playback in Sibelius switch to the NotePerformer configuration This configuration should appear automatically if you ve installed NotePerformer NotePerformer s instruments respond to reverb pan and volume from the Sibelius mixer Mixer settings are saved with your score By default reverb is 39 while pan and volume