0% found this document useful (0 votes)
22 views15 pages

DS Unit 2

The document provides an introduction to 8051 microcontroller programming using Embedded C. It discusses why Embedded C is used, programming structure, various data types, port programming, logic operations and sample programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views15 pages

DS Unit 2

The document provides an introduction to 8051 microcontroller programming using Embedded C. It discusses why Embedded C is used, programming structure, various data types, port programming, logic operations and sample programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

A Technical Session

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

• Various data types

• Port programming

• Logic operations

• Data conversion programs

2/12/2022 2
Why Embedded C?
• Embedded C programming easier and less time consuming as
compared to assembly

• C is easier to modify and update

• Readymade libraries can be used

• Portable with multiple controller families

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

As 8051 is 8-bit controller, unsigned char is most widely


used as data type
2/12/2022 6
Various data types
• Unsigned char:
• 8051 is an 8-bitcontroller
• 8 bit datatype
• Takes values from 0-255 [00h to FFh ]

• 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

• Suppose 0x55 is a 8 bit data • Suppose contents of port P2


that we want to send on port are 0x65 and we want to assign
P1 then it is written as, it to unsigned char x then it is
written as,
P1=0x55 x=P2

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

• Write an 8051 C program to monitor bit P1.5. If it is high, send 55H to


P0; otherwise, send AAH to P2.

• A door sensor is connected to the P1.1 pin, and a buzzer is connected


to P1.7. Write an 8051 C program to monitor the door sensor, and
when it opens, sound the buzzer. You can sound the buzzer by
sending a square wave of a few hundred Hz .

2/12/2022 13
Logical Operators

2/12/2022 14
Logical Operators

CODE
2/12/2022 15

You might also like