PWM s PIC 12F675
Napsal: 21 bře 2007, 17:19
Ahoj,dá se udělat s tímto picem PWM třaba na 400 Hz ? Poradil by mi někdo jak napsat program (nemyslím konkrétně spíš schématicky)?
Díky
Díky
Vše, co potřebujete vědět o elektronice :-)
http://elektrobastlirna.cz/
Kód: Vybrat vše
;**********************************************************************
; Files required: <P12F675.INC>
;
;**********************************************************************
list p=12F675 ; list directive to define processor
#include <P12F675.INC> ; processor specific variable definitions
errorlevel -302
__CONFIG _CP_OFF &_CPD_OFF & _WDT_OFF & _MCLRE_OFF &_BODEN_OFF &_PWRTE_ON &_INTRC_OSC_NOCLKOUT
;--------- VARIABLE DEFINITIONS ---------------------------------------
#define RAM_Start 0x20
CBLOCK RAM_Start
ucrHI ; universalni registr HI
ENDC
;--------- CONSTANTS DEFINITIONS---------------------------------------
vykon EQU 0x80 ; pozadovany vykon 50%
led_OUT EQU GPIO2 ; LED proti zemi
;----------------------------------------------------------------------
ORG 0x000 ; Processor reset vector
reset
goto LED_UP ; Go to beginning of program
ORG 0x004 ; interrupt vector location
;----------------------------------------------------------------------
; Podprogram pro PWM LED
;----------------------------------------------------------------------
LED_UP
movlw vykon
loop_PWM movwf ucrHI ; Ton
bsf GPIO,led_OUT ; LED ON
lole0 decfsz ucrHI,F
goto lole0
movwf ucrHI
comf ucrHI,F ; Toff = T - Ton
bcf GPIO,led_OUT ; LED OFF
lole1 decfsz ucrHI,F
goto lole1
goto loop_PWM
END ; directive 'end of program'