SlideShare a Scribd company logo
Topic: Writing First C Program
PRESENTED BY:
A.PRIYANKA
Contents
 Basics of C program
 Basics of hardware specific code
Writing first C Program
Keil C is not much different from a normal C program.
If you know assembly, writing a C program is not a problem, only thing you
have to keep in mind is forget that your controller has general purpose registers,
accumulators or whatever.
But do not forget about Ports and other on chip peripherals and related registers
to them.
In basic C, all programs have atleast one function which is entry point for your
application that function is named as "main“ function.
Cont..
Similarly in keil, we will have a main function, in which all your application
specific work will be defined.
Lets move further deep into the working of applications and programs.
When you run your C programs in your PC or computer, you run them as a
child program or process to your Operating System so when you exit your
programs (exits main function of program) you come back to operating system.
Cont..
 Whereas in case of embedded C, you do not have any operating system running
in there.
 So you have to make sure that your program or main file should never exit.
 This can be done with the help of simple while(1) or for(;;) loop as they are
going to run infinitely.
To open a new file in Keil C:
Open Keil and Start a new project:
Cont..
You will prompted to chose a name for your new project, choose a name and
click save. The following window will appear, where you will be asked to
select a device for Target ‘Target 1′:
Cont..
From the list ,select ATMEL and chose your microcontroller .The AT89s52
will be called your ‘Target device’ ,which is the final destination of your
source code. You will be asked whether to copy standard 8051 startup code
click No.
Click file, New and similar to the following window should appear. The blank
space where your code should be written.
Cont..
From the list ,select ATMEL and chose your microcontroller .The AT89s52
will be called your ‘Target device’ ,which is the final destination of your
source code. You will be asked whether to copy standard 8051 startup code
click No.
Click file, New and similar to the following window should appear. The blank
space where your code should be written.
Cont..
Now, you have to click ‘File ‘,Save as and choose a file name for code ending
with the extension ‘.c’ and click save. Then you have to add this file to your
project work space as shown in the following screen:
Cont..
After right-clicking on ‘source group 1‘, click on ‘Add files to group…‘, then you will be
prompted to browse the file to add to ‘source group 1′, chose the file that you just saved and
add it to the source group. You will notice that the file is added to the project tree at the left.
In some versions of this software you have to turn ON manually the option to generate HEX
files. make sure it is turned ON, by right-clicking on target 1, Options for target ‘target 1′,
then under the ‘output‘ tab, by checking the box ‘generate HEX file‘. This step is very
important as the HEX file is the compiled output of your project that is going to be transferred
to the microcontroller.
Following layout provides a skeleton of Basic C program:
1.voidmain()
2.{
3. //Your one time initialization code will come here
4.while(1){
5. //while 1 loop
6. //This loop will have all your application code
7. //which will run infinitely
8. }
9.}
Writing first C Program
 When we are working on controller specific code, then we need to add header
file for that controller.
 After project is created, add the C file to project.
 Now first thing you have to do is adding the header file.
 All you have to do is right click in editor window, it will show you correct
header file for your project.
Figure bellow shows the windows context for adding header file to your c file.
Write an 8051 C program to send values 00 – FF to port P1:
#include <reg51.h>
void main(void)
{
unsigned char z;
for (z=0;z<=255;z++)
P1=z;
}
Write an 8051 C program to toggle bit D0 of the port P1 (P1.0)
50,000 times
#include <reg51.h>
sbit MYBIT=P1^0;
void main(void)
{
unsigned int z;
for (z=0;z<=50000;z++)
{
MYBIT=0;
MYBIT=1;
}
}
Write an 8051 C program to toggle bits of P1 continuously forever
with some delay
//Toggle P1 forever with some delay in between “on” and “off”
#include <reg51.h>
void main(void)
{
unsigned int x;
for (;;) //repeat forever
{
p1=0x55;
for (x=0;x<40000;x++); //delay size
//unknown
p1=0xAA;
for (x=0;x<40000;x++);
}}
Writing Hardware specific code
In hardware specific code, we use hardware peripherals like ports, timers and
USART etc.
Do not forget to add header file for controller you are using, otherwise you will
not be able to access registers related to peripherals.
Lets write a simple code to Blink LED on Port1,
Pin1.
Thank You..

More Related Content

What's hot (17)

