Sunteți pe pagina 1din 22

Design an 8051 microcontroller based system

for Displaying number from 0 to 255 using LEDs


• Specifications
 Use AT89s8252 (flash MC with In System
Programming(ISP)
 Use 12 MHz freq.
 Use on chip program memory to storing program
instructions
 8-LED connected to port
 LEDs connected through pull-up resistor 470 ohms,
conduct when port pin is logic ‘0’
 Each LED represent the binary bit of byte.
 Counting start from ‘0’ n start increment by one.
 When counter reaches 255 then it start from 0.
Designing hardware and software
• Hardware part
 AT89C51/52 or AT89S8252 both are from 8051 family, first one
require EEPROM/flash programmer device, other one does not
require
 In System programming (ISP) technique is sufficient for second MC.
• Some of the important features of the 7805 IC are as follows:
• It can deliver up to 1.5 A of current (with heat sink).
• Has both internal current limiting and thermal shutdown features.
• Requires very minimum external components to fully function if the
input supply is an unregulated DC Voltage, then all you need are
two capacitor (even those are not mandatory depending on the
implementation).
• Ceramic resonators may be used as a low-cost alternative to crystal
resonators but due to decrease in frequency stability and accuracy,
ceramic resonators are not preferred for high-speed serial data
communication with other system.
• When the 5V power is switched on, the capacitor shorts to 5V, and
then gradually the RC circuit discharges to bring the reset pin to 0.
According to the 8051 documentation, the voltage across the reset
pin should be at logic high for more than 2 machine cycles (where 1
machine cycle = 4 clock cycles).
• The resistor is used to limit the current through the LED and to
prevent that it burns. If the voltage source is equal to the voltage
drop of the LED, no resistor is required. The resistance of the
resistor is easy to calculate with Ohm's law and Kirchhoff's circuit
laws.
Program
ORG 0000H
JMP 0050H
ORG 0003H
RETI
ORG 0013H
RETI
ORG 001BH
RETI
ORG 0023
RETI
ORG 0050H
MOV P2, #0FFH ; TURN off all leds
CLR EA ; disable all intrpts
MOV SP,#08H
MOV R7, #00H
REPEAT: CALL Delay
INC R7
MOV A, R7
CPL A
MOV P2, A
JMP REPEAT
Calculate delay generated by the program

Delay: MOV R2, #50


Loop1: MOV R1, #200
Loop2: MOV R0, #248
Loop3: DJNZ R0, Loop3
DJNZ R1, Loop2
DJNZ R2, Loop1
RET
END
 In the original 8051, one machine cycle lasts 12 oscillator periods.
Therefore, to calculate the machine cycle for the 8051, we take
1/12 of the crystal frequency, then take its inverse,
 1/12 x crystal frequency
 Time for per Machine cycle=1/f
Design an 8051 microcontroller based system for
controlling 5v, 2-phase-wire stepper motor.
• Specifications
 Use AT89s8252 (flash MC with In System Programming(ISP)
 Use 12 MHz freq.
 Use on chip program memory to storing program
instructions
 Wires of the stepper motor are marked corresponding to
the coils(A,B,C,D) And ground (2-wires)
 Use octal peripheral driver IC ULN2803 for driving stepper
motor
 Step the motor in full step mode with a delay of 1 second
between the steps
 Connect coil drives to port 1 in order Coil A to P1.0, B to
P1.1, C to P1.2, D to P1.3
Program
ORG 0000H
JMP 0100H
ORG 0003H
RETI
ORG 0013H
RETI
ORG 001BH
RETI
ORG 0023
RETI
ORG 0100H
MOV P1 , #00H ; TURN off drives to all stator coils
CLR EA ; disable all intrpts
MOV SP, #08H
MOV A, #0CCH
REPEAT: MOV P1, A
RR A

CALL Delay
JMP REPEAT
Calculate delay generated by the
program
Delay: MOV R2, #10
Loop1: MOV R1, #200
Loop2: MOV R0, #248
Loop3: DJNZ R0, Loop3
DJNZ R1, Loop2
DJNZ R2, Loop1
RET
END
 In the original 8051, one machine cycle lasts 12 oscillator periods.
Therefore, to calculate the machine cycle for the 8051, we take
1/12 of the crystal frequency, then take its inverse,
 1/12 x crystal frequency
 Time for per Machine cycle=1/f
Design an 8051 based system for interfacing the
Programmable Peripheral interface (PPI) device
8255
• Specifications
 Use AT89s8252 (flash MC with In System
Programming(ISP)
 Use 12 MHz freq.
 Use on chip program memory to storing program
instructions
 Use 82C55A PPI device
 Allocate the address space 8000 to FFFF to 8255.
initialise port A, port B, port C of 8255 as output
ports in mode 0.
• Hardware
 Here we are allocating the address space 8000 to FFFF to 8255
 8255 activated when the 15th bit of address line becomes 1, here we use NOT gate
to invert A15 line before applying to CS\ line of 8255.
 In this configuration 8255 requires only four address space namely 8000 for Port
A, 8001 for Port B, 8002 for Port C, 8003 for control register, rest of addresses left
unused.
 A decoder can be used if we have more than one device is connected.
 The octal latch 74LS373 latches lower order address bus which is multiplexed with
data lines.
 A 3 to 8 decoder chip, 74LS138, decodes the address bus to generate the CS\
signal for 8255, here we have only one A15 address line to decode, rest of two are
grounded, intention is to assert the CS\ signal of 8255 when A15 is 1.
 The i/p condition corresponds to this is 001, decoded for this is 1(y1), you can
replace decoder with NOT gate.
 P1.0 is connected to reset pin of 8255
 When 8051 is initialised , the port P1.0 automatically generates a reset high signal
for 8255.
 Control word
D7 D6 D5 D4 D3 D2 D1 D0
D3
1 0 0 0 0 0 0 0
ORG 0000H
JMP Main
ORG 0003H
RETI
ORG 0013H
RETI
ORG 001BH
RETI
ORG 0023
RETI
Main: CLR P1.0
MOV SP, #08
MOV A, #80 ;LOAD INITIAL CONTROL WORD
MOV DPTR, #8003 ;
MOVX @DPTR, A
JMP $
END
• Design an 8051 based system to
interface 8255 and Connect LEDs to
Port A of 8255. Develop an ALP
program for 0 to 255 counter.
#include< reg52.h> rd=1; //Disabling read
sbit A0=P1^0; wr=0;
sbit A1=P1^1; P2=0x80; //Making all ports output
sbit wr=P3^6; A0=1; //Selecting control register
sbit rd=P3^7; A1=1; //Selecting control register
void delay(unsigned int no) while(1){
{ wr=1;
unsigned int i; delay(10000);
for(i=0;i<=no;i++); A0=0;
} A1=0;
wr=0;
void main(){ P2=0x0F;
P1=0x00; //Port-1 as Output wr=1;
P3=0x00; // Port-3 as Output A0=0;
P2=0x00; // Port-2 as Output A1=0;
delay(10000); delay(10000);
wr=0;
P2=0xF0;

}
}

S-ar putea să vă placă și