You are on page 1of 12

8051 Basic Connection

fig1: 8051 basic connection

Push Button (tact switch) with LED indicator

fig2: push button (tact switch) with LED indicator When button is Pushed Not Pushed LED Light On Light Off Logic State 0 1

+5V DC Voltage Supply

fig3: voltage regulator connection Component 1N4001 Description This rectifier diodes function is to protect voltage regulator 7805 from being damaged by reverse polarity battery input. Its forward bias voltage is around 1.1V thus the effective voltage supply to 7805 is +10.9V (12V 1.1V = 10.9V) They smooth the voltage level. They are used to suppress high frequency noise. The impedance of capacitor is Xc = 1/j2fc, where f is frequency and c is capacitance. The higher the frequency, the lower the impedance. Effectively, high frequency noise is being filtered. Normal 7805 can supply 1.0A current. For proper operation, the input voltage should at least +9V.

C1, C4 C2, C3

7805

Relay configuration of H-Bridge

*bat = battery fig4: H-bridge connection

Component 74HC04

Description It is a Hex Inverter to act as a buffer between microcontroller and the ULN2803. It inverts the input logic at the output side. Input Output nA nY L (Logic 0) H (Logic 1) H (Logic 1) L (Logic 0) *H = HIGH voltage level L = LOW voltage level

ULN2803

This is Darlington Transistor Arrays used to drive high current load such as dc motor.

C1 R1, R2 H-Bridge

It is used for high frequency noise filtering. To limit the current flows through the LED. A normal LED (3mm) requires 10mA to emit light. V = IR thus R = V / I = 12V / 10mA = 1.2K It mainly consists of 2 12V relay, namely RLY1 and RLY2. P0.0 D1 P0.1 D2 Motor state L On L On Stop L On H Off CCW H Off L On CW H Off H Off Stop *H = HIGH voltage level L = LOW voltage level CW = Clockwise direction (assume that current flow from M1 to M2 is CW) CCW = Counter Clockwise direction (assume that current flow from M2 to M1 is CCW)

Extra Note on H-Bridge

fig5: Comparison of pin layout of real relay component and the schematic symbol

fig6: Basic H-Bridge.

H-Bridge Working Principle

fig7: Clock-Wise (CW) direction NO = Normally Open NC = Normally Close COM = Common Coil1 = one side of coil named as coil1 Coil2 = another side of coil named as coil2 Clock-Wise (CW) direction 1. When P0.1 is cleared (LOW state), 74HC04 will invert it and output to 2Y as HIGH state. This High state will be inverted again by ULN2803 to LOW state at pin 17. 2. Since there is a voltage difference between Coil1 and Coil2 (relay on your right hand side), current will flows through the coil and generate magnetic field to pull the internal switch from NC to NO. 3. Now a voltage difference appears between M1 and M2. Thus current flows from +12V terminal -> M1 -> M2 -> GND. (assume that current flow from M1 to M2 is CW)

fig8: Counter Clock-Wise (CCW) direction Counter Clock-Wise (CCW) direction 4. When P0.0 is cleared (LOW state), 74HC04 will invert it and output to 1Y as HIGH state. This High state will be inverted again by ULN2803 to LOW state at pin 18. 5. Since there is a voltage difference between Coil1 and Coil2 (relay on your right hand side), current will flows through the coil and generate magnetic field to pull the internal switch from NC to NO. 6. Now a voltage difference appears between M1 and M2. Thus current flows from +12V terminal -> M2 -> M1 -> GND. (assume that current flow from M2 to M1 is CCW)

Programming Below are the simple assembly codes that can perform triggering the relay by pressing a button.
;Simple button pressing and trigger on relays assembly code. ORG 0000 MAIN: SETB P2.0 SETB P2.1 OK1: JNB P1.0, RELAY1 JNB P1.1, RELAY2 JMP MAIN RELAY1: RELAY2: END CLR JMP CLR JMP P2.0 OK1 P2.1 OK1 ;clear P2.0, and wait for another button press ;clear P2.1, and wait for another button press ;wait for P1.0 button press, and jump to Relay1 ;wait for P1.0 button press, and jump to Relay1 ;trigger on relay at P2.0 ;jump back button press inspection loop ;trigger on relay at P2.1 ;jump back button press inspection loop

Description of the code: Button1 = Pin 1.0 of the micro-controller Button2= Pin 1.1 of the micro-controller Relay1= Pin 2.0 require to connect to a transistor to trigger on the first relay. Relay2= Pin 2.1 require to connect to a transistor to trigger on the second relay. Operation of the code: The operation of this code is simple. When you press the button1 (that require to grounding the P1.0), relay1 will turn on (with pin2.0 set to low that will turn on a PNP transistor for trigger on a relay).When you release pressing button1, P2.0 will set to high, and relay1 will turn off. The same response will show with respective pin configuration when you pressing/release button2.

Step by step of using Fet89c5x. Step1

Write your code in Fet89c5x.

Step2

-go to -> file, -> save as; to save your code that you had wrote to a specific location.

Step3

Compile your code by pressing the build icon . A .hex file will generate after compile the code. There will be a massage box to show how many errors in your code.

Step by step of using 8052Simulator.

Step1

Open 8052SIM.exe (this program not requires to install). Go to View, and then select I/O ports and SFR window. I/O ports window is for you to observe the I/O ports response; SFR window is for you to observe Special Function Registers value while program running. Step2

-open the .hex file from respective location that you had save your code.

Step3

Run your program (by pressing the icon ) and observe the Ports window response. Un-tick (set low) the P1.0 box at the Ports window. You will see P2.0 box also follow un-tick. Tick (set high) the P1.0 box, P2.0 will follow to tick back.

The same response will show when you tick/ un-tick P1.1 box.

Following are the sample code for simple LED blinking.


;simple led blinking ORG 0000H MOV P1, 0FFH MOV P2, 0FFH START: STOP: LEDBLINK: JNB P1.0 , LEDBLINK JMP START CLR P2.0 JMP START CLR P2.0 CALL DELAY_1SEC CLR P2.0 JNB P1.1, STOP JMP LEDBLINK

;The subroutine below causes a delay of 1 second ;(crystal frequency = 12 MHz) DELAY_1SEC: REPEAT: AGAIN: HERE: MOV R0, #4 MOV R1, #250 MOV R2, #250 NOP NOP DJNZ R2, HERE DJNZ R1, AGAIN DJNZ R0, REPEAT ;1 machine cycle ;1 machine cycle ;1 machine cycle ;1 machine cycle ;1 machine cycle ;2 machine cycle ;2 machine cycle ;2 machine cycle ;2 machine cycle

RET

END

(For the LED blinking code, you might not be able to observe the response of I/O ports by using 8952Simulator program because of 8952Simulator cant simulate the real time delay, and you might wait for long time to count a second delay.)

You might also like