Need help in Assembly language

Discussion in 'Programmer's Corner' started by mpcotuong, Sep 15, 2010.

  1. mpcotuong

    Thread Starter Member

    Aug 26, 2010
    170
    0
    Hi All,

    I am very new for assemly language. How you write delay function for 10 second? or 15 second? Please help.

    Thanks, for your help

    Kevin
     
  2. lihle

    Active Member

    Apr 12, 2009
    83
    3
    man you need to tell us what crystal oscillator you are using then i can give you those delays.

    lihle
    'trying to read books is worth much'
     
  3. lihle

    Active Member

    Apr 12, 2009
    83
    3
    to speed up things if you are using a 4 MHz crystal oscillator here is the code.
    ; Delay = 10 seconds
    ; Clock frequency = 4 MHz

    ; Actual delay = 10 seconds = 10000000 cycles
    ; Error = 0 %

    cblock
    d1
    d2
    d3
    endc

    delay10sec ;9999995 cycles
    movlw 0x5A
    movwf d1
    movlw 0xCD
    movwf d2
    movlw 0x16
    movwf d3
    Delay_0
    decfsz d1, f
    goto $+2
    decfsz d2, f
    goto $+2
    decfsz d3, f
    goto Delay_0

    ;5 cycles
    goto $+1
    goto $+1
    nop
    return

    hope this code will help you.

    lihle
     
  4. mpcotuong

    Thread Starter Member

    Aug 26, 2010
    170
    0
    I have the target 10 second as following

    mov cnt, #40 ; 40 *.25 = 10 seconds
     
  5. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,699
    907
    mpcotuong likes this.
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    This is just a friendly tip:). But your code is very hard to read. If you use MPLAB you can include prepared header files for your chip. It will be more easy for your self and other to read your code. This is an example. You will find header files in the folder
    \<program install folder>\Microchip\MPASM Suite
    And by the way. No skimping on the comments:p
    Code ( (Unknown Language)):
    1.  
    2. #include <p16F690.inc>
    3. __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_ON & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
    4. cblock 0x20
    5. Delay1 ; Define two file registers for the
    6. Delay2 ; delay loop
    7. endc
    8.  
    9. org 0
    10. Start:
    11. bsf STATUS,RP0 ; select Register Page 1
    12. movlw 0
    13. tris PORTC ;test instr
    14. ;bcf TRISC,0 ; make IO Pin B.0 an output
    15. bcf STATUS,RP0 ; back to Register Page 0
    16. MainLoop:
    17. bsf PORTC,0 ; turn on LED C0
    18. OndelayLoop:
    19. decfsz Delay1,f ; Waste time.
    20. goto OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
    21. decfsz Delay2,f ; The outer loop takes and additional 3 instructions per lap * 256 loops
    22. goto OndelayLoop ; (768+3) * 256 = 197376 instructions / 1M instructions per sec sec.
    23. ; call it a two-tenths of a second.
    24.  
    25. bcf PORTC,0 ; Turn off LED C0
    26. OffDelayLoop:
    27. decfsz Delay1,f ; same delay as above
    28. goto OffDelayLoop
    29. decfsz Delay2,f
    30. goto OffDelayLoop
    31. goto MainLoop ; Do it again...
    32. end
    33.  
    34.  
     
    mpcotuong likes this.
Loading...