;********************************************************************** ; * ; Filename: PWM1.asm * ; Date: 06.01.08 * ; File Version: 1.0 * ; * ; Author: Olaf K. * ; Company: * ; * ; * ;********************************************************************** list p=16F84A ; list directiv e to define processor #include ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_OFF & _XT_OSC ;************************* Variablen *********************************** option_reg equ 0x81 ; Adresse Option Register intcon equ 0x8b ; Adresse Intcon Register indf equ 0x80 ; Adresse INDF Register w_copy equ 0x20 ; Backup für Accuregister s_copy equ 0x21 ; Backup für Statusregister portb equ 0x06 ; port b gleichsetzen duty equ 0x0c ; länge von duty cycle temp equ 0xd ; länge von duty cycle porta equ 0x05 ; port a gleichsetzen trisb equ 0x86 ; Trisb = Tri-state register portb an 86h status equ 0x03 ; Adresse Statusregister ;--------------------------------------------------------------------------- taste equ portb ; ersetze taste durch portb ein equ 0x04 ; Portb pin1 ;--------------------------------------------------------------------------- c equ 0 ; status bit überprüfen, nach subtraktion ;--------------------------------------------------------------------------- ;**************************************************************************** ; die eizige bedeutung der gleichsetzung hier ist PWM. ; di eses Register wird verwendet, um die länge des PWM signals zu generieren. ;**************************************************************************** org 0x00 goto start org 0x04 ;**************************************************************************** ; Interruptroutine ;intvec btfss INTCON,TOIF ; Abfrage des T0 Registers ; retfie ; nicht gesetzt rücksprung movwf w_copy ; w retten swapf status,w ; staus retten movwf s_copy ;--------------------------------------- btfsc taste,0 goto rstrt2 ; goto wert ; Prüfe länge des hi impulses an RB0 ; btfss taste,1 ; > 3sec goto sleep ; btfsp taste,1 ; ??? ??? ; < 3sec lese duty cycle wert ; ??? ??? ; duty cycle wert < d'255'dann addiere d'25,5' ; ??? ??? ; duty cycle wert = d'255'dann subtrahiere d'153' ; ??? ??? ; schreibe neuen wert für duty cycle ;--------------------------------------- INT_end bcf intcon,indf ; RB0 Interruptflag löschen swapf s_copy,w ; Status zurück movwf status swapf w_copy,f swapf w_copy,w retfie ;****************************************************************************** start movlw 0x00 ; lade W mit 0x00 setze porta als ausgang tris porta ; kopiere W tristate auf porta ausgang movlw 0x00 ; fülle W mit nullen movwf porta ; setze porta ausgänge auf low ; Diese zeilen setzen portb als ausgänge, alle ausgänge sind low. movlw 0x01 ; movwf trisb bcf status,5 ; lösche bit des registers ; port a pin1 als eingang definiert ;---------------------------------------------------------------------------- btfss taste,0 ; lese portb0 =0 zurück zu start =1 weiter zu rstrt goto start ;------------------------------------------------------------------------------ ; rb0 interrupt einstellen ; bsf status, taste ; auf BANK 1 umschalten ; bsf OPTION_REG, INTEDG ; 0-1 Flanke an rb0 ; bcf status, taste ; auf Bank 0 umschalten ; bsf INTCON, INTE ; rb0 Interrupt erlauben ; bsf INTCON, GIE ; Interrupt generell erlauben rstrt movlw d'0' movwf porta movlw d'153' ; duty cycle länge movwf duty ; nach einrichten der ports, hat die hauptschleife begonnen. ; nach beginn der hauptschleife werden alle portpins auf low gestellt. ; der duty cycle auf 153= 50%, "255=100%, 0=0%" a01loop movf duty,w movwf temp bsf porta,0 pwma nop nop nop nop nop nop nop nop nop nop nop nop decfsz temp goto pwma ; pwm schleife generiert an porta pin0. die pwma generiert den high anteil des pwm-signals. ; der duty cycle ist gespeichert in temp und die pins sind high gesetzt. movlw d'255' movwf temp movf duty,w subwf temp,f bcf porta,0 pwmb nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop decfsz temp goto pwmb goto rstrt ; der nächste teil erzeugt den low teil des pwm. der wert 255 wird in temp gespeichert. ; und der duty cyclus wird von diesem subtrahiert. ;---------------------------------------------------------------------------- ;end ;*************************** PWM Schleife 2 ********************************** rstrt2 movlw d'0' movwf porta movlw d'90' ; duty cycle länge movwf duty ; nach einrichten der ports, hat die hauptschleife begonnen. ; nach beginn der hauptschleife werden alle portpins auf low gestellt. ; der duty cycle auf 90 < 50%, "255=100%, 0=0%" a01loop2 movf duty,w movwf temp bsf porta,0 pwma2 nop nop nop nop nop nop nop nop nop nop nop nop decfsz temp goto pwma2 ;----------------------- movlw d'255' movwf temp movf duty,w subwf temp,f bcf porta,0 pwmb2 nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop decfsz temp goto pwmb2 goto rstrt2 ;************************************************************ end