Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Now we need to change the program to output all of P1 to light the LED's as required..
If you start by flashing each LED in sequence.. This is quite easy
Put 0x01 on P1..
call a delay
Rotate P1
call a delay
Rotate P1
....etc...
Then the LED's will appear to animate..
Once you get your head around it we can then move onto the data pointer... Using the data pointer you can work through a list of output variables..
org 0x00
sjmp main
org 0x40
main:
mov S0CON,#0x42
mov PCON,#0x00
mov TH1,#0xFD
mov TMOD,#0x20
setb TR1
mov S0BUF, #'A'
txbuf:
jnb TI,TXBUF
clr TI
done:
sjmp done
END
Hi, plz tell me what is wrong in the code????
but the LEDs are working....View attachment 72796
main:
op 1
op 2
op 3
op 4
sjmp main
MOV R0,#30H ;..... R0 < = 30H ( direct.. The number 0x30 is placed in A )
MOV A,@R0 ;...... A < = 40H ( indirect , using R0.. the data IN R0 is placed in A )
MOV R1,A ;...... R1 < = 40H ( direct.... The number 0x40 is placed in R1 )
MOV B,@R1 ;..... B < = 10H ( indirect... The number IN R1 is placed in B )
MOV @R1,P1 ;..... RAM (40H) < = 0CAH ( indirect )
MOV P2,P1 ;...... P2 #0CAH ( direct )
org 0000h
sjmp start
start:
clr P1.0
clr P1.3
setb P1.0
setb P1.3
clr P1.2
setb P1.2
clr P1.1
setb P1.1
setb P1.2
sjmp start
end
Oooh!! Too fast...
The 8051 normally runs with a 12mhz clock.... 12 cycles per instruction... 9 instructons + 2 for the jump... 11 cycles or 11μS per loop... The LED's will appear to be doing nothing, as they are off more than on...
The human eye will need 100mS to see the LED transitions... ( 10 pulses per second )
You will need to write a delay routine ( one in the first example we did ) to slow the action a bit...
so you just take away my opportunity to learn more from your questions????? just kidding absf.... I will follow your post there.Hi, I have started my own thread here so I wouldn't interfere with ikelectro..... thanks
https://www.electro-tech-online.com/threads/learning-8051.134119/#post1122255
Allen
Delay10: mov R6,#010h
jmp Dy1
Delay5: mov R6,#02h
Dy1: mov R5,#010h
Dy2: mov R4,#010h
Dy3: djnz R4,Dy3
djnz R5,Dy2
djnz R6,Dy1
ret
org 0000h
sjmp start
start:
clr P1.0
clr P1.3
setb P1.0
setb P1.3
clr P1.2
setb P1.2
clr P1.1
setb P1.1
setb P1.2
sjmp start
end
org 0000h
sjmp start ; goto main loop called start
start:
clr P1.0 ; bit 0 of PORT1 is cleared
clr P1.3 ; bit 3 of PORT1 is cleared
setb P1.0 ; bit 0 of PORT1 is set
setb P1.3 ; bit 3 of PORT1 is set
clr P1.2 ; bit 2 of PORT1 is cleared
setb P1.2 ; bit 2 of PORT1 is set
clr P1.1 ; bit 1 of PORT1 is cleared
setb P1.1 ; bit 1 of PORT1 is set
setb P1.2 ; bit 2 of PORT1 is set
sjmp start ; go back to start and do it again..
end
org 0000h
sjmp start ; goto main loop called start
start:
clr P1.0 ; bit 0 of PORT1 is cleared
clr P1.3 ; bit 3 of PORT1 is cleared
lcall Delay
setb P1.0 ; bit 0 of PORT1 is set
setb P1.3 ; bit 3 of PORT1 is set
lcall Delay
clr P1.2 ; bit 2 of PORT1 is cleared
lcall Delay
setb P1.2 ; bit 2 of PORT1 is set
lcall Delay
clr P1.1 ; bit 1 of PORT1 is cleared
lcall Delay
setb P1.1 ; bit 1 of PORT1 is set
setb P1.2 ; bit 2 of PORT1 is set
lcall Delay
sjmp start ; go back to start and do it again..
Delay: mov R1,#010h
Dy1: mov R2,#010h
Dy2: djnz R2,Dy2
djnz R1,Dy1
ret
end