中文字幕无码不卡一区二区三区_少妇被又大又粗又爽毛片久久黑人_91精品国产在热久久无毒不卡_久久久久久亚洲综合网站

技術熱線: 4007-888-234

技術支持

Using the PWM hardware

更新時間: 2019-03-25

16F876 PWM example code
;
; Device 16F876
    LIST P=16F876, W=2, X=ON, R=DEC
    #INCLUDE P16F876.INC
    __CONFIG    0x393A

cblock 0x20 ;start of general purpose registers
count ;used in delay routine
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
temp ;temp storage
endc

RL Equ 0x00 ;pin for left motor reverse
FL Equ 0x03 ;pin for left motor forward
RR Equ 0x04 ;pin for right motor reverse
FR Equ 0x05 ;pin for right motor forward

;pins 1 and 2 are the 2 PWM channels



    ORG 0x0000
    NOP ;for bootloader compatibility
    NOP
    NOP
    GOTO START
    ORG 0x0010

START CALL Initialise

MainLoop:
MOVLW d'64
CALL SpeedL ;both half speed forwards
CALL SpeedR
CALL Long_Delay

MOVLW d'64
CALL SpeedL ;left half speed forwards

MOVLW d'192
CALL SpeedR ;right half speed reverse
CALL Long_Delay

MOVLW d'10
CALL SpeedL ;slow speed forwards
MOVLW d'228
CALL SpeedR ;fast speed reverse
CALL Long_Delay

MOVLW d'228
CALL SpeedL ;fast speed reverse
MOVLW d'10
CALL SpeedR ;slow speed forwards
CALL Long_Delay

GOTO MainLoop

Initialise:

 BANKSEL  ADCON1 ;turn off A2D
    MOVLW    0x06
    MOVWF    ADCON1
    BANKSEL  PORTA
    BANKSEL  TRISC
    MOVLW    0 ;set PORTC as all outputs
    MOVWF    TRISC
    BANKSEL  PORTC

   MOVF     CCP1CON,W ;set CCP1 as PWM
    ANDLW    0xF0
    IORLW    0x0C
    MOVWF    CCP1CON

    MOVF     CCP2CON,W ;set CCP2 as PWM
    ANDLW    0xF0
    IORLW    0x0C
    MOVWF    CCP2CON

    MOVLW    126 ;set highest PWM value
    BANKSEL  PR2 ;over this (127) is permanently on
    MOVWF    PR2
    BANKSEL  TMR2

    MOVF     T2CON,W ;set prescaler to 16

ANDLW    0xF8 ;PWM at 2500HZ
    IORLW    0x02
    MOVWF    T2CON

    MOVF     T2CON,W ;set postscaler to 1
    ANDLW    0x07
    IORLW    0x00
    MOVWF    T2CON
   
    CLRF CCPR1L ;set PWM to zero
    CLRF CCPR2L

    BSF      T2CON, TMR2ON ;and start the timer running
RETURN

SpeedL: ;use value in W to set speed (0-127)
    MOVWF temp
BTFSC temp, 7 ;if more than 128 set speed in reverse
CALL ReverseL ;so '1' is very slow forward
BTFSS temp, 7 ;and '129' is very slow reverse
CALL ForwardL

ANDLW 0x7F
    MOVWF   CCPR1L
RETURN

SpeedR:
    MOVWF temp
BTFSC temp, 7
CALL ReverseR
BTFSS temp, 7
CALL ForwardR
ANDLW 0x7F
    MOVWF   CCPR2L
RETURN

ReverseL:
BSF PORTC, RL ;set pins for reverse
BCF PORTC, FL
RETURN

ReverseR:
BSF PORTC, RR
BCF PORTC, FR
RETURN

ForwardL:
BCF PORTC, RL ;set pins for forward
BSF PORTC, FL
RETURN

ForwardR:
BCF PORTC, RR
BSF PORTC, FR
RETURN

;Delay routines

Long_Delay
movlw d'50' ;delay 5 seconds
call Delay100W
return

Delay100W movwf count ;delay W x 100mS
d2 call Delay100 ;maximum delay 25.5 seconds
decfsz count ,f
goto d2
return

Delay255 movlw 0xff ;delay 255 mS
goto d0
Delay100 movlw d'100' ;delay 100mS
goto d0
Delay50 movlw d'50' ;delay 50mS
goto d0
Delay20 movlw d'20' ;delay 20mS
goto d0
Delay10 movlw d'10' ;delay 10mS
goto d0
Delay1 movlw d'1' ;delay 1mS
goto d0
Delay5 movlw 0x05 ;delay 5.000 ms (4 MHz clock)
d0 movwf count1
d1 movlw 0xE7
movwf counta
movlw 0x04
movwf countb
Delay_0 decfsz counta, f
goto

Using the PWM hardware

點擊次數:166次        更新時間:2017-12-12

16F876 PWM example code
;
; Device 16F876
    LIST P=16F876, W=2, X=ON, R=DEC
    #INCLUDE P16F876.INC
    __CONFIG    0x393A

cblock 0x20 ;start of general purpose registers
count ;used in delay routine
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
temp ;temp storage
endc

