Sayın;@MAIN_LOOP,bİldiğim kadarıyla 16f628'de bu port yok.Pwm yapılamaz. Yanılıyorsam özür..
12f683 için;
; CLOCK: Internal RC 4MHz (instruction execution time: 1usec)
;
; NOTE: PWM used for LED fade in/out. Positive sides locked to
; HI via 150-ohm resistors, while GND side of LEDs is
; driven by a varying active-low PWM signal.
;
;==================================================================================
list P=12F683, ST=OFF ; Turnoff Symbol Table in List file.
errorlevel -302 ; Ignore error message when storing to Bank 1.
;==================================================================================
#include <p12f683.inc>
__config _INTOSCIO & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_ON & _CPD_OFF & _BOD_NSLEEP & _IESO_OFF & _FCMEN_OFF
; ------------------------------------
; Configuration Bit Settings Explained
; ------------------------------------
; Internal RC Oscillator, No Clock Out
; Watch Dog Timer = OFF
; Power Up Timer = ON
; MCLR = INTERNAL
; Code Protect = ON
; Data EE Read Protect = OFF
; Brown Out Detect = Enabled in Run, Disabled in Sleep, SBOREN Disabled
; Internal External Switch Over Mode (2-speed Startup) = OFF
; Monitor Clock Fail-safe = OFF
;==========================================================================
;*****[ Data Storage Reg's ]*****
CBLOCK 0x20 ; Assign each reg. from Bank 0 RAM area.
;
DB1 ; Registers used for
DB0 ; number storage within
count1 ; the various delay/counter routines.
count2
count3
count4
count5
counter
speedcnt
init
DAT ; Calculations memory
;
ENDC ; Conclude Bank 0 RAM assignments.
;==================================================================================
ORG 0 ; Program origin at mem location 0.
;----------------------------------------------------------------------------------
Initialize
BANKSEL OSCCON ; Switch to Bank 1.
MOVLW b'01100001' ; 4MHz Clk, IntOsc, SysClk via IntOsc
MOVWF OSCCON
;
BANKSEL CMCON0 ; Switch to Bank 0.
MOVLW b'00000111' ; Turn off Comparator.
MOVWF CMCON0
BANKSEL ANSEL ; Switch to Bank 1.
CLRF ANSEL ; Set I/O pins to Digital.
;
MOVLW b'00011000' ; Define inputs & outputs.
MOVWF TRISIO
MOVLW b'11000011' ; Disable pull-ups, Prescaler -> TMR0
MOVWF OPTION_REG ; (TMR0 prescaler = 16).
;
BANKSEL GPIO ; Switch to Bank 0.
Starter movlw b'00011011' ; Set GPIO initial states.
movwf GPIO ; (Make GP0 & GP1 HI, HI side of LEDs)
;
; Set CCP1 as PWM
MOVLW B'00001111'
MOVWF CCP1CON ; Set bits 4-5 (2 LSB's of Duty Cycle) to 00.
;
; Set highest PWM value (resolution), 10-bit but only 256 discrete Duty Cycles.
BANKSEL PR2 ; Bank 1
MOVLW d'255' ; 10-bit res. but 256 Duty Cycles (Duty Cycle LSB = 00)
MOVWF PR2 ; Establishes Timer2 Period.
;
; Set prescaler to 16 for a PWM freq. of 244Hz (based on 4MHz clock).
; Since the human eye cannot perceive flicker above 120Hz, 244Hz is OK.
BANKSEL T2CON ; Bank 0
MOVLW B'00000010'
MOVWF T2CON ; Timer2 is now OFF & Prescaler is 16.
;
CLRF CCPR1L ; Clear PWM Reg.1 LO Byte (sets PWM Duty Cycle to zero)
; (CCPR1L contains the 8 MSB's of the Duty Cycle.)
BSF T2CON, TMR2ON ; Turn on Timer2.
;
;==================================================================================
Begin ; Fade Duration: 3.9ms x 255 = 1s
CALL Del_4 ; Wait 3.9ms.
INCF CCPR1L, F ; Increase Duty Cycle (make LED brighter).
MOVLW b'11111111'
XORWF CCPR1L, W
SKPZ ; Have we incremented up to 255 yet?
GOTO Begin ; No. Keep incrementing (increasing brightness).
;
CALL Del_200 ; Keep LED at max brightness for 200ms.
Fadeout
CALL Del_4 ; Wait 3.9ms.
DECFSZ CCPR1L, F ; Decrease Duty Cycle (make LED dimmer).
GOTO Fadeout ; Keep decrementing until 0 (LED OFF).
;
;LED OFF, so kill PWM output to save power.
MOVLW b'00011000' ; Make GP0 & GP1 LO (HI side of LEDs).
movwf GPIO
BCF T2CON, TMR2ON ; Turn OFF Timer2.
CLRF CCP1CON ; Turn OFF PWM module.
;
CALL Del_2s ; Hold LED OFF for 2 seconds.
;
GOTO Starter ; Power PWM back up & Restart program.
Hesaplama için