Advertisement
jack96013

FinalExamPractice

Jan 8th, 2021
3,796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 15.34 KB | None | 0 0
  1.  
  2. list p=16F877A
  3. #include <p16f877A.inc> ; Include file locate at defult directory
  4. ; CONFIG
  5. ; __config 0xFF7A
  6.  __CONFIG _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF
  7.  
  8. ;
  9. VAL_DELAY_1MS_COUNT equ .40 ; 1ms delay valum
  10. ADDR_DELAY_1MS_COUNT equ 0x20 ; Defined temp reg. for 1ms delay
  11. VAL_DELAY_100MS_COUNT equ .100
  12. ADDR_DELAY_100MS_COUNT equ 0x21            ; Defined delay reg.
  13.  
  14. VAL_DELAY_CUSTOM_COUNT equ .80 ; 1ms delay valum
  15. ADDR_DELAY_CUSTOM_COUNT equ 0x22 ; Defined temp reg. for 1ms delay
  16.  
  17.  
  18.  
  19. ADDR_DISP equ 0x26 ;轉 7 Segment
  20. ADDR_BCD_SOU equ 0x27 ;轉BCD (個位)
  21. ADDR_BCD_SOU2 equ 0x2F ;轉BCD (2組)
  22. ADDR_BCD_TEN equ 0x28 ;轉BCD 十位
  23. ADDR_BCD_HUN equ 0x23 ;轉BCD 百位
  24. ADDR_BCD_TEMP equ 0x24
  25.  
  26. ADDR_MULTIPLIER equ 0x2B
  27. ADDR_MULTIPLICAND equ 0x2C
  28. ;### Temp For Interrupt
  29. ADDR_TEMP_STATUS equ 0x2D
  30. ADDR_TEMP_W equ 0x2E
  31.  
  32. ;ADDR_DISPLAY_MODE equ 0x30 ;<0> = 初始 <1> = 時鐘 <2> = 顯示紀錄
  33. ;### 時鐘 ###
  34. ADDR_CLOCK_DIV_1 equ 0x31;
  35. VAL_CLOCK_DIV_1 equ .121     ;83*3=249 125*2=250
  36. ADDR_CLOCK_DIV_2 equ 0x32
  37. VAL_CLOCK_DIV_2 equ .8
  38. ADDR_CLOCK_SEC equ 0x33  ;秒
  39. ADDR_CLOCK_MIN equ 0x34  ;分
  40. ADDR_CLOCK_HUR equ 0x35  ;小時
  41.  
  42. ;### 按鈕處理 ###
  43. ADDR_BUTTON_SCAN_DIV equ 0x36 ;按鈕掃描週期
  44. NUM_BUTTON_SCAN_DIV equ .20 ;按鈕掃描週期
  45.  
  46. ADDR_BUTTON_STATUS equ 0x37 ;按鈕狀態(輸入/出)
  47. ADDR_BUTTON_COUNT equ 0x38 ;按住計數
  48. ADDR_BUTTON_S0_PRESSED_COUNT equ 0x39
  49. ADDR_BUTTON_S1_PRESSED_COUNT equ 0x3A
  50. ADDR_BUTTON_S2_PRESSED_COUNT equ 0x3B
  51. ADDR_BUTTON_S3_PRESSED_COUNT equ 0x3C
  52. VAL_BUTTON_SHORT_PRESSED equ .25
  53. VAL_BUTTON_LONG_PRESSED equ .25
  54.  
  55. BUTTON_RELEASE equ .0
  56. BUTTON_PRESSED equ .1
  57. BUTTON_SHORT equ .2
  58. BUTTON_LONG equ .3
  59. ;##################
  60. ADDR_POLL equ 0x25 ;掃描顯示
  61. VAL_POLL_START equ .0
  62. VAL_POLL_END equ .7
  63.  
  64. ADDR_SEG_DIG0 equ 0x40 ;第0位顯示
  65. ADDR_SEG_DIG1 equ 0x41 ;第1位顯示
  66. ADDR_SEG_DIG2 equ 0x42 ;第2位顯示
  67. ADDR_SEG_DIG3 equ 0x43 ;第3位顯示
  68. ADDR_SEG_DIG4 equ 0x44 ;第4位顯示
  69. ADDR_SEG_DIG5 equ 0x45 ;第5位顯示  
  70. ADDR_SEG_DIG6 equ 0x46 ;第6位顯示
  71. ADDR_SEG_DIG7 equ 0x47 ;第7位顯示
  72.  
  73. ;### Timer Configuration ###
  74. VAL_TMR0_INIT equ .178
  75. VAL_TMR1_INIT_L equ 0x2C
  76. VAL_TMR1_INIT_H equ 0xCF
  77. VAL_TMR2_INIT equ .28
  78. ;### Temp For Interrupt
  79. ADDR_TEMP_STATUS equ 0x2D
  80. ADDR_TEMP_W equ 0x2E
  81.  
  82. ;### ADC Configuration ###
  83. ADDR_ADC_CHANNEL equ 0x48
  84. VAL_ADC_DIV equ .100
  85. ADDR_ADC_DIV equ 0x49
  86. VAL_ADC_CHANNEL_LEN equ .1
  87. ADDR_ADC_VAL_0 equ 0x4A
  88. ADDR_ADC_VAL_1 equ 0x4B
  89. VAL_ADC_CON1 equ b'00001110'
  90. VAL_ADC_TRISA_SAMPLING equ b'00000001'
  91. VAL_ADC_TRISA_ORIGINAL equ b'00000001'
  92.  
  93. ;### Wave Generator ###
  94. VAL_WAVE_PIN equ .7
  95.  
  96. ;
  97. ;***************************************
  98. ;           Program start              *
  99. ;***************************************
  100. org 0x0 ; reset vector
  101. goto Initial
  102. org 0x4
  103. goto INTSUB
  104.  
  105. Initial:
  106.     ;Port Configure
  107.     clrw ; W =0
  108.     clrf PCLATH
  109.     banksel TRISA ; Select to bank1
  110.     ;=== Port Configuration ===
  111.     movlw 0x06
  112.     movwf ADCON1
  113.     movlw VAL_ADC_TRISA_ORIGINAL
  114.     movwf TRISA
  115.     clrf TRISD
  116.     clrf TRISE;TEST
  117.     movlw b'01111111'
  118.     movwf TRISB
  119.  
  120.     ;=== Timer , INT ===
  121.     ;Ext,TMR0,RBPU
  122.     movlw B'00000110'
  123.     movwf OPTION_REG
  124.  
  125.     ; <1> TMR2IE: TMR2 to PR2 Match Interrupt Enable bit
  126.     ; <0> TMR1IE: TMR1 Overflow Interrupt Enable bit
  127.     movlw B'00000011'
  128.     movwf PIE1
  129.  
  130.     movlw VAL_TMR2_INIT
  131.     movwf PR2
  132.    
  133.     banksel PORTA
  134.  
  135.     ;=== Timer , INT ===    
  136.     movlw B'11100000'
  137.     movwf INTCON
  138.  
  139.     movlw B'0110101'
  140.     movwf T1CON
  141.  
  142.     movlw B'01111110' ;16x16
  143.     movwf T2CON
  144.    
  145.     clrf PIR1
  146.  
  147.     movlw VAL_TMR0_INIT
  148.     movwf TMR0 ; Timer 0 Value
  149.     movlw VAL_TMR1_INIT_L
  150.     movwf TMR1L
  151.     movlw VAL_TMR1_INIT_H
  152.     movwf TMR1H
  153.     clrf TMR2
  154.     ;=== Timer , INT ===
  155.    
  156.     bsf PORTE,0
  157.     bsf PORTE,1
  158.     movlw .0
  159.     movwf ADDR_POLL
  160.  
  161.     clrf ADDR_CLOCK_SEC
  162.     clrf ADDR_CLOCK_MIN
  163.     clrf ADDR_CLOCK_HUR
  164.  
  165.     ;clrf PORTD
  166.     movlw VAL_CLOCK_DIV_1
  167.     movwf ADDR_CLOCK_DIV_1 ;
  168.     movlw VAL_CLOCK_DIV_2
  169.     movwf ADDR_CLOCK_DIV_2
  170.  
  171.     movlw NUM_BUTTON_SCAN_DIV
  172.     movwf ADDR_BUTTON_SCAN_DIV
  173.    
  174.     movlw b'10111111'
  175.     ;movwf ADDR_DISP
  176.     ;call bcd_to_segment
  177.     ;movf ADDR_DISP,0
  178.     movwf ADDR_SEG_DIG0
  179.     movwf ADDR_SEG_DIG1
  180.     movwf ADDR_SEG_DIG2
  181.     movwf ADDR_SEG_DIG3
  182.     movwf ADDR_SEG_DIG4
  183.     movwf ADDR_SEG_DIG5
  184.     ;movlw b'10110011'
  185.     movwf ADDR_SEG_DIG6
  186.     movwf ADDR_SEG_DIG7
  187.  
  188.     bsf PORTB,7
  189.     clrf ADDR_BCD_SOU2
  190.     clrf ADDR_ADC_CHANNEL
  191.  
  192. ;
  193. ;************ Main *********************
  194. ;
  195.  
  196. Loop:
  197.     ;call test
  198.     call task_adc
  199.     call task_button ;按鈕工作
  200.     call task_clock ;計數工作
  201.     call task_digi_polling ;掃描顯示工作
  202.  
  203.     call delay_1ms ; Call delay routine
  204.     goto Loop
  205.  
  206. ;***************************************
  207. ;               Tasks                  *
  208. ;***************************************
  209. task_digi_polling: ;掃描顯示
  210.     ;Polling the digits pin
  211.     incf ADDR_POLL
  212.     movf ADDR_POLL,W
  213.     sublw VAL_POLL_END
  214.     btfsc STATUS,C
  215.         goto task_digi_polling_fin
  216.     movlw VAL_POLL_START
  217.     movwf ADDR_POLL
  218.  
  219.     task_digi_polling_fin:
  220.     movlw b'00111111'
  221.     movwf PORTA
  222.     movlw b'00000011'
  223.     movwf PORTE
  224.  
  225.     movf ADDR_POLL,0
  226.     addwf ADDR_POLL,0
  227.     addwf ADDR_POLL,0
  228.     addwf PCL
  229.  
  230.     movf ADDR_SEG_DIG0,0
  231.     bcf PORTE,1
  232.     goto seg_out
  233.  
  234.     movf ADDR_SEG_DIG1,0
  235.     bcf PORTE,0
  236.     goto seg_out
  237.  
  238.     movf ADDR_SEG_DIG2,0
  239.     bcf PORTA,5
  240.     goto seg_out
  241.  
  242.     movf ADDR_SEG_DIG3,0
  243.     bcf PORTA,4
  244.     goto seg_out
  245.  
  246.     movf ADDR_SEG_DIG4,0
  247.     bcf PORTA,3
  248.     goto seg_out
  249.  
  250.     movf ADDR_SEG_DIG5,0
  251.     bcf PORTA,2
  252.     goto seg_out
  253.  
  254.     movf ADDR_SEG_DIG6,0
  255.     bcf PORTA,1
  256.     goto seg_out
  257.  
  258.     movf ADDR_SEG_DIG7,0
  259.     bcf PORTA,0
  260.     goto seg_out
  261.  
  262.     seg_out:
  263.     movwf PORTD
  264.    
  265.     return
  266.  
  267. task_adc:
  268.     btfsc ADCON0,GO
  269.         return
  270.     btfsc PIR1,ADIF
  271.         goto adc_result
  272.     adc_start:
  273.         decfsz ADDR_ADC_DIV,f
  274.             return
  275.         movlw VAL_ADC_DIV
  276.         movwf ADDR_ADC_DIV
  277.  
  278.         movf ADDR_ADC_CHANNEL,w
  279.         addwf ADDR_ADC_CHANNEL,w
  280.         addwf PCL
  281.         movlw b'01000001'
  282.         goto adc_start_fin
  283.         movlw b'01001001'
  284.         goto adc_start_fin
  285.         adc_start_fin:
  286.             movwf ADCON0
  287.             ;重新設定PORT
  288.             banksel TRISA ; Select to bank1
  289.             movlw VAL_ADC_CON1
  290.             movwf ADCON1
  291.             movlw VAL_ADC_TRISA_SAMPLING
  292.             movwf TRISA
  293.             banksel PORTA
  294.             bsf ADCON0,GO
  295.         return
  296.     adc_result:
  297.         movlw ADDR_ADC_VAL_0
  298.         movwf FSR
  299.         movf ADDR_ADC_CHANNEL,w
  300.         addwf FSR
  301.         movf ADRESH,w
  302.         movwf INDF
  303.         bcf PIR1,ADIF
  304.  
  305.         banksel TRISA ; Select to bank1
  306.         movlw 0x06
  307.         movwf ADCON1
  308.         movlw VAL_ADC_TRISA_ORIGINAL
  309.         movwf TRISA
  310.         banksel PORTA
  311.        
  312.         incf ADDR_ADC_CHANNEL
  313.         movlw VAL_ADC_CHANNEL_LEN
  314.         subwf ADDR_ADC_CHANNEL,w
  315.         btfss STATUS,Z
  316.             return
  317.         clrf ADDR_ADC_CHANNEL
  318.         return
  319.  
  320. task_display_handle: ;顯示時間至7段
  321.     ;更新秒
  322.     movf ADDR_CLOCK_SEC,0
  323.  
  324.     call val_to_segment
  325.     movf ADDR_BCD_SOU,0
  326.     movwf ADDR_SEG_DIG0
  327.     movf ADDR_BCD_TEN,0
  328.     movwf ADDR_SEG_DIG1
  329.  
  330.     ;更新分
  331.     movf ADDR_CLOCK_MIN,0
  332.  
  333.     call val_to_segment
  334.     movf ADDR_BCD_SOU,0
  335.     movwf ADDR_SEG_DIG2
  336.     bcf ADDR_SEG_DIG2,7 ;小數點
  337.     movf ADDR_BCD_TEN,0
  338.     movwf ADDR_SEG_DIG3
  339.    
  340.     clrf ADDR_BCD_SOU2
  341.     movf ADDR_ADC_VAL_0,0
  342.     movwf ADDR_BCD_SOU
  343.     call BCD_HUN_2B
  344.     movf ADDR_BCD_SOU,w
  345.     call val_to_segment
  346.     movf ADDR_BCD_SOU,w
  347.     movwf ADDR_SEG_DIG4
  348.     movf ADDR_BCD_TEN,w
  349.     movwf ADDR_SEG_DIG5
  350.     movf ADDR_BCD_HUN,w
  351.     call val_to_segment
  352.     movf ADDR_BCD_SOU,w
  353.     movwf ADDR_SEG_DIG6
  354.     movf ADDR_BCD_TEN,w
  355.     movwf ADDR_SEG_DIG7
  356.  
  357.     ;更新時
  358.     ;movf ADDR_CLOCK_HUR,0
  359.    
  360.     ;call val_to_segment
  361.     ;movf ADDR_BCD_SOU,0
  362.     ;movwf ADDR_SEG_DIG4
  363.     ;bcf ADDR_SEG_DIG4,7
  364.     ;movf ADDR_BCD_TEN,0
  365.     ;movwf ADDR_SEG_DIG5
  366.     return
  367.  
  368. task_clock: ;達目標次數(1秒),計數一次
  369.     decfsz ADDR_CLOCK_DIV_1,f
  370.         return
  371.     movlw VAL_CLOCK_DIV_1
  372.     movwf ADDR_CLOCK_DIV_1
  373.  
  374.     decfsz ADDR_CLOCK_DIV_2,f
  375.         return
  376.     movlw VAL_CLOCK_DIV_2
  377.     movwf ADDR_CLOCK_DIV_2
  378.  
  379.     call clock
  380.     call task_display_handle
  381.     return
  382.    
  383. task_button:
  384.     decfsz ADDR_BUTTON_SCAN_DIV,f
  385.         return
  386.     movlw NUM_BUTTON_SCAN_DIV
  387.     movwf ADDR_BUTTON_SCAN_DIV
  388.     button_s1: ;開始計數
  389.         movlw b'00000010'
  390.         andwf PORTB,W
  391.         movwf ADDR_BUTTON_STATUS
  392.         movf ADDR_BUTTON_S1_PRESSED_COUNT,W
  393.         movwf ADDR_BUTTON_COUNT
  394.         call button_general
  395.  
  396.         movwf ADDR_BUTTON_S1_PRESSED_COUNT
  397.         btfss ADDR_BUTTON_STATUS,BUTTON_SHORT ;短按檢測
  398.             goto button_s1_fin
  399.         ;### EXECUTE ###
  400.         goto Initial
  401.         ;##### END #####
  402.         goto button_s1_fin
  403.     button_s1_fin:
  404.     return
  405.  
  406. ;***************************************
  407. ;               Other                  *
  408. ;***************************************
  409. bcd_to_segment: ;BCD 轉 7 段碼
  410.     ;Edge Check
  411.     movlw ADDR_DISP
  412.     sublw .9
  413.     btfsc STATUS,0
  414.     return
  415.     movf ADDR_DISP,0
  416.     addwf PCL
  417.     retlw b'11000000' ;0
  418.     retlw b'11111001' ;1
  419.     retlw b'10100100' ;2
  420.     retlw b'10110000' ;3
  421.     retlw b'10011001' ;4
  422.     retlw b'10010010' ;5
  423.     retlw b'10000010' ;6
  424.     retlw b'11111000' ;7
  425.     retlw b'10000000' ;8
  426.     retlw b'10010000' ;9
  427.  
  428. clock: ;時鐘
  429.     ;call test
  430.     ;=====SEC======
  431.     incf ADDR_CLOCK_SEC,1
  432.    
  433.     movlw .60
  434.     subwf ADDR_CLOCK_SEC,0
  435.     btfss STATUS,2
  436.     goto clock_fin
  437.     clrf ADDR_CLOCK_SEC
  438.     ;=====MIN======
  439.     min:
  440.     incf ADDR_CLOCK_MIN,1
  441.     movlw .60
  442.     subwf ADDR_CLOCK_MIN,0
  443.     btfss STATUS,2
  444.     goto clock_fin
  445.     clrf ADDR_CLOCK_MIN
  446.     ;=====HOUR======
  447.     hour:
  448.     incf ADDR_CLOCK_HUR,1
  449.     movlw .24
  450.     subwf ADDR_CLOCK_HUR,0
  451.     btfss STATUS,2
  452.     goto clock_fin
  453.     clrf ADDR_CLOCK_HUR
  454.     clock_fin:
  455.     return
  456.    
  457. val_to_segment: ;原值轉 7 段顯示碼
  458.     movwf ADDR_BCD_SOU
  459.     call BCD
  460.    
  461.     movf ADDR_BCD_SOU,0 ;個位轉SEG
  462.     movwf ADDR_DISP
  463.     call bcd_to_segment
  464.     movwf ADDR_BCD_SOU
  465.    
  466.     movf ADDR_BCD_TEN,0 ;十位轉SEG
  467.     movwf ADDR_DISP
  468.     call bcd_to_segment
  469.     movwf ADDR_BCD_TEN
  470.     return
  471.  
  472. digi_clear:
  473.     movlw .0
  474.     movwf ADDR_DISP
  475.     call bcd_to_segment
  476.     movwf ADDR_SEG_DIG0
  477.     movwf ADDR_SEG_DIG1
  478.     movwf ADDR_SEG_DIG2
  479.     bcf ADDR_SEG_DIG2,7
  480.     movwf ADDR_SEG_DIG3
  481.     movwf ADDR_SEG_DIG4
  482.     bcf ADDR_SEG_DIG4,7
  483.     movwf ADDR_SEG_DIG5
  484.     return
  485.  
  486.  
  487.  
  488. ;用法port & mask 後帶入 ADDR_BUTTON_STATUS,按住計數器帶入ADDR_BUTTON_COUNT
  489. ;結束後 ADDR_BUTTON_STATUS ,W為COUNT
  490. ;...<3> <2> <1> <0>
  491. ;    0   0   0   1 ;為鬆開狀態
  492. ;    0   0   1   0 ;為按住狀態
  493. ;    0   1   0   0 ;為短按
  494. ;    1   0   0   0 ;為長按
  495. button_general:
  496.     movf ADDR_BUTTON_STATUS,w
  497.     btfss STATUS,Z
  498.         goto button_off
  499.     button_on:
  500.         clrf ADDR_BUTTON_STATUS
  501.         bsf ADDR_BUTTON_STATUS,BUTTON_PRESSED ;表示按住
  502.         comf ADDR_BUTTON_COUNT,w ;溢位檢查
  503.         btfsc STATUS,Z
  504.             goto button_general_finish
  505.         incf ADDR_BUTTON_COUNT
  506.         movlw VAL_BUTTON_LONG_PRESSED
  507.         subwf ADDR_BUTTON_COUNT,w
  508.         btfss STATUS,C
  509.             goto button_general_finish
  510.         ;差值 > 0 表示長按,利用移入255達到死鎖
  511.         movlw .255
  512.         movwf ADDR_BUTTON_COUNT
  513.         ;### Long Pressed ###
  514.         bcf ADDR_BUTTON_STATUS,BUTTON_PRESSED ;
  515.         bsf ADDR_BUTTON_STATUS,BUTTON_LONG ;表長按
  516.         ;####################
  517.         goto button_general_finish
  518.     button_off:
  519.         clrf ADDR_BUTTON_STATUS
  520.         bsf ADDR_BUTTON_STATUS,BUTTON_RELEASE ;表示鬆開
  521.         movf ADDR_BUTTON_COUNT,w
  522.         btfsc STATUS,Z
  523.             goto button_general_finish
  524.         ;Non Zero means the button has been pressed
  525.         movlw VAL_BUTTON_SHORT_PRESSED
  526.         subwf ADDR_BUTTON_COUNT,w
  527.         clrf ADDR_BUTTON_COUNT
  528.         btfsc STATUS,C
  529.             goto button_general_finish
  530.         ;### Long Pressed ###
  531.         bcf ADDR_BUTTON_STATUS,BUTTON_PRESSED
  532.         bsf ADDR_BUTTON_STATUS,BUTTON_SHORT ;表短按
  533.         ;####################
  534.         goto button_general_finish
  535.         ;===== End ======
  536.     button_general_finish:
  537.         movf ADDR_BUTTON_COUNT,w
  538.            return
  539.  
  540. INTSUB:
  541.     ;Backup Register
  542.     movwf ADDR_TEMP_W ;Backup W
  543.     swapf STATUS,w ; Backup STATUS (swaped)
  544.     movwf ADDR_TEMP_STATUS
  545.     ;### Exec ###
  546.  
  547.     btfsc INTCON,TMR0IF
  548.         goto INT_T0
  549.     btfsc PIR1,TMR1IF
  550.         goto INT_T1
  551.     btfsc PIR1,TMR2IF
  552.         goto INT_T2
  553.     goto INTSUB_RESTORE
  554.  
  555.     ;############
  556.     ;Restore Register
  557.     INT_T0:
  558.        
  559.         INT_T0_RESTORE:
  560.             bcf INTCON,TMR0IF
  561.             movlw VAL_TMR0_INIT
  562.             movwf TMR0
  563.             goto INTSUB_RESTORE
  564.     INT_T1:
  565.        
  566.  
  567.         INT_T1_RESTORE:
  568.             bcf PIR1,TMR1IF
  569.             movlw VAL_TMR1_INIT_H
  570.             movwf TMR1H
  571.             movlw VAL_TMR1_INIT_L
  572.             movwf TMR1L
  573.             goto INTSUB_RESTORE
  574.     INT_T2:
  575.         call task_wave
  576.         INT_T2_RESTORE:
  577.             bcf PIR1,TMR2IF
  578.             goto INTSUB_RESTORE
  579.     INTSUB_RESTORE:
  580.         swapf ADDR_TEMP_STATUS,w
  581.         movwf STATUS
  582.         swapf ADDR_TEMP_W,f
  583.         swapf ADDR_TEMP_W,w
  584.         bcf INTCON,INTF ;Clear Flag
  585.         RETFIE
  586.  
  587. task_wave:
  588.     btfss PORTB,VAL_WAVE_PIN
  589.         goto wave_on
  590.     bcf PORTB,VAL_WAVE_PIN
  591.     return
  592.     wave_on:
  593.     bsf PORTB,VAL_WAVE_PIN
  594.     return
  595.        
  596. BCD: ;轉 BCD 碼
  597.     clrf ADDR_BCD_TEN
  598.     BCD_TEN:
  599.         movlw .10
  600.         subwf ADDR_BCD_SOU,0
  601.         btfss STATUS,0
  602.             return
  603.         movwf ADDR_BCD_SOU
  604.         incf ADDR_BCD_TEN,1
  605.         goto BCD_TEN
  606.  
  607. BCD_HUN_2B:
  608.     clrf ADDR_BCD_HUN
  609.     BCD_HUN_LOOP:
  610.     movlw .100
  611.     subwf ADDR_BCD_SOU,0
  612.     btfsc STATUS,C
  613.         goto BCD_HUN_NOBARROW
  614.     movwf ADDR_BCD_TEMP
  615.     movlw .1
  616.     subwf ADDR_BCD_SOU2,W
  617.     btfss STATUS,C
  618.         return
  619.     movwf ADDR_BCD_SOU2
  620.     movf ADDR_BCD_TEMP,W
  621.     movwf ADDR_BCD_SOU
  622.     incf ADDR_BCD_HUN
  623.     goto BCD_HUN_LOOP
  624.     BCD_HUN_NOBARROW:
  625.     movwf ADDR_BCD_SOU
  626.     incf ADDR_BCD_HUN
  627.     goto BCD_HUN_LOOP
  628.    
  629. MULTI:
  630.     clrw
  631.     MULTI_LOOP
  632.     addwf ADDR_MULTIPLICAND,0
  633.     decfsz ADDR_MULTIPLIER,1
  634.         goto MULTI_LOOP
  635.     return
  636. ;-------- 100 ms delay routine ----------
  637. delay_100ms:
  638. movlw VAL_DELAY_100MS_COUNT
  639. movwf ADDR_DELAY_100MS_COUNT
  640.     loop_ms
  641.     call delay_1ms
  642.     decfsz ADDR_DELAY_100MS_COUNT,f
  643.     goto loop_ms
  644.     return
  645.    
  646. ;-------- Cutom ms delay routine -----------
  647. delay_Custom:
  648.     movlw VAL_DELAY_CUSTOM_COUNT
  649.     movwf ADDR_DELAY_CUSTOM_COUNT
  650.     dec_loop_500u
  651.     call D_short
  652.     decfsz ADDR_DELAY_CUSTOM_COUNT,f
  653.     goto dec_loop_500u
  654.     return
  655.    
  656. ;-------- 1 ms delay routine -----------
  657. delay_1ms:
  658.     movlw VAL_DELAY_1MS_COUNT
  659.     movwf ADDR_DELAY_1MS_COUNT
  660.     dec_loop
  661.     call D_short
  662.     decfsz ADDR_DELAY_1MS_COUNT,f
  663.     goto dec_loop
  664.     return
  665. ;
  666. ;--------     Delay 5uS    ------------- 25ms
  667. D_short
  668.     call D_ret ; 1uS * 4 + 1uS = 10uS
  669.     call D_ret
  670.     call D_ret
  671.     call D_ret
  672.     nop
  673.     nop
  674.     D_ret return
  675. ;
  676. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement