;****************************************************** ;* LED_INC1.ASM ;* PORTC外接LED,輸出值由0開始每隔一段Delay時間加1 ;****************************************************** list p=16F877 #include ; VAL_US equ .249 ; 1ms delay 給定初值 VAL_MS equ .250 ; 呼叫1ms Delay之次數 count equ 0x20 ; 1ms delay 變數位址 count_ms equ 0x21 ; 呼叫1ms Delay之變數位址. VAL_S equ .50 count_s equ 0x22 ; ;****** 程式開始 ********************* org 0x00 ; reset vector nop ; Reserve for MPLAB-ICD initial: banksel TRISC ; Select to bank1 clrf TRISC ; PORTC = Output banksel PORTC ; Select to bank0 clrf PORTC ; Clear PORTC start: incf PORTC,f ; PORTC = PORTC + 1 call delay_s ; Call delay routine goto start ; delay_s: movlw VAL_S movwf count_s loop_s call dly_tmr0 decfsz count_s,f goto loop_s return dly_tmr0: bcf STATUS,C banksel OPTION_REG movlw b'000001111' movwf OPTION_REG banksel TMR0 clrf TMR0 loop movlw .250 subwf TMR0,w btfss STATUS,C goto loop return ;-------- 250 ms delay routine ---------- delay_250ms: movlw VAL_MS movwf count_ms loop_ms call delay_1ms decfsz count_ms,f goto loop_ms return ; ;-------- 1 ms delay routine ----------- delay_1ms: nop movlw VAL_US movwf count dec_loop nop decfsz count,f goto dec_loop return ; end