Professional Documents
Culture Documents
DS Unit 2
DS Unit 2
DS Unit 2
on
Introduction to
8051 Microcontroller
Programming using Embedded C
Mr.A.R.Telepatil
Assistant Professor
Department of Electronics & Telecommunication Engineering
D.K.T.E’s Textile And Engineering Institute, Ichalkaranji
2/12/2022 1
[An Autonomous Institute]
Index
• Why Embedded C?
• Structure of programming
• Port programming
• Logic operations
2/12/2022 2
Why Embedded C?
• Embedded C programming easier and less time consuming as
compared to assembly
2/12/2022 3
Structure of programming
• Include header files
• Declare global variables
• Define function
• Define main function
• Define local variable
• Initialize variables
• Define body for the function
• Repeat process
2/12/2022 4
Structure of programming
• Include header files
• Declare global variables
• Define function
• Define main function
• Define local variable
• Initialize variables
• Define body for the function
• Repeat process
2/12/2022 5
Various data types
• Signed char:
• 8-bit datatype
• MSB bit [D7] is used to represent the +/- value
• Gives values from -128 to +127
2/12/2022 7
Various data types
• Unsigned int :
• 16 bit datatype
• Takes values from range –65535[0000h to FFFFH]
• Used to define 16 bit variable like,
• Memory location address
• Set counter value of more than 256
• Signed int :
• 16 bit datatype
• MSB bit [D15]is used to represent -/+ value
• Takes values from range –32768 to 32767
• sbit : Used to access single bit addressable register
2/12/2022 8
Various data types
• It contains 4 I/O Ports
– PORT P0
– PORT P1
– PORT P2
– PORT P3
• All are 8 bit and bit programmable
• All PORT’s upon RESET configured as input
– When written as ‘0’ PORTS Output
– When written as ‘1’ PORTS Input
2/12/2022 9
Various data types
Writing data to PORT Reading data from PORT
2/12/2022 10
Logical Operators
2/12/2022 11
Program Statement
• Write an 8051 C program to send values 00-FF to port P1.
• Write an 8051 C program to toggle bits of P1 ports continuously with
a 250 ms.
• Write an 8051 C program to get a byte of data form P1, wait ½
second, and then send it to P2.
• Write an 8051 C program to get a byte of data form P0. If it is less
than 100, send it to P1; otherwise, send it to P2.
• Write an 8051 C program to convert 11111101 (FD hex) to decimal
and display the digits on P0, P1 and P2.
2/12/2022 12
Program Statement
• Write an 8051 C program to toggle only bit P2.4 continuously without
disturbing the rest of the bits of P2
2/12/2022 13
Logical Operators
2/12/2022 14
Logical Operators
CODE
2/12/2022 15