wish to learn microcontroller....... need your help

Status
Not open for further replies.
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..
 

but Ian, I dont know how to write the program. what you have written, should copy and paste???
 
You still need to learn.... Me doing it all won't teach you jack s**t...

You need to get the feel of each command..

mov... how, where and when...
sjmp,ljmp...acall, lcall...

Jmp + dptr...

I can write the routines but you must understand what's going on...

Code:
   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

Without any understanding the code is useless to you....I mean.. What do you think it's doing...
 
Hi,

Can I rotate P1 directly using

Code:
 mov  p1,01
 RL   P1

or I have to load Acc with 01, rotate, then copy to P1

Code:
  mov   A,01
  rl       A
  mov   p1,a

Allen
 
absf You need to download the instruction set... This will tell you the addressing modes.


"What are addressing modes" I hear you cry!!

Take the command ... mov

This can move data from --> to registers.. BUT some registers can't do some functions, whilst others can.

https://www.electro-tech-online.com/custompdfs/2013/04/doc0509_Inst_51_set_manual.pdf

The instruction set...

Here is a couple of examples of direct and indirect addressing..
 
Thanks for the pdf file. I have downloaded it and will read it tonight. If there's anything I don't understand, I'll post the question here again.

Cheers

Allen
 
Code:
       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

if I write these program into the micro, then will it work?(it is working in the micro)
what will be frequency of the LED's to turn on and off????
 
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...
 

I have tried almost 15mnts to get the delay. but no result... can you plz show me how to get the delay in the code that I poeted in post no.92?????
 
Simple delays are easy to implement

Here are some delays..

Code:
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

These delays gave me small medium and large Dy1, delay5 and delay10

They aren't 5 mS and 10 mS as implied... more like 4 and 12 but they do what I want... It was for a toshiba T6963C display...
 
Ian, sorry to say that I cant do anything because i cant manage to know or understand the codes. what does the code will act in physically.
what I understand that the post 92 is showing. or here it is:

Code:
       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
even i cant understand the how the delay should I write....
 
What's not to understand... this is as simple as it gets...

Code:
	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

You can place delays after changes in port status like this..

Code:
	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
 
can you just describe elaborately this part......

Code:
Delay:	mov	R1,#010h
Dy1:	mov	R2,#010h
Dy2:	djnz	R2,Dy2
	djnz	R1,Dy1
	ret
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…