0% found this document useful (0 votes)
28 views3 pages

Codigo PWM Un Motor

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

Codigo PWM Un Motor

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

; Archivo :

; Fecha de creación / modificación :


; Autor :
; Dispositivo : PIC16F628A
; Descripción del programa :
; Hardware :

; ----------------------
; Librerías
; ----------------------

PROCESSOR 16F628A
#include <xc.inc>

; -------------------------------------
; Palabra de configuración
; -------------------------------------
; CONFIG
CONFIG FOSC = INTOSCIO ; Oscillator Selection bits (INTOSC oscillator:
I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
CONFIG WDTE = OFF ; Watchdog Timer Enable bit (WDT disabled)
CONFIG PWRTE = ON ; Power-up Timer Enable bit (PWRT enabled)
CONFIG MCLRE = OFF ; RA5/MCLR/VPP Pin Function Select bit
(RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)
CONFIG BOREN = OFF ; Brown-out Detect Enable bit (BOD disabled)
CONFIG LVP = OFF ; Low-Voltage Programming Enable bit (RB4/PGM pin
has digital I/O function, HV on MCLR must be used for programming)
CONFIG CPD = OFF ; Data EE Memory Code Protection bit (Data memory
code protection off)
CONFIG CP = OFF ; Flash Program Memory Code Protection bit (Code
protection off)

PSECT udata_bank0
CARGA1: DS 1
CARGA2: DS 1

PSECT CODIGO, class = CODE, delta = 2

#define MOTOR PORTA,0

Inicio:
MOVLW 07H
MOVWF CMCON
BSF STATUS, 05H
BCF STATUS, 06H
CLRF TRISA
BCF TRISA,0
CLRF TRISB
MOVLW 0FH
MOVWF TRISB

;---------- TMR0 Configuración


MOVLW 00000101B
MOVWF OPTION_REG

BCF STATUS,05H
CLRF PORTA
CLRF PORTB
Principal:
MOVF PORTB,W
ANDLW 0FH
CALL TABLA
MOVWF CARGA1
BSF MOTOR
CALL RET
MOVF PORTB,W
ANDLW 0FH
CALL TABLA2
MOVWF CARGA2
BCF MOTOR
CALL MET
GOTO Principal

TABLA:
ADDWF PCL,F
RETLW 255 ;9ms
RETLW 240 ;8ms
RETLW 233 ;7.5ms
RETLW 225 ;7ms
RETLW 217 ;6.5ms
RETLW 209 ;6ms
RETLW 194 ;5.5ms
RETLW 178 ;5ms
RETLW 162 ;4.5ms
RETLW 146 ;4ms
RETLW 139 ;3.5ms
RETLW 131 ;3ms
RETLW 123 ;2.5ms
RETLW 115 ;2ms
RETLW 108 ;1.5ms
RETLW 100 ;1ms

TABLA2:
ADDWF PCL,F
RETLW 100 ;1ms
RETLW 108 ;1.5ms
RETLW 115 ;2ms
RETLW 123 ;2.5ms
RETLW 131 ;3ms
RETLW 139 ;3.5ms
RETLW 146 ;4ms
RETLW 162 ;4.5ms
RETLW 178 ;5ms
RETLW 194 ;5.5ms
RETLW 209 ;6ms
RETLW 217 ;6.5ms
RETLW 225 ;7ms
RETLW 233 ;7.5ms
RETLW 240 ;8ms
RETLW 255 ;9ms

RET:
MOVF CARGA1,W
MOVWF TMR0
BCF INTCON,02H
BTFSS INTCON,02H
GOTO $-01H
RETURN

MET:
MOVF CARGA2,W
MOVWF TMR0
BCF INTCON,02H
BTFSS INTCON,02H
GOTO $-01H
RETURN
END

You might also like