Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I am having problem to write assembly program for 8051

Status
Not open for further replies.

Parth86

Member
I want to ask questions the device like switch , led, motor they have two terminal (positive terminal and negative terminal ) when we interface with controller why we use only single pin like we say switch is connected PO.1 or led is connected P1.1

I have simple task I have one switch and one motor. the positive edge of switch is connected to port pin PO.1 and negative edge is connected to port pin PO.2 and motor is connected to output the positive edge of motor is connected to port pin P1.1 and negative edge is connected to P1.2

if switch is on then motor is on
if switch is of then motor is of

I am having problem to write code someone please give me idea
 
Is this a real scenario? because you can't connect the motor directly to the micro... I say this because the motor will be driven through a transistor of some kind!!

Pseudo code
Test switch
If switch is high
switch motor on​
else
switch motor off​
goto beginning

Test
JB or JNB ( Jump if Bit is on) (Jump if Bit is Not on)
Code:
JB P0.1, ON
Motor on or off
SETB or CLR
Code:
ON:
   SETB P1.1
   CLR  P1.2
OFF:
   CLR P1.1
   CLR  P1.2
 
I think we need to give instruction for every pin if we use
please check out me If i wrong

org 00000 h
on:
SETB P1.1 ,positive ; motor on
SETB P1.2 ,negative ; motor on
off:
CLR P1.1 , positive ; motor off
CLR P1.2 negative ; motor off
loop:
JB Po.1 ; jump if bit is on
sjmp loop
End
 
You wouldn't write the code like this as it will be very messy

Code:
   org 00000 h
on:
   SETB P1.1 ,positive ; motor on
   SETB P1.2 ,negative ; motor on
off:
   CLR P1.1 , positive ; motor off
   CLR P1.2 negative ; motor off
loop: 
   JB Po.1 ; jump if bit is on 
   sjmp loop
End
You would give it a bit of structure like so
Code:
    org    0              ; You need a reset vector
    sjmp    main    ; At least 0x30 to clear vector space

    org 0x30
main:                ; start here
    jb    P0.1,on
    jnb    P0.1,OFF
    sjmp    main

on:    setb    P1.0      ; On
    clr    P1.1
    sjmp    main

off:    clr    P1.0       ; Off
    clr    P1.1
    sjmp    main
    end
 
ON:
SETB P1.1
CLR P1.2
you wrote this in your code what does it mean i think if we set bit it means motor is on but if we clear it means motor is off please clear my confusen
 
If you have the motor on two pins P1.1 and P1.2, then one pin needs to be high and one needs to be low..

motor.png
Or are you thinking differently!!!

P.S. I know you can't attach a motor like this or the chip wouldn't last very long... It's for visual reference.
 
vead said:
Why can't we interface motor directly to microcontroller?

For the same reason a human requires a jack or a hydraulic lift to lift a car.

Micros are not designed to source load current...ESPECIALLY not an 8051. The 8051 is not "push-pull" output. It uses a weak pull up/strong pull down configuration.

On the MCS-51 family of microcontrollers (i.e. all 8051/8052 based microcontrollers), with the exception of non-legacy port equipped variants, a pin's source current (i.e. electron current passed from the pin to Vcc when the pin is set high) is very low relative to a pin's sink current (i.e. electron current passed from GND to the pin when the pin is set low). But even the rated sink current is no greater than 15mA per pin, and you cannot sink 15mA on every pin simultaneously.

Aside from the current demand of a motor, motors are an inductive load. There will be counter voltages as the field expands/collapses, and micros are not designed to deal with this. Even relays are not directly driven from a micro's I/O pins for this very reason.

Micros are designed to provide high and low voltage signals used to drive high current switching devices such as bipolar transistors, MOSFET's, etc etc. Transistors require very little current to switch them on/off (which the micro can more than source) while they can source/sink LOTS of current on their collectors/drains for driving high current loads. On a standard bipolar transistor, the collector junction would pass the motor current while the micro would simply provide the base current, which is very low in comparison to the motor current. A darlington pair could sink 10+ amps on its collector junction while only requiring maybe 5mA of base current to saturate the base, which a micro can more than deal with.
 
Last edited:
Likewise Ian. Been super busy with the little one since earlier this year but now that he's learned to crawl and now learning to stand, he's on his way to autonomy, which frees up my time a bit.

So I'm back here on good ol' ETO. Eventually I'll be back to typing up my tutorial articles, which I highly enjoy doing.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top