Getting started with Keil uVision 2020
Getting started with Keil uVision 2020Getting started with Keil uVision 2020
Getting started with Keil uVision 2020
SaravananVijayakumar4
 
Common Programming Errors
Common Programming ErrorsCommon Programming Errors
Common Programming Errors
Nicole Ynne Estabillo
 
Devry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-startedDevry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-started
noahjamessss
 
Project eprom progr
Project eprom progrProject eprom progr
Project eprom progr
Anurag Farkya
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
rohassanie
 
C programming tokens & error types
C  programming tokens & error typesC  programming tokens & error types
C programming tokens & error types
argusacademy
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program execution
Rumman Ansari
 
OVERVIEW OF ‘C’ PROGRAM
OVERVIEW OF ‘C’ PROGRAMOVERVIEW OF ‘C’ PROGRAM
OVERVIEW OF ‘C’ PROGRAM
Sahithi Naraparaju
 
Reverse algorithm how_to_guide
Reverse algorithm how_to_guideReverse algorithm how_to_guide
Reverse algorithm how_to_guide
Lekh Raj Lalka
 
Session 1
Session 1Session 1
Session 1
pham vu
 
Lect '1'
Lect '1'Lect '1'
Lect '1'
reena0098
 
Algorithm
AlgorithmAlgorithm
Algorithm
Cambriannews
 
Debugging programs with Keil uVision
Debugging programs with Keil uVisionDebugging programs with Keil uVision
Debugging programs with Keil uVision
SaravananVijayakumar4
 
How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program
Leela Koneru
 
Devry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting startedDevry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting started
shyaminfo04
 
Enginex messaging
Enginex messagingEnginex messaging
Enginex messaging
Valentina Salihu
 
#Include
#Include#Include
#Include
Saurabh Chauhan
 
Getting started with Keil uVision 2020
Getting started with Keil uVision 2020Getting started with Keil uVision 2020
Getting started with Keil uVision 2020
SaravananVijayakumar4
 
Devry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-startedDevry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-started
noahjamessss
 
C programming tokens & error types
C  programming tokens & error typesC  programming tokens & error types
C programming tokens & error types
argusacademy
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program execution
Rumman Ansari
 
Reverse algorithm how_to_guide
Reverse algorithm how_to_guideReverse algorithm how_to_guide
Reverse algorithm how_to_guide
Lekh Raj Lalka
 
Session 1
Session 1Session 1
Session 1
pham vu
 
Debugging programs with Keil uVision
Debugging programs with Keil uVisionDebugging programs with Keil uVision
Debugging programs with Keil uVision
SaravananVijayakumar4
 
How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program
Leela Koneru
 
Devry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting startedDevry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting started
shyaminfo04
 

Similar to Writing first C Program (20)

Cp e 214_appendix_c
Cp e 214_appendix_cCp e 214_appendix_c
Cp e 214_appendix_c
basavaraju ramaduragam
 
ABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docxABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docx
ransayo
 
Introduction-to-Keil.ppt
Introduction-to-Keil.pptIntroduction-to-Keil.ppt
Introduction-to-Keil.ppt
akshatsharma823122
 
Devry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-startedDevry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-started
govendaagoovenda
 
C++ chapter # 1
C++ chapter # 1C++ chapter # 1
C++ chapter # 1
AliIjaz35
 
How to work with code blocks
How to work with code blocksHow to work with code blocks
How to work with code blocks
Tech Bikram
 
Programming in c_in_7_days
Programming in c_in_7_daysProgramming in c_in_7_days
Programming in c_in_7_days
Ankit Dubey
 
Ecad final
Ecad finalEcad final
Ecad final
Srinivas Sri
 
Chapter1 introduction it2
Chapter1 introduction it2Chapter1 introduction it2
Chapter1 introduction it2
Kinglan Galon
 
C in7-days
C in7-daysC in7-days
C in7-days
Sanuj Nair
 
C in7-days
C in7-daysC in7-days
C in7-days
Amit Kapoor
 
ICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdfICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdf
ssuser33f16f
 
computer programming omputer programming
computer programming omputer programmingcomputer programming omputer programming
computer programming omputer programming
Jifarnecho
 
Session 1 - c++ intro
Session   1 - c++ introSession   1 - c++ intro
Session 1 - c++ intro
VijayaNagarajan5
 
