I have one switch and one LED. the positive edge of switch is connected to port pin PO.1 and negative edge is connected to port pin PO.2 and LED 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 LED is on
if switch is of then LED is of
I am trying to make assembly code please check out code
Code:
org o h
main:
jb P0.1, on
jb P0.2, on ; switch is closed
jnb P0.1, off ; switch is open
jnb P0.2, off
sjmp main
ON:
setb P1.1 ; led on
clr P1.2
sjmp main
OFF:
clr P1.1 ; led off
clrP1.2
sjmp main
end
That's the code I gave you for the motor!!
If you have one LED connected to P1.1
And one switch on P0.1
Code:
org o h
main:
jb P0.1, on ; switch is closed
jnb P0.1, off ; switch is open
sjmp main
OFF:
setb P1.1 ; led off
sjmp main
ON:
clr P1.1 ; led on
sjmp main
end
You need to sink the LED on Port 1 ( not sure if they are open collectors.. )
That's the code I gave you for the motor!!
If you have one LED connected to P1.1
And one switch on P0.1
Code:
org o h
main:
jb P0.1, on ; switch is closed
jnb P0.1, off ; switch is open
sjmp main
OFF:
setb P1.1 ; led off
sjmp main
ON:
clr P1.1 ; led on
sjmp main
end
View attachment 82887
You need to sink the LED on Port 1 ( not sure if they are open collectors.. )
let me clear one thing
the positive edge of LED is connected to port pin P1.1 and negative edge is connected to P1.2
so why you are using only one pin P1.1 why you are not using P1.2
Why on earth would you want to use TWO pins to light an LED????
Some pins on the micro can't supply 5v.... All pins can sink current... the pins on a 8051 can only sink / source less than 10mA.... I think only Port 0 can supply as well as sink...
Why on earth would you want to use TWO pins to light an LED????
Some pins on the micro can't supply 5v.... All pins can sink current... the pins on a 8051 can only sink / source less than 10mA.... I think only Port 0 can supply as well as sink...
I can think of one reason why you want to connect both legs of the LED to the 8051. In case someone wants to connect more LEDs to less number of pin on the 8051. In the attached schematic, I can connect 8 LED to 5 I/O pins. With a little more thought, you can connect even more LEDs to the same amount of pins.
Though I've never tried out whether it would work, this was mentioned in one of the Ap notes in microchips " Bag of Tricks". Only problem is that only 4 LEDs can be switched on at the same time....
I can think of one reason why you want to connect both legs of the LED to the 8051. In case someone wants to connect more LEDs to less number of pin on the 8051. In the attached schematic, I can connect 8 LED to 5 I/O pins. With a little more thought, you can connect even more LEDs to the same amount of pins.
Though I've never tried out whether it would work, this was mentioned in one of the Ap notes in microchips " Bag of Tricks". Only problem is that only 4 LEDs can be switched on at the same time....