10 F2XX , PWM ???
|
||||
---|---|---|---|---|
資深會員
|
笨鴨我 ,有個地方不了 ??????
煩請大哥能解惑囉!!! 謝謝啦 !!!! 那就是這麼個指令 讓笨鴨我左思右不解 -------> btfsc STATUS,2 <----------------- 2 又表示甚麼呢 ???? 全文如下----> ; File Name:PIC10F206_04.asm, by John Massa, Nov 20, 2004, Ver 1.00 ; Description: Press the pushbutton and the LED will pulsate on and off. LIST ; P10F206.INC Standard Header File, Version 1.01 Microchip Technology, Inc. NOLIST #include <p10F206.inc> ; processor specific variables ; Configure: Controls the reset pin, code protect, oscillator selection, WDT. __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF ;-----[Defines & Variable Assignments]--------------------------------------- cblock 0x08 COUNT ; Count buffer COUNT1 ; Count buffer #1 PWM_BUF ; PWM buffer endc ;-----[Reset Vector]--------------------------------------------------------- ORG 0x000 ; PIC goes here (Origin of code) after reset. movwf OSCCAL ; Load the oscillator calibration factor. goto init ; go to initialization routine ;-----[Initialization]------------------------------------------------------- init ;-----[OPTION]--------------------------------------------------------------- ; OPTION register controls wake on GP0,1,3 change, GP0,1,3 pull-ups, TM0, etc movlw b'10000111' ; Set pull-ups only, max pre-scaler OPTION ; ;-----[CMCON0]--------------------------------------------------------------- ; Comparator control register movlw b'10001111' ; Turn-off the comparator, enable the I/O pins. movwf CMCON0 ;-----[TRIS]----------------------------------------------------------------- ; TRIS (reg#) tri-state I/O register. All I/O pins default to inputs at reset. movlw b'00001000' ; Set GPIO pin 3 to an input, pins 0 - 3 to outputs. TRIS GPIO ; Register 06h ;-----[Main routine]--------------------------------------------------------- main ; Routine pulsates an LED connected to GP0 thru 220 Ohms btfsc GPIO,3 ; Press the pushbutton to begin goto main ; ...Loop, if the pushbutton is not pressed clrf COUNT ; The reg COUNT causes the subroutine to loop 255 times. clrf COUNT1 ; The reg COUNT1 sets the PWM value clrf PWM_BUF ; The reg PWM_BUF holds the PWM ratio of 'on' to 'off' bcf GPIO,0 ; Start with the LED turned off main1 movf COUNT1,W ; Transfer the value in reg COUNT1 to reg PWM_BUF movwf PWM_BUF call pwm incfsz COUNT1,F ; Has COUNT1 counted from 0 to 255? goto main1 ; ...No, loop again main2 decf COUNT1,F ; ...Yes, and now COUNT1 holds the decrementing PWM value main3 movf COUNT1,W ; Transfer the value in reg COUNT1 to reg PWM_BUF movwf PWM_BUF call pwm decfsz COUNT1,F ; Has COUNT1 counted from 255 to 0? goto main3 ; ...No, loop again goto main ; ...Yes, start over. ;-----[Subroutines]---------------------------------------------------------- pwm ; This subroutine performs pulse width modulation. movlw 0xFF ; Move the literal count of 255 to reg 'W' movwf COUNT ; ...then store it in the register 'COUNT' pwm1 movf PWM_BUF,F ; Test if the register PWM_BUF is zero btfsc STATUS,2 ; ...Is PWM_BUF = 0? goto led_off ; ...No, not yet, skip this instruction for now. led_on bsf GPIO,0 ; ...Yes, set GPIO pin-1 high, turn-on the LED decf PWM_BUF,F ; Decrement the register PWM_BUF goto exit led_off bcf GPIO,0 ; Set GPIO pin-1 low, turn-off the LED nop goto exit ; exit decfsz COUNT,F ; Has this sobroutine looped 255 times? goto pwm1 ; ...No, keep looping retlw 0 ; ...yes, return to the calling program END ; Directive to end the program
發表於: 2005/7/9 1:09
|
|||
|