0% found this document useful (0 votes)
3 views

pwm.asm

Uploaded by

ticebekhulu.nt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

pwm.asm

Uploaded by

ticebekhulu.nt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

;******************************************************************

; Your Name
; Your Student Number
; Assignment Number
; PWM Example for PIC16F818 on RB3
;******************************************************************

LIST__1_______; Using PIC16F818


#INCLUDE <P16F818.INC> ; Header file for PIC16F818
;******************************************************************
; Configuration Bits
__CONFIG _XT_OSC & __2__ _OFF & _3 _ON &
_CP_OFF_4______5_________6__________7_________;
******************************************************************

ORG 0x00 ; Start address in memory


GOTO START ; Goto start

; Interrupt Vector
ORG 8____ ; 9_________
GOTO 10____ ; No interrupt service routine for this example

START:
; Configure PORTB
BSF STATUS, RP0 ; Switch to Bank 1
MOVLW 0x00 ; Set PORTB As 11_____ (including RB3)
MOVWF TRISB ; 12________
BCF STATUS, RP0 ; Switch back to Bank 0

; Initialize Timer 2 for PWM


MOVLW 13________ ; Set prescaler to 1:1, enable Timer 2
MOVWF T2CON ;14______

; Load the period value (e.g., 0xFF for max duty cycle)
BSF STATUS, RP0 ; Switch to Bank 1
MOVLW 15____ ; Set Timer 2 period register (adjust as
needed)
MOVWF PR2 ; Load PR2 register
BCF STATUS, RP0 ; Switch back to Bank 0

; Initialize CCP1 for PWM mode


MOVLW 16________ ; Set CCP1 in PWM mode
MOVWF CCP1CON ; Write to CCP1CON

; Set duty cycle (for example, 50%)


MOVLW 0x7F ; Set duty cycle to 50% (out of 255)
MOVWF 17_____ ;18______(low byte)
MOVLW 0x00 ; High byte (only the low byte is used in PWM
mode)
MOVWF CCPR1H ; Write to CCPR1H

; Start Timer 2
BSF T2CON,19_______; Start Timer 2
main_loop:
; Main loop (Do nothing, PWM will run automatically)
goto main_loop

END ; End of program

You might also like