embedded c concepts
DESCRIPTION
PointsTRANSCRIPT
Prepared By: Reetu Gupta. IT Dept. DYPCOE
Android OS OS for mobile (mobility) devices. Handheld Devices - PDA
-Smartphone's- Tablets
-Mobile Phones
Prepared By: Reetu Gupta. IT Dept. DYPCOE
PIC Embedded C Basics Variable Declaration. Loops Decision Making Micro Controller Program Imp Characteristics
Less memory for Program and Data
Prepared By: Reetu Gupta. IT Dept. DYPCOE
PIC Embedded C Basics Variable Declaration - Data type is selected based
on data usage
Data Type Size in Bits RangeInt1 1 0 /1
Unsigned int8 8 Bit But in C it is 16 bit but for Microcontroller it is 8 bit
0 to 255
Signed int8 8 -128 to +127Unsigned int16 16 0 to 65535
Signed int16 16 -32767 to 32768Unsigned int32 32 0 to 4294967296
Signed int32 32 -2147483648 to 2147483647
Prepared By: Reetu Gupta. IT Dept. DYPCOE
Floating Point Data Format for PIC Microcontroller
Exponent Sign MantissaXXXX XXXX X XXX XXXX XXXX XXXX XXXX XXXX
8 bit 1 bit 23 bits
•PIC Uses 32-bit format for floating number representation.
Prepared By: Reetu Gupta. IT Dept. DYPCOE
Embedded C Program Program to print a value on Port#include header filevoid main(){ output _X();//X– The port where u want to print assign a value -- Value is given in brackets. E.g. (25)}
#include “16F877A.h”void main(){ output _C(85);}
Prepared By: Reetu Gupta. IT Dept. DYPCOE
Embedded C Program Program to assign a value to port #include header filevoid main(){data_type variable_name;variable_name=input_X();Output_X(variable_name);
}
#include “16F877A.h”void main() { int i; // I is integer variablei=input_C(); // value given as input to port C is stored in iOutput_A(i);// And it is being printed at port C }
Prepared By: Reetu Gupta. IT Dept. DYPCOE
Embedded C Loops Variable Declaration - Data type is selected based
on data usage
Data Type Size in Bits RangeInt1 1 0 /1
Unsigned int8 8 Bit But in C it is 16 bit but for Microcontroller it is 8 bit
0 to 255
Signed int8 8 -128 to +127Unsigned int16 16 0 to 65535
Signed int16 16 -32767 to 32768Unsigned int32 32 0 to 4294967296
Signed int32 32 -2147483648 to 2147483647
Prepared By: Reetu Gupta. IT Dept. DYPCOE
MPLAB Compiler Function
Sr. No
Library Function Use of Function
1 delay_us(x) Generate delay of x microseconds2 delay_ms(x) Generate delay of x milliseconds3 output_p(x) Output the value ‘x’ on port ‘p’4 output_high(PIN_px) Set pin ‘x’ of port ‘p’ to logic 1 / High.5 output_low(PIN_px) Set pin ‘x’ of port ‘p’ to logic 0 / Low.6 input_p() Functions returns the value on port ‘p’7 Input(PIN_px) Functions returns the value of ‘x’ pin
on port ‘p’
• MPLAB has 5 ports : A,B,C,D,E• Separate Function for Each Port
Prepared By: Reetu Gupta. IT Dept. DYPCOE
Operators• Unary • Binary
Arithmetic Bitwise Logical Relational
• Assignment• Selection
Prepared By: Reetu Gupta. IT Dept. DYPCOE
Unary Operators
Sr. No
Unary Operators
Use of Function
1 Unary Minus(-) Return negative value of operator to which it is preceded. E.g x=3, y=-x, then y=-3.
2 Logical Not (!) Logical Not operation on the value obtained from the expression on right.
3 Bitwise Not ( ~ ) Bitwise Not Operation4 Increment (++) Add 1. E.g. If x=5, then x++ will make x=6.5 Decrement (--) Sub 1. E.g. If x=5, then x-- will make x=4
• Operation to be performed is given by: Operators• Data :operation will be performed : Operands• Operator require one operand : Unary Operator
Prepared By: Reetu Gupta. IT Dept. DYPCOE
Pre and Post Increment Operators
Sr. No
Unary Operators
Use of Function
1 Pre Increment X=5, y=++x. Then y=6, x=52 Post Increment X=5, y=x++. Then y=5, x=63 Pre Decrement X=5, y=--x. Then y=4, x=54 Post Increment X=5, y=x--. Then y=5, x=4
Pre : First Operation Then Assign
Post: First Assignment Then Operation
• ++ :• ++x– Preincrement • x++ Post Increment
-- :• --x– Preincrement • x-- Post Increment
Prepared By: Reetu Gupta. IT Dept. DYPCOE
C Peripheral Interface: PIC18F877• ADC : Analog to Digital Converter• PIC18F :
• A single 10-bit ADC• 8 Analog: Input Channel: Port A (6 pins) and Port E (2 pins)• Port A : RA0 to RA5 and Port E: RE1 and RE2• MPLAB function : Handling ADC of PIC18F877
Prepared By: Reetu Gupta. IT Dept. DYPCOE
C Peripheral Interface: PIC18F877Sr. No
Unary Operators Use of Function
1 setup_adc(ADC_CLK_INTERNAL)
Set ADC using Internal Clck Pluse
2 setup_adc_ports(Rpx_Analog) Initial pin ‘x’ of port ‘p’as analog input.
3 set_adc_channel(x) Selects channel x to provide input to ADC
4 read_adc() Reads the value of ADC and return it to variable on left.
Prepared By: Reetu Gupta. IT Dept. DYPCOE
C Mechatronics Applications• Driving Motors : Stepper Motor, DC Motor, Servo Motor.• Interfacing Display ( LCD or LED)