亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pic tutorial eight.txt

?? CCP1模塊使用的有關PIC應用程序Trabicom On Board Engine Controller
?? TXT
字號:
PIC Tutorial Eight - Using the PWM hardware

--------------------------------------------------------------------------------

This tutorial is a little different, it's based on the 16F876 processor 2 board, but is designed specifically as a basic framework for a small differential drive robot, this means simply that it has two motors, one for left and one for right, with steering controlled in the same way as a tank. There seems a lot of confusion about how to use the hardware PWM, hence this simple tutorial. I've used the 16F876 as it has two PWM channels, the 16F628 only has one, the principals are exactly the same though, and the code could very simply be moved to the 16F628 if you only wanted a single PWM channel.

The PWM hardware has up to 10 bit resolution, which means you can have 1024 different steps from zero to full power, for our purposes this is a little excessive, and I've decided on 128 steps forward (0-127), and 128 steps in reverse (128-255), using a single byte for the speed and direction, with the highest bit signifying reverse.

It's actually very easy to use, once you've set the PWM up all you need to do is write to the CCPR1L and CCPR2L registers to set the speed, the listed routine uses an initialise subroutine which sets everything up, then subroutines to set the left and right motor speeds.

The initialise subroutine sets various registers, they are commented in the code, but I'll explain them here as well:

First we turn off the analogue to digital converters for PortA, they default to analogue, so it's good practice to set them as digital I/O if they are not being used, if we need them later we can turn them back on (or simply remove the code which turns them off). 
Secondly we set all the pins of PortC as outputs, we'll be using six of the pins, pins 1 and 2 are the PWM outputs, and pins 0, 3, 4 and 5 will be used for direction switching. 
Next we set the CCP1CON and CCP2CON registers to operate as PWM, CCP1 and CCP2 can operate in various modes, so we need to specifically set them as PWM. 
Then we set the PR2 register, this is a step which often causes confusion, it basically sets the value of a comparison register which the actual PWM value will be compared against, in this case we set it to 126 which means the highest PWM value will be 126, if the PWM is 127 the comparator will never reach that value and the output will stay permanently high - just as we need for full power!. If the PWM value is zero, the comparator will always equal that value as it starts, so the output will remain permanently low - again, just as we need for zero power. 
The next step is to set T2CON, this sets the frequency of the PWM, as it's derived from the 20MHz system clock it runs too at too high a frequency, there are two possibilities here - setting the prescaler divides the frequency before the PWM section, and the postscaler afterwards. For this example we set the prescaler to divide by 16, this gives us a PWM frequency of 2500Hz. 
The next two lines set both PWM channels to zero, so both motors are off when it starts up. 
The last line actually starts the PWM system by turning Timer2 on, once this line runs the PWM is independent of the rest of the code, we can do pretty well whatever we like (unless we alter the register settings) and the PWM will carry on running regardless. 
The main program itself is just a demonstration of how to use the PWM subroutines, it simply sets four different PWM and direction settings with 5 second delays in between them. It should be pretty self evident how to use it from your own programming.


; 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	$+2
		decfsz	countb, f
		goto	Delay_0

		decfsz	count1	,f
		goto	d1
		return

;end of Delay routines

    	END


      


--------------------------------------------------------------------------------
 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
