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

Programming Parallel Ports (1)

Uploaded by

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

Programming Parallel Ports (1)

Uploaded by

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

DEPARTMENT OF ELECTRONICS &

COMMUNICATION ENGINEERING

Embedded System and IOT


Unit I- 8-BIT EMBEDDED PROCESSOR

www.kgkite.ac.in
Programming in 8051
Calculate the sum of series of numbers . The length of the series is in the memory location 2200H and the
series itself begins from memory location 2201H.
Pin diagram of 8051 Microcontroller
8051 I/O PORTS

• Port 0 (Pin 32-39)


• Port 1(Pin 1-8)
• Port 2(Pin 21-28)
• Port 3(Pin 10-17)
Port 0 (pin 32-39)
Port 2,3,4 have internal pull up resistors
Reason for using Pullup Resistor
Port 3(Pin 10-17)
• Special Function register
• P3.0-RXD
• P3.1-TXD
• P3.2-INTO
• P3.3-INT1
• P3.4-T0
• P3.5-T1
• P3.6-WR
• P3.7-RD
Ways to access 8 bits in ports
BACK MOV A, #55H
MOV P1,A
ACALL DELAY
MOV A,#0AAH
MOV P1,A
ACALL DELAY
SJMP BACK
BACK MOV P1,#55H
ACALL DELAY
MOV P1,#0AAH
ACALL DELAY
SJMP BACK
I/O Bit Manipulation programming
• I/O Bit manipulation a powerful and widely used Features of 8051 family.
 I/O ports have the capability to access individual bits of the ports without altering the rest of the
bits in that port.
 Of the four 8051 ports , we can access either 8 bits or any single bit without altering the rest.
 For accessing a port in single bit manner, we use syntax SETB X.Y
 Where X-Port no 0,1,2,3
 Y-Desired Bit no 0-7(D0-D7)
Example:
BACK: CPL P1.2 ;complement P1.2 only
ACALL DELAY
SJMP BACK
• AGAIN : SETB P1.2 ;Change only P1.2 =high
ACALL DELAY
CLR P1.2
ACALL DELAY :change only P1.2=low
SJMP AGAIN
Write a program to toggle all bits of P0 continuously

BACK: MOV A, #0AAH


MOV P0, A
A CALL DELAY
MOV A,#55H
MOV P0,A
A CALL DELAY
SJMP BACK
Write a program to read the content of P1 and save it in R6 and also send it to P2

MOV A, #0FFH
MOV P1,A
MOV A, P1
MOV R6,A
MOV P2,A
Write an ALP to receive input from port P1.5 and if it is high then an output 35H is sent to
port 0.
SETB P1.5 ; Conf P1.5 as an input
JNB P1.5, LAST ; Skip next instruction if P1.5 is low
MOV P0, #35H ; send 35H on P0
LAST:
Programming I/O Ports using 8051C

• It is easier and Time consuming to write a C program than assembly.


• C is more Flexible.
• It is easier to modify and update
• Programming C allow u to use code available in program memory.
• C program can be used for different microcontroller with small or no
modification.
Data Types in 8051C
Logical operation in 8051C
Steps to Build an Embedded C Program

• Comments
• Directives of Processor
• Configuration of Port
• Global variables
• Core Function/Main Function
• Declaration of Variable
• The logic of the Program
Comments

1. Single line comment –Non Executable but it provides Program Documentation.


Comments begin with \\

2. Multi Line Comment- Multi-line comments begin with a single slash (/) & an asterisk (/*) in the
programming languages which explains a block of code.
Directives of Processor

• #include
#include<reg51.h>
Sbit LED = P2^3;
Main();
{
LED = 0x0ff
Delay();
LED=0x00;
}
Configuration of Port

• The keywords in the embedded c program are standard as well as predefined like a bit, sbit, SFR which are
used to state the bits & single pin within a program.
• #include< >
Sbit a = P 2^2;
SFR 0x00 = PoRT0;
Bit C;
main()
{
……………..
……………..
}
The syntax for this data type is : sbit variable name = SFR bit ;
The syntax of this data type is : name of bit variable;
The syntax of this data type is: SFR variable name = SFR address for SFR register;

You might also like