list p=pic16c54B, r=hex #include #define PWM_PORT PORTA #define PWM_PIN 0 DutyCycle EQU 0x09 Counter EQU 0x0A Period EQU 0x0B ORG 0x00 Begin call Initialize_PWM Main call PWM_Signal goto Main Initialize_PWM clrf PORTA ; reset PORTA movlw b'00001110' tris PORTA ; Set PWM pin for output movlw 80 movwf DutyCycle ; initialize duty cycle movlw FF movwf Period ; initialize period register clrf Counter ; reset counter bsf PORTA, PWM_PIN ; set PWM signal to high retlw 0 PWM_Signal incf Counter,f ; Increment the counter movf DutyCycle,w subwf Counter,w ; compare duty cycle against ; period btfss STATUS,C ; Is period < duty cycle retlw 0 ; duty cycle is greater than ;period, therefore PWM signal ; remains high bcf PORTA,PWM_PIN ; time of duty cycle ;elapsed movf Period,w ; compare the counter ;against the period subwf Counter,w btfss STATUS,Z ; if the counter == ; period, retlw 0 ; period is not over clrf Counter ; reset the counter bsf PORTA, PWM_PIN ; Set PWM_Pin to high retlw 0 ORG 0x1FF Reset goto Begin END