1. 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.
    Dismiss Notice

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

Discussion in 'Microcontrollers' started by ikelectro, Apr 6, 2013.

  1. ikelectro

    ikelectro Member

    Joined:
    Aug 25, 2012
    Messages:
    388
    Likes:
    4
    Location:
    Kolkata, Proud to be an Indian.
    ok... I'll do it in bread board.... and can i use 220Ω???
     
  2. ikelectro

    ikelectro Member

    Joined:
    Aug 25, 2012
    Messages:
    388
    Likes:
    4
    Location:
    Kolkata, Proud to be an Indian.
    Ok, I have done it with bread board.. 220Ω and LED......:D
     
  3. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,164
    Likes:
    910
    Location:
    Rochdale UK
    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..
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. ikelectro

    ikelectro Member

    Joined:
    Aug 25, 2012
    Messages:
    388
    Likes:
    4
    Location:
    Kolkata, Proud to be an Indian.

    but Ian, I dont know how to write the program. what you have written, should copy and paste???
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,164
    Likes:
    910
    Location:
    Rochdale UK
    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 (ASM):
       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...
     
  7. ikelectro

    ikelectro Member

    Joined:
    Aug 25, 2012
    Messages:
    388
    Likes:
    4
    Location:
    Kolkata, Proud to be an Indian.
    yes, you are right 100%. I have to understand the codes and how it works... I'm trying hard......
     
  8. absf

    absf Active Member

    Joined:
    Jun 18, 2012
    Messages:
    206
    Likes:
    27
    Location:
    Malaysia
    Hi,

    Can I rotate P1 directly using

    Code (text):

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

    Code (text):

      mov   A,01
      rl       A
      mov   p1,a
     
    Allen
     
  9. ikelectro

    ikelectro Member

    Joined:
    Aug 25, 2012
    Messages:
    388
    Likes:
    4
    Location:
    Kolkata, Proud to be an Indian.
    Hi, plz tell me what is wrong in the code????
    but the LEDs are working.... screen shot.JPG
     
  10. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,164
    Likes:
    910
    Location:
    Rochdale UK
    Nothing!! The program is ended..

    If you need repetition, then you need to include a super loop.


    Code (text):
    main:
       op 1
       op 2
       op 3
       op 4
       sjmp  main
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,164
    Likes:
    910
    Location:
    Rochdale UK
    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.

    http://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..
     
    • Like Like x 1
  12. absf

    absf Active Member

    Joined:
    Jun 18, 2012
    Messages:
    206
    Likes:
    27
    Location:
    Malaysia
    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
     
  13. ikelectro

    ikelectro Member

    Joined:
    Aug 25, 2012
    Messages:
    388
    Likes:
    4
    Location:
    Kolkata, Proud to be an Indian.
    Code (text):
           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????
     
  14. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,164
    Likes:
    910
    Location:
    Rochdale UK
    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...
     
  15. ikelectro

    ikelectro Member

    Joined:
    Aug 25, 2012
    Messages:
    388
    Likes:
    4
    Location:
    Kolkata, Proud to be an Indian.
    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?????
     
  16. absf

    absf Active Member

    Joined:
    Jun 18, 2012
    Messages:
    206
    Likes:
    27
    Location:
    Malaysia
  17. ikelectro

    ikelectro Member

    Joined:
    Aug 25, 2012
    Messages:
    388
    Likes:
    4
    Location:
    Kolkata, Proud to be an Indian.
  18. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,164
    Likes:
    910
    Location:
    Rochdale UK
    Simple delays are easy to implement

    Here are some delays..

    Code (ASM):

    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...
     
  19. ikelectro

    ikelectro Member

    Joined:
    Aug 25, 2012
    Messages:
    388
    Likes:
    4
    Location:
    Kolkata, Proud to be an Indian.
    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 (text):
           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....
     
  20. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,164
    Likes:
    910
    Location:
    Rochdale UK
    What's not to understand... this is as simple as it gets...

    Code (ASM):

        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 (ASM):

        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
     
     
  21. ikelectro

    ikelectro Member

    Joined:
    Aug 25, 2012
    Messages:
    388
    Likes:
    4
    Location:
    Kolkata, Proud to be an Indian.
    can you just describe elaborately this part......

    Code (text):
    Delay:  mov R1,#010h
    Dy1:    mov R2,#010h
    Dy2:    djnz    R2,Dy2
        djnz    R1,Dy1
        ret
     

Share This Page