CIS 170 Effective Communication - tutorialrank.com
CIS 170 Effective Communication - tutorialrank.comCIS 170 Effective Communication - tutorialrank.com
CIS 170 Effective Communication - tutorialrank.com
Bartholomew19
 
Devry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting startedDevry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting started
ash52393
 
Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com  Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com
amaranthbeg143
 
CIS 170 Exceptional Education - snaptutorial.com
CIS 170   Exceptional Education - snaptutorial.comCIS 170   Exceptional Education - snaptutorial.com
CIS 170 Exceptional Education - snaptutorial.com
DavisMurphyB33
 
CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   
bellflower42
 
CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   
llflowe
 
ABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docxABC Consolidated Financial InfoABC Companys current financial inf.docx
ABC Consolidated Financial InfoABC Companys current financial inf.docx
ransayo
 
Devry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-startedDevry cis-170-c-i lab-1-of-7-getting-started
Devry cis-170-c-i lab-1-of-7-getting-started
govendaagoovenda
 
C++ chapter # 1
C++ chapter # 1C++ chapter # 1
C++ chapter # 1
AliIjaz35
 
How to work with code blocks
How to work with code blocksHow to work with code blocks
How to work with code blocks
Tech Bikram
 
Programming in c_in_7_days
Programming in c_in_7_daysProgramming in c_in_7_days
Programming in c_in_7_days
Ankit Dubey
 
Chapter1 introduction it2
Chapter1 introduction it2Chapter1 introduction it2
Chapter1 introduction it2
Kinglan Galon
 
ICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdfICT1002-W8-LEC-Introduction-to-C.pdf
ICT1002-W8-LEC-Introduction-to-C.pdf
ssuser33f16f
 
computer programming omputer programming
computer programming omputer programmingcomputer programming omputer programming
computer programming omputer programming
Jifarnecho
 
CIS 170 Effective Communication - tutorialrank.com
CIS 170 Effective Communication - tutorialrank.comCIS 170 Effective Communication - tutorialrank.com
CIS 170 Effective Communication - tutorialrank.com
Bartholomew19
 
Devry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting startedDevry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting started
ash52393
 
Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com  Cis 170 Extraordinary Success/newtonhelp.com
Cis 170 Extraordinary Success/newtonhelp.com
amaranthbeg143
 
CIS 170 Exceptional Education - snaptutorial.com
CIS 170   Exceptional Education - snaptutorial.comCIS 170   Exceptional Education - snaptutorial.com
CIS 170 Exceptional Education - snaptutorial.com
DavisMurphyB33
 
CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   CIS 170 Imagine Your Future/newtonhelp.com   
CIS 170 Imagine Your Future/newtonhelp.com   
bellflower42
 
CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   CIS 170 Life of the Mind/newtonhelp.com   
CIS 170 Life of the Mind/newtonhelp.com   
llflowe
 
Ad

More from Priyanka Anni (9)

Bluetooth
BluetoothBluetooth
Bluetooth
Priyanka Anni
 
General Electric
General ElectricGeneral Electric
General Electric
Priyanka Anni
 
Modulation of LED
Modulation of LEDModulation of LED
Modulation of LED
Priyanka Anni
 
Mcrowave and Radar engineering
Mcrowave and Radar engineeringMcrowave and Radar engineering
Mcrowave and Radar engineering
Priyanka Anni
 
Reasons of Perception Failure
Reasons of Perception FailureReasons of Perception Failure
Reasons of Perception Failure
Priyanka Anni
 
Product life cycle with example
Product life cycle with exampleProduct life cycle with example
Product life cycle with example
Priyanka Anni
 
DSP Memory Architecture
DSP Memory ArchitectureDSP Memory Architecture
DSP Memory Architecture
Priyanka Anni
 
Microstrip patch
Microstrip patchMicrostrip patch
Microstrip patch
Priyanka Anni
 
Horn antenna
Horn antennaHorn antenna
Horn antenna
Priyanka Anni
 
Mcrowave and Radar engineering
Mcrowave and Radar engineeringMcrowave and Radar engineering
Mcrowave and Radar engineering
Priyanka Anni
 
Reasons of Perception Failure
Reasons of Perception FailureReasons of Perception Failure
Reasons of Perception Failure
Priyanka Anni
 
Product life cycle with example
Product life cycle with exampleProduct life cycle with example
Product life cycle with example
Priyanka Anni
 
DSP Memory Architecture
DSP Memory ArchitectureDSP Memory Architecture
DSP Memory Architecture
Priyanka Anni
 
