成人做爰黄A片免费视频网站野外,成人免费看片APP下载,成人做爰A片免费看黄冈白狐影院,成人做爰黄级A片免费看土方,成人做爰A片AAA毛真人,成人做爰A片免费看网站性晶

技術熱線: 4007-888-234

技術支持

利用PIC的PWM實現數模轉換的方法

更新時間: 2019-03-25

硬件圖:

 

3cb4317700b54fa3a81c287de7a81526.png

源程序:

; PWM port (in w), pin, duty
; Generates a bit stream of 256 1s and 0s with the specified
; duty cycle. If this bit stream is run through a simple RC
; integrator, the result is an analog voltage output of
; (duty/255) * (PIC supply voltage). For example, if duty is
; 100 and the supply is 5 volts, then the integrated output of
; pwm would be (100/255) * 5 = 1.96 volts. In many applications,
; pwm output should be buffered with a unity-gain op-amp
; circuit. In those cases, the pwm output pin should be set up
; as an output when Pwm is called, then immediately switched to
; input when Pwm is done. This prevents the steady-state output
; of the pin from affecting the voltage set by Pwm.

  P = pic16c55
        #include <16c55.inc>   ; processor assembler definitions
        _CONFIG _xt_osc & _wdt_off & _protect_off
        reset start

        org 8
duty Res d'1' ; Pwm duty cycle.
acc Res d'1' ; Pwm accumulator.
index Res d'1' ; Temporary counter for pwm.
pin Res d'1' ; Pin number to pulse (0-7).

; Device data and reset vector

 org 0

; Table to convert pin number (0-7) into bit mask (00000001b to 10000000b).
Pinz         ADDWF pcl                 
             RETLW d'1'                
             RETLW d'2'
             RETLW d'4'
             RETLW d'8'
             RETLW d'16'
             RETLW d'32'
             RETLW d'64'
             RETLW d'128'

start        MOVLW d'0'                 ; All outputs.
             TRIS 5h
             CLRF 5h                    ; Start with LED off.
             CLRF duty                  ; Initial brightness = 0.
             CLRF index                 ; Clear loop counter for pwm.
start_loop   MOVLW d'2'                 ; Pin 2.
             MOVWF pin

 MOVLW d'0'                 ; of port ra.
             CALL pwm                   ; Send pwm to LED.
             INCF duty                  ; Turn up brightness.
             GOTO start_loop            ; Endless loop
; Upon entry, the desired pin must already be set up as an output.
; Variable "pin" contains the pin number (0-7). The w register contains a
; number representing the output port (0-2) for RA through RC. The variable
; duty contains the desired duty cycle from 0 to 255.

Pwm          MOVWF fsr                  ; Point to the port number.
             MOVLW 5h                   ; Add offset for port RA.
             ADDWF fsr
             MOVF pin,w                
             CALL Pinz                  ; Get bit mask from the table.
             MOVWF pin                  ; Put the mask into pin.
Pwm_loop     MOVF duty,w                ; Let acc = acc + duty
             ADDWF acc

             MOVF pin,w                
             BTFSC status,c             ; IF carry THEN pin = 1
             IORWF indirect             ; ELSE pin = 0.
             COMF pin,w                
             BTFSS status,c            
             ANDWF indirect             

    DECFSZ index               ; Repeat 256 times.
             GOTO Pwm_loop
             RETLW 0h                  

            
            
             end


404
返回首頁 |  返回上一頁
欢迎光临: 鄂托克前旗| 怀柔区| 江口县| 文安县| 孟津县| 武宣县| 华池县| 金平| 宝应县| 娱乐| 长治市| 常熟市| 云霄县| 怀集县| 嘉黎县| 海晏县| 皋兰县| 米泉市| 甘谷县| 松桃| 手游| 大石桥市| 巴彦淖尔市| 绥中县| 小金县| 泸定县| 资源县| 巴东县| 盱眙县| 绍兴市| 张北县| 皮山县| 从江县| 安陆市| 常熟市| 水富县| 安阳市| 鸡东县| 伽师县| 胶州市| 故城县|