21.07.2013 Views

THỰC HÀNH VI XỬ LÝ - Khoa Khoa học và Kỹ thuật Máy tính

THỰC HÀNH VI XỬ LÝ - Khoa Khoa học và Kỹ thuật Máy tính

THỰC HÀNH VI XỬ LÝ - Khoa Khoa học và Kỹ thuật Máy tính

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Trường ĐH. Bách <strong>Khoa</strong> TP.HCM <strong>Khoa</strong> KH & KTMT<br />

movwf PR2 ;initialize PWM period<br />

movlw 0x80 ;initialize PWM duty cycle<br />

movwf CCPR1L<br />

bcf CCP1CON,CCP1X<br />

bcf CCP1CON,CCP1Y<br />

;postscale 1:1, prescaler 4, Timer2 ON<br />

movlw 0x05<br />

movwf T2CON<br />

movlw 0x0F ;turn buzzer on<br />

movwf CCP1CON<br />

return<br />

Để khởi tạo chức năng pwm, đầu tiên ta phải cấu hình cho PORTC2 là<br />

output. Tiếp theo khởi tạo chu kì của PWM thông qua việc cấu hình thanh ghi<br />

PR2. Sau đó ta khởi tạo duty cycle của xung pwm bằng cách cấu hình thanh ghi<br />

CCPR1L.<br />

9.2 Chương trình mẫu<br />

;=====================================;<br />

; Name: pwm.asm<br />

; Project: Su dung Pwm de xuat am thanh ra loa.<br />

; Author: BKIT HARDWARE CLUB<br />

; Homepage: http://www.bkit4u.com/forum<br />

; Creation Date: 20 - 8 - 2009<br />

;======================================;<br />

; vectors<br />

list p=18f4520<br />

#include "p18f4520.inc"<br />

org 0x000000 ; reset vector<br />

bra START<br />

;************************************************************<br />

; program<br />

START<br />

call Init_pwm<br />

Bộ môn <strong>Kỹ</strong> Thuật <strong>Máy</strong> Tính 74 Thực hành Vi xử lý

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!