RL Equ 0x00 ;pin for left motor reverse
FL Equ 0x03 ;pin for left motor forward
RR Equ 0x04 ;pin for right motor reverse
FR Equ 0x05 ;pin for right motor forward

;pins 1 and 2 are the 2 PWM channels



    ORG 0x0000
    NOP ;for bootloader compatibility
    NOP
    NOP
    GOTO START
    ORG 0x0010

START CALL Initialise

MainLoop:
MOVLW d'64
CALL SpeedL ;both half speed forwards
CALL SpeedR
CALL Long_Delay

MOVLW d'64
CALL SpeedL ;left half speed forwards

MOVLW d'192
CALL SpeedR ;right half speed reverse
CALL Long_Delay

MOVLW d'10
CALL SpeedL ;slow speed forwards
MOVLW d'228
CALL SpeedR ;fast speed reverse
CALL Long_Delay

MOVLW d'228
CALL SpeedL ;fast speed reverse
MOVLW d'10
CALL SpeedR ;slow speed forwards
CALL Long_Delay

GOTO MainLoop

Initialise:

 BANKSEL  ADCON1 ;turn off A2D
    MOVLW    0x06
    MOVWF    ADCON1
    BANKSEL  PORTA
    BANKSEL  TRISC
    MOVLW    0 ;set PORTC as all outputs
    MOVWF    TRISC
    BANKSEL  PORTC

   MOVF     CCP1CON,W ;set CCP1 as PWM
    ANDLW    0xF0
    IORLW    0x0C
    MOVWF    CCP1CON

    MOVF     CCP2CON,W ;set CCP2 as PWM
    ANDLW    0xF0
    IORLW    0x0C
    MOVWF    CCP2CON

    MOVLW    126 ;set highest PWM value
    BANKSEL  PR2 ;over this (127) is permanently on
    MOVWF    PR2
    BANKSEL  TMR2

    MOVF     T2CON,W ;set prescaler to 16

ANDLW    0xF8 ;PWM at 2500HZ
    IORLW    0x02
    MOVWF    T2CON

    MOVF     T2CON,W ;set postscaler to 1
    ANDLW    0x07
    IORLW    0x00
    MOVWF    T2CON
   
    CLRF CCPR1L ;set PWM to zero
    CLRF CCPR2L

    BSF      T2CON, TMR2ON ;and start the timer running
RETURN

SpeedL: ;use value in W to set speed (0-127)
    MOVWF temp
BTFSC temp, 7 ;if more than 128 set speed in reverse
CALL ReverseL ;so '1' is very slow forward
BTFSS temp, 7 ;and '129' is very slow reverse
CALL ForwardL

ANDLW 0x7F
    MOVWF   CCPR1L
RETURN

SpeedR:
    MOVWF temp
BTFSC temp, 7
CALL ReverseR
BTFSS temp, 7
CALL ForwardR
ANDLW 0x7F
    MOVWF   CCPR2L
RETURN

ReverseL:
BSF PORTC, RL ;set pins for reverse
BCF PORTC, FL
RETURN

ReverseR:
BSF PORTC, RR
BCF PORTC, FR
RETURN

ForwardL:
BCF PORTC, RL ;set pins for forward
BSF PORTC, FL
RETURN

ForwardR:
BCF PORTC, RR
BSF PORTC, FR
RETURN

;Delay routines

Long_Delay
movlw d'50' ;delay 5 seconds
call Delay100W
return

Delay100W movwf count ;delay W x 100mS
d2 call Delay100 ;maximum delay 25.5 seconds
decfsz count ,f
goto d2
return

Delay255 movlw 0xff ;delay 255 mS
goto d0
Delay100 movlw d'100' ;delay 100mS
goto d0
Delay50 movlw d'50' ;delay 50mS
goto d0
Delay20 movlw d'20' ;delay 20mS
goto d0
Delay10 movlw d'10' ;delay 10mS
goto d0
Delay1 movlw d'1' ;delay 1mS
goto d0
Delay5 movlw 0x05 ;delay 5.000 ms (4 MHz clock)
d0 movwf count1
d1 movlw 0xE7
movwf counta
movlw 0x04
movwf countb
Delay_0 decfsz counta, f
goto {D_L_技術支持_內容瀏覽}2

decfsz countb, f
goto Delay_0

decfsz count1 ,f
goto d1
return

;end of Delay routines

    END


2

decfsz countb, f
goto Delay_0

decfsz count1 ,f
goto d1
return

;end of Delay routines

    END


404
返回首頁 |  返回上一頁
白山市| 高阳县| 台山市| 马公市| 新丰县| 同德县| 丹江口市| 绩溪县| 嵊泗县| 名山县| 南开区| 电白县| 沛县| 庆元县| 阿合奇县| 会昌县| 长寿区| 洮南市| 巴彦县| 青龙| 泽州县| 长子县| 仙居县| 石门县| 汝州市| 吐鲁番市| 万盛区| 永兴县| 阳高县| 蓬安县| 山西省| 铅山县| 通江县| 汽车| 海南省| 井陉县| 汉寿县| 阜新市| 孟村| 涞水县| 彭水|