Holey_yan

20141023_KUAS_Assignment_Timer

Oct 27th, 2014
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Date:     20141023
  2. ; Project:  Timer
  3. ; Group:    Six(6)
  4. ; Maker:    Yan
  5. ; E-Mail:   [email protected]
  6.  
  7. LED EQU P1
  8.     ORG 0000h
  9. REFRESH:
  10.     MOV TMOD,   #00010001b  ; Set Timer to work in Mode 1 (16-bit Timer)
  11.     MOV A,  #11111111b
  12.  
  13. ; Make a 8-Bit Up-Counter
  14. LOOP:
  15.     DEC A
  16.     MOV LED,    A
  17.     CALL    DELAY
  18.     MOV B,  #5
  19.     CJNE    A,  #11100000b, LOOP    ; Compare two numbers. If it's not equal, the program will goto the specified function.
  20.                         ; Like this. If (A != B),the program will goto the function [LOOP].
  21. SHOW:
  22.     MOV LED,    #081h
  23.     CALL    DELAY
  24.     MOV LED,    #042h
  25.     CALL    DELAY
  26.     MOV LED,    #024h
  27.     CALL    DELAY
  28.     MOV LED,    #018h
  29.     CALL    DELAY
  30.     MOV LED,    #081h
  31.     CALL    DELAY
  32.     MOV LED,    #042h
  33.     CALL    DELAY
  34.     MOV LED,    #024h
  35.     CALL    DELAY
  36.     MOV LED,    #018h
  37.     CALL    DELAY
  38.     DJNZ    B,  SHOW
  39.     CALL    REFRESH
  40.  
  41. ;----------------Totle can delay about [130ms]----------------
  42. DELAY:
  43.     MOV R4, #2  ;Run 2 time
  44.    
  45. TIMER_0:
  46.     ; Set Timer count bit = [0000 0000] = 65535 * 1us = 65535 = 65ms
  47.     MOV TL0,    #000h
  48.     MOV TH0,    #000h
  49.    
  50.     ;Turn on Timer
  51.     SETB    TR0
  52.  
  53. ; Wait for Timer stop(Timer interrupt Flag)
  54. WAIT_0:
  55.     JBC TF0,    OVER
  56.     JMP WAIT_0
  57.  
  58. OVER:
  59.     CLR TF0 ; Clear Timer interrupt Flag
  60.     DJNZ    R4, TIMER_0
  61.     RET
  62. ;-------------------------------------------------------------
  63.     END
Advertisement
Add Comment
Please, Sign In to add comment