Programming Parallel Ports (1)
Programming Parallel Ports (1)
COMMUNICATION ENGINEERING
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
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
• Comments
• Directives of Processor
• Configuration of Port
• Global variables
• Core Function/Main Function
• Declaration of Variable
• The logic of the Program
Comments
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;