Ad

Recently uploaded (20)

FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.
maldonadocesarmanuel
 
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Mohamed905031
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptxFINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
ANFIS Models with Subtractive Clustering and Fuzzy C-Mean Clustering Techniqu...
ANFIS Models with Subtractive Clustering and Fuzzy C-Mean Clustering Techniqu...ANFIS Models with Subtractive Clustering and Fuzzy C-Mean Clustering Techniqu...
ANFIS Models with Subtractive Clustering and Fuzzy C-Mean Clustering Techniqu...
Journal of Soft Computing in Civil Engineering
 
Call For Papers - International Journal on Natural Language Computing (IJNLC)
Call For Papers - International Journal on Natural Language Computing (IJNLC)Call For Papers - International Journal on Natural Language Computing (IJNLC)
Call For Papers - International Journal on Natural Language Computing (IJNLC)
kevig
 
introduction to Digital Signature basics
introduction to Digital Signature basicsintroduction to Digital Signature basics
introduction to Digital Signature basics
DhavalPatel171802
 
Influence line diagram for truss in a robust
Influence line diagram for truss in a robustInfluence line diagram for truss in a robust
Influence line diagram for truss in a robust
ParthaSengupta26
 
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
ijccmsjournal
 
"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai
Julio Chai
 
Forecasting Road Accidents Using Deep Learning Approach: Policies to Improve ...
Forecasting Road Accidents Using Deep Learning Approach: Policies to Improve ...Forecasting Road Accidents Using Deep Learning Approach: Policies to Improve ...
Forecasting Road Accidents Using Deep Learning Approach: Policies to Improve ...
Journal of Soft Computing in Civil Engineering
 
Presentación Tomografía Axial Computarizada
Presentación Tomografía Axial ComputarizadaPresentación Tomografía Axial Computarizada
Presentación Tomografía Axial Computarizada
Juliana Ovalle Jiménez
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
Journal of Soft Computing in Civil Engineering
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
Advanced Automation and Technology in Coal Handling Plants
Advanced Automation and Technology in Coal Handling PlantsAdvanced Automation and Technology in Coal Handling Plants
Advanced Automation and Technology in Coal Handling Plants
Infopitaara
 
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
gerogepatton
 
What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...
cyhuutjdoazdwrnubt
 
Webinar On Steel Melting IIF of steel for rdso
Webinar  On Steel  Melting IIF of steel for rdsoWebinar  On Steel  Melting IIF of steel for rdso
Webinar On Steel Melting IIF of steel for rdso
KapilParyani3
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 
FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.
maldonadocesarmanuel
 
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Mohamed905031
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptxFINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
Call For Papers - International Journal on Natural Language Computing (IJNLC)
Call For Papers - International Journal on Natural Language Computing (IJNLC)Call For Papers - International Journal on Natural Language Computing (IJNLC)
Call For Papers - International Journal on Natural Language Computing (IJNLC)
kevig
 
introduction to Digital Signature basics
introduction to Digital Signature basicsintroduction to Digital Signature basics
introduction to Digital Signature basics
DhavalPatel171802
 
Influence line diagram for truss in a robust
Influence line diagram for truss in a robustInfluence line diagram for truss in a robust
Influence line diagram for truss in a robust
ParthaSengupta26
 
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...
ijccmsjournal
 
"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai"The Enigmas of the Riemann Hypothesis" by Julio Chai
"The Enigmas of the Riemann Hypothesis" by Julio Chai
Julio Chai
 
Presentación Tomografía Axial Computarizada
Presentación Tomografía Axial ComputarizadaPresentación Tomografía Axial Computarizada
Presentación Tomografía Axial Computarizada
Juliana Ovalle Jiménez
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
Advanced Automation and Technology in Coal Handling Plants
Advanced Automation and Technology in Coal Handling PlantsAdvanced Automation and Technology in Coal Handling Plants
Advanced Automation and Technology in Coal Handling Plants
Infopitaara
 
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
gerogepatton
 
What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...What is dbms architecture, components of dbms architecture and types of dbms ...
What is dbms architecture, components of dbms architecture and types of dbms ...
cyhuutjdoazdwrnubt
 
Webinar On Steel Melting IIF of steel for rdso
Webinar  On Steel  Melting IIF of steel for rdsoWebinar  On Steel  Melting IIF of steel for rdso
Webinar On Steel Melting IIF of steel for rdso
KapilParyani3
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 