午夜影视日本亚洲欧洲精品| 久久久不卡网国产精品一区| 成人小视频免费观看| 亚洲激情在线播放| 亚洲欧美在线另类| 成人欧美一区二区三区小说 | 椎名由奈av一区二区三区| 久久精品一区二区三区四区| 精品88久久久久88久久久| 在线不卡中文字幕播放| 欧美一区二区免费视频| 日韩欧美一级特黄在线播放| 久久亚洲精品小早川怜子| 久久久久久久久久久99999| 国产性天天综合网| 亚洲天堂网中文字| 亚洲自拍偷拍综合| 日本中文字幕一区二区有限公司| 日日摸夜夜添夜夜添精品视频 | 久久久久久久久伊人| 欧美精品一区二区三区久久久| ww亚洲ww在线观看国产| 国产精品蜜臀在线观看| 亚洲美女偷拍久久| 三级成人在线视频| 国产精品一区二区三区99| 成人精品一区二区三区中文字幕| 91黄色小视频| 亚洲精品一区二区三区精华液 | 91久久免费观看| 欧美伦理电影网| 久久先锋资源网| 亚洲人亚洲人成电影网站色| 午夜视频在线观看一区二区三区 | 中文字幕一区二区三区色视频| 自拍偷自拍亚洲精品播放| 免费看精品久久片| 91理论电影在线观看| 日韩视频不卡中文| 日韩一区在线看| 国产在线精品一区二区三区不卡| 99久久精品费精品国产一区二区| 911精品产国品一二三产区| 久久久综合视频| 午夜久久福利影院| 色综合久久88色综合天天免费| 日韩一级免费观看| 伊人夜夜躁av伊人久久| 国产一区二区三区四| 欧美丝袜丝交足nylons| 中文字幕一区二区三区在线不卡| 久久国内精品视频| 欧美少妇xxx| 亚洲欧洲韩国日本视频| 国产成人免费视频网站高清观看视频| 欧美在线|欧美| 中文一区在线播放| 激情五月播播久久久精品| 欧美日韩在线播放三区四区| 中文字幕中文乱码欧美一区二区| 久久国产精品99久久久久久老狼| 欧美色综合网站| 亚洲一二三区在线观看| 91老师片黄在线观看| 国产欧美日韩精品a在线观看| 美女脱光内衣内裤视频久久网站| 欧美日韩综合色| 亚洲欧美日韩国产中文在线| 国产电影精品久久禁18| 欧美大片免费久久精品三p| 丝袜亚洲另类丝袜在线| 91精彩视频在线| 一区二区欧美在线观看| 97精品国产露脸对白| 亚洲欧洲日本在线| 91猫先生在线| 亚洲一区二区在线观看视频| 在线观看www91| 亚洲一区二区三区激情| 欧美伊人久久大香线蕉综合69| 伊人性伊人情综合网| 欧美三级三级三级| 日韩电影免费一区| 日韩欧美国产成人一区二区| 黑人巨大精品欧美一区| 精品国产乱码久久久久久蜜臀| 7777精品伊人久久久大香线蕉完整版| 日韩欧美中文字幕一区| 亚洲国产精品人人做人人爽| 色av成人天堂桃色av| 一区二区三区精品| 91麻豆精品国产91久久久| 日本中文在线一区| 久久综合一区二区| 不卡一卡二卡三乱码免费网站 | 国产成人一区在线| 亚洲欧洲在线观看av| 91蜜桃在线免费视频| 偷拍一区二区三区| 亚洲精品一区二区三区香蕉| 国产成人亚洲综合a∨婷婷图片| 亚洲欧洲精品一区二区三区不卡| 91黄色小视频| 麻豆成人91精品二区三区| 久久无码av三级| 91在线免费播放| 视频一区二区欧美| 中文一区二区在线观看| 91国在线观看| 国产精品99久久久久久有的能看 | 在线欧美日韩国产| 久久99精品久久久久婷婷| 国产精品乱子久久久久| 欧美久久久久中文字幕| 成人自拍视频在线观看| 午夜精品久久久久久久99樱桃| 精品99999| 欧美日韩免费电影| 国产91精品久久久久久久网曝门| 亚洲已满18点击进入久久| 国产欧美日韩激情| 欧美大度的电影原声| 欧美最猛性xxxxx直播| 国产一区二区久久| 日韩主播视频在线| 日韩毛片视频在线看| 欧美va亚洲va香蕉在线| 欧美三级日本三级少妇99| 99精品视频一区| 大白屁股一区二区视频| 麻豆成人综合网| 轻轻草成人在线| 亚洲制服欧美中文字幕中文字幕| 久久久久久久久久久久久夜| 日韩三级.com| 欧美福利视频一区| 91麻豆视频网站| 99热国产精品| 成人一道本在线| 丁香亚洲综合激情啪啪综合| 美女www一区二区| 日韩中文字幕1| 天天av天天翘天天综合网色鬼国产| 亚洲欧美在线aaa| **性色生活片久久毛片| 国产精品麻豆一区二区| 欧美极品另类videosde| 久久精品亚洲精品国产欧美kt∨ | 免费成人av资源网| 亚洲成a人片在线不卡一二三区 | 欧美午夜免费电影| 色综合天天综合网天天狠天天| 成人一二三区视频| 99精品久久久久久| 色偷偷久久人人79超碰人人澡 | 日本免费新一区视频| 婷婷国产在线综合| 污片在线观看一区二区| 天天色 色综合| 久久精品72免费观看| 国产精一区二区三区| 国产成人精品一区二区三区四区| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 欧美精品色一区二区三区| 欧美日韩精品一区二区三区| 欧美精品在线一区二区三区| 91精品欧美久久久久久动漫| 欧美一级免费观看| 国产无一区二区| 亚洲免费在线看| 婷婷成人激情在线网| 国产一区日韩二区欧美三区| 高清国产一区二区| 色老汉av一区二区三区| 欧美日韩成人综合| 欧美xxx久久| 最好看的中文字幕久久| 亚洲成在线观看| 激情文学综合丁香| 91在线看国产| 日韩天堂在线观看| 中文字幕av一区 二区| 亚洲小说欧美激情另类| 国内精品写真在线观看| 91一区二区三区在线观看| 欧美精品亚洲二区| 欧美国产激情二区三区 | 欧美精品国产精品| 国产欧美一区在线| 亚洲3atv精品一区二区三区| 91免费观看视频| 欧美一区二区三区在线观看视频| 久久久亚洲高清| 亚洲精品国产一区二区三区四区在线 | 久久伊99综合婷婷久久伊| 国产精品天干天干在线综合| 午夜影院在线观看欧美| 成人精品视频一区| 日韩亚洲欧美在线观看| 亚洲人被黑人高潮完整版|