0% found this document useful (0 votes)
3 views

module 1

The document provides an introduction to the C programming language and its features, particularly in the context of embedded systems. It outlines differences between standard C and Embedded C, including resource constraints, hardware interaction, and memory management. Additionally, it includes basic C program structures, examples of C programs, and various programming concepts such as operators and I/O operations.

Uploaded by

Ankit Dhang
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

module 1

The document provides an introduction to the C programming language and its features, particularly in the context of embedded systems. It outlines differences between standard C and Embedded C, including resource constraints, hardware interaction, and memory management. Additionally, it includes basic C program structures, examples of C programs, and various programming concepts such as operators and I/O operations.

Uploaded by

Ankit Dhang
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Module-1

Introduction to C

S.PAVANI
Overview
Features of C language
Introduction to Embedded C
Difference between C and
Embedded C
Feature C Programming Embedded C
Embedded systems (microcontrollers,
Target Platform General-purpose computing platforms
microprocessors)
Designed for efficient use of limited resources
Resource Constraints May not be optimized for resource constraints
(memory, processing power) in embedded systems

Provides mechanisms for direct interaction with


Typically relies on operating system abstractions for
Hardware Interaction hardware components (registers, peripherals) in
hardware interaction
embedded systems

Supports real-time programming for tasks requiring


Real-Time Considerations Real-time considerations may not be critical precise timing and interrupt handling in embedded
systems

May not have standard I/O; often uses


Standard I/O Operations Relies on standard I/O operations (printf, scanf) communication interfaces (UART, SPI, I2C) for data
exchange in embedded systems

Involves efficient memory management, often using


Dynamic memory allocation (malloc, free) is
Memory Management static allocation or memory pools to avoid
common
fragmentation in embedded systems

Often requires cross-compilation for different


Code is compiled for the same architecture as the
Cross-Compilation architectures, essential for embedded systems with
development environment
varied hardware platforms

Embedded systems in automotive, consumer


Desktop applications, servers, general-purpose
Application Examples electronics, medical devices, industrial automation,
software
etc.
Basic C program structure
Comments
Single-line comments: Single-line comments begin with two forward slashes (//). Everything following
these symbols on the same line is treated as a comment.

// This is a single-line comment


int main() {
// Code goes here
return 0;
}
Multi-line comments: Multi-line comments start with /* and end with */. Everything between these
symbols is considered a comment, even if it spans multiple lines.
/*
This is a multi-line comment.
It can span multiple lines.
*/
int main() {
// Code goes here
return 0;
}
Identifiers

Identifiers refer to user defined names for variables, functions etc. in C.


Variables
Variable types
Header files
Data types
1. Write a C program to show the ASCII value of a character

#include <stdio.h>
int main() {
char ch;
printf(“Enter a character: “);
scanf(“%c”,&ch);
printf(“The ASCII value of ‘%c’ is %d\n”, ch, ch);
return 0;
}
• Write a C program to display the ASCII code of a character in
decimal, octal and hexadecimal
• Write a C program to swap two numbers without using third
variable
• Write a C program to swap two numbers
• Write a C program to calculate volume of a sphere
• Write a C program to calculate simple interest
• Write a C program to calculate compound interest
#include <stdio.h>

int main()

char ch;

printf("Enter a Character : ");

scanf("%c", &ch);

printf("ASCII value of %c in decimal = %d \n", ch, ch);

printf("ASCII value of %c in decimal = %o \n", ch, ch);

printf("ASCII value of %c in hexadecimal = %x \n", ch, ch);

}
#include <stdio.h>
int main() {

int x = 15, y = 20;

printf("Before swapping: x = %d, y = %d\n", x, y);

x = x+y;

y = x-y;

x = x-y;

printf("After swapping: x = %d, y = %d\n", x, y);

return 0;

}
#include <stdio.h>

int main() {

int x = 15, y = 20, temp;

printf("Before swapping: x = %d, y = %d\n", x, y);

temp = x; // Store the value of x in temp

x = y; // Assign the value of y to x

y = temp; // Assign the original value of x (stored in temp) to y

printf("After swapping: x = %d, y = %d\n", x, y);

return 0;

}
Write a C program to calculate volume of a sphere

#include <stdio.h>
int main() {
float radius, volume;
printf("Enter the radius of the sphere in cm: ");
const float PI = 3.14159;
scanf("%f", &radius);
volume = (4/3)*PI*radius*radius*radius;
printf("Volume of sphere in cubic centimeter = %.3f\n", volume);
return 0;
}
• #include <stdio.h>
• int main() {
• char ch;
• printf("Enter a character: ");
• scanf("%c",&ch);
• printf("The ASCII value of '%c' is %d\n", ch, ch);
• return 0;
•}
Arithmetic Operators in C
• Type casting, refers to the process of changing the data
type of a variable from one type to another. In
programming, different data types represent different
kinds of values and have different memory
representations. Type casting allows you to work with
variables of different types in a consistent manner.
int x = 5;
float y = 2.5;
float result = x + y; // Implicit type casting of 'x' from int to float
Logical operators
Bitwise operators
Other operators
Order of operations
Order of operations
Format specifiers
Escape sequences
Console I/O
1) Write a C program to convert temperature from Fahrenheit to Celsius
2) Write a C program to find the sum of digits of a 3-digit number
3) Write a C program to perform flooring and ceiling operation on a number
without using inbuilt function(s)
4) Write a C program to reverse a 3-digit number.
• For Ex : If input - 123, output = 321
• Additional exercises:
1. Average of three numbers
2. Perimeter of a rectangle
3. Volume of a cone
4. Total surface area of a cylinder
Enhanced I/O Operations

You might also like