Writing first C Program

  • 1. Topic: Writing First C Program PRESENTED BY: A.PRIYANKA
  • 2. Contents  Basics of C program  Basics of hardware specific code
  • 3. Writing first C Program Keil C is not much different from a normal C program. If you know assembly, writing a C program is not a problem, only thing you have to keep in mind is forget that your controller has general purpose registers, accumulators or whatever. But do not forget about Ports and other on chip peripherals and related registers to them. In basic C, all programs have atleast one function which is entry point for your application that function is named as "main“ function.
  • 4. Cont.. Similarly in keil, we will have a main function, in which all your application specific work will be defined. Lets move further deep into the working of applications and programs. When you run your C programs in your PC or computer, you run them as a child program or process to your Operating System so when you exit your programs (exits main function of program) you come back to operating system.
  • 5. Cont..  Whereas in case of embedded C, you do not have any operating system running in there.  So you have to make sure that your program or main file should never exit.  This can be done with the help of simple while(1) or for(;;) loop as they are going to run infinitely.
  • 6. To open a new file in Keil C: Open Keil and Start a new project:
  • 7. Cont.. You will prompted to chose a name for your new project, choose a name and click save. The following window will appear, where you will be asked to select a device for Target ‘Target 1′:
  • 8. Cont.. From the list ,select ATMEL and chose your microcontroller .The AT89s52 will be called your ‘Target device’ ,which is the final destination of your source code. You will be asked whether to copy standard 8051 startup code click No. Click file, New and similar to the following window should appear. The blank space where your code should be written.
  • 9. Cont.. From the list ,select ATMEL and chose your microcontroller .The AT89s52 will be called your ‘Target device’ ,which is the final destination of your source code. You will be asked whether to copy standard 8051 startup code click No. Click file, New and similar to the following window should appear. The blank space where your code should be written.
  • 10. Cont.. Now, you have to click ‘File ‘,Save as and choose a file name for code ending with the extension ‘.c’ and click save. Then you have to add this file to your project work space as shown in the following screen:
  • 11. Cont.. After right-clicking on ‘source group 1‘, click on ‘Add files to group…‘, then you will be prompted to browse the file to add to ‘source group 1′, chose the file that you just saved and add it to the source group. You will notice that the file is added to the project tree at the left. In some versions of this software you have to turn ON manually the option to generate HEX files. make sure it is turned ON, by right-clicking on target 1, Options for target ‘target 1′, then under the ‘output‘ tab, by checking the box ‘generate HEX file‘. This step is very important as the HEX file is the compiled output of your project that is going to be transferred to the microcontroller.
  • 12. Following layout provides a skeleton of Basic C program: 1.voidmain() 2.{ 3. //Your one time initialization code will come here 4.while(1){ 5. //while 1 loop 6. //This loop will have all your application code 7. //which will run infinitely 8. } 9.}
  • 13. Writing first C Program  When we are working on controller specific code, then we need to add header file for that controller.  After project is created, add the C file to project.  Now first thing you have to do is adding the header file.  All you have to do is right click in editor window, it will show you correct header file for your project.
  • 14. Figure bellow shows the windows context for adding header file to your c file.
  • 15. Write an 8051 C program to send values 00 – FF to port P1: #include <reg51.h> void main(void) { unsigned char z; for (z=0;z<=255;z++) P1=z; }
  • 16. Write an 8051 C program to toggle bit D0 of the port P1 (P1.0) 50,000 times #include <reg51.h> sbit MYBIT=P1^0; void main(void) { unsigned int z; for (z=0;z<=50000;z++) { MYBIT=0; MYBIT=1; } }
  • 17. Write an 8051 C program to toggle bits of P1 continuously forever with some delay //Toggle P1 forever with some delay in between “on” and “off” #include <reg51.h> void main(void) { unsigned int x; for (;;) //repeat forever { p1=0x55; for (x=0;x<40000;x++); //delay size //unknown p1=0xAA; for (x=0;x<40000;x++); }}
  • 18. Writing Hardware specific code In hardware specific code, we use hardware peripherals like ports, timers and USART etc. Do not forget to add header file for controller you are using, otherwise you will not be able to access registers related to peripherals.
  • 19. Lets write a simple code to Blink LED on Port1, Pin1.