Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;-------------------------------------------------------------------------------
- ;
- ; Archivo: main.s
- ; Fecha de creación/modificación: 31 Marzo 2021
- ; Author original: Kurt Kellner
- ; Modificado por:
- ; Dispositivo: PIC16F887
- ; Descripción: Blink Without Delay
- ; Hardware: (Explicar qué está conectado en dónde)
- ;
- ;-------------------------------------------------------------------------------
- ;-------------------------------------------------------------------------------
- ; Librerías incluidas
- ;-------------------------------------------------------------------------------
- PROCESSOR 16F887
- #include <xc.inc>
- ;-------------------------------------------------------------------------------
- ; Palabras de configuración
- ;-------------------------------------------------------------------------------
- ; CONFIG1
- CONFIG FOSC = INTRC_NOCLKOUT ; Oscillator Selection bits (INTOSCIO 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 and can be enabled by SWDTEN bit of the WDTCON register)
- CONFIG PWRTE = OFF ; Power-up Timer Enable bit (PWRT disabled)
- CONFIG MCLRE = OFF ; RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)
- CONFIG CP = OFF ; Code Protection bit (Program memory code protection is disabled)
- CONFIG CPD = OFF ; Data Code Protection bit (Data memory code protection is disabled)
- CONFIG BOREN = OFF ; Brown Out Reset Selection bits (BOR disabled)
- CONFIG IESO = OFF ; Internal External Switchover bit (Internal/External Switchover mode is disabled)
- CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
- CONFIG LVP = OFF ; Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)
- ; CONFIG2
- CONFIG BOR4V = BOR40V ; Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
- CONFIG WRT = OFF ; Flash Program Memory Self Write Enable bits (Write protection off)
- ;-------------------------------------------------------------------------------
- ; Macros
- ;-------------------------------------------------------------------------------
- movlf macro arg1, arg2
- movlw arg1
- movwf arg2
- endm
- _movff macro arg1, arg2
- movf arg1, w
- movwf arg2
- endm
- restartTMR0 macro
- movlf 61, TMR0
- bcf T0IF
- endm
- restartTMR1 macro
- banksel TMR1H
- movlf 0x0B, TMR1H
- movlf 0xDC, TMR1L
- bcf TMR1IF
- endm
- ;-------------------------------------------------------------------------------
- ; Variables
- ;-------------------------------------------------------------------------------
- _tmr2Value EQU 25
- _count EQU 12
- _countA EQU 20
- _countB EQU 1
- ; Para hacer que todas las variables sean globales (se puedan usar en más
- ; módulos)
- GLOBAL W_TEMP, STATUS_TEMP, count, countA, countB, countC
- PSECT vars, space=1, class=udata
- ;linker: -Pvars=0x020
- count: DS 1
- countA: DS 1
- countB: DS 1
- countC: DS 1
- countCValue: DS 1
- PSECT udata_shr ;common memory, 16 espacios
- W_TEMP: DS 1
- STATUS_TEMP: DS 1
- ;-------------------------------------------------------------------------------
- ; Vector de Reset
- ;-------------------------------------------------------------------------------
- PSECT resetVector, delta=2
- ;linker: -PresetVector=0x0000
- goto main
- ;-------------------------------------------------------------------------------
- ; Vector de Interrupción
- ;-------------------------------------------------------------------------------
- PSECT interruptVector, delta=2
- ;linker: -PinterruptVector=0x0004
- push:
- movwf W_TEMP
- swapf STATUS, W
- movwf STATUS_TEMP
- isr:
- banksel PIR1
- btfss TMR1IF
- goto pop
- restartTMR1
- decf count
- decf countA
- decf countB
- decf countC
- bcf TMR1IF
- goto pop
- pop:
- swapf STATUS_TEMP, W
- movwf STATUS
- swapf W_TEMP, F
- swapf W_TEMP, W
- retfie
- ;-------------------------------------------------------------------------------
- ; Loop principal
- ;-------------------------------------------------------------------------------
- PSECT code, delta=2
- main:
- call config_io
- call config_osc
- call config_interrupt
- call config_tmr1
- BANKSEL count
- movlf _count, count
- movlf _countA, countA
- movlf _countB, countB
- movlf 8, countCValue
- _movff countCValue, countC
- banksel PORTA
- loop:
- movf count, f
- btfsc ZERO
- call toggleCount
- movf countA, f
- btfsc ZERO
- call toggleCountA
- movf countB, f
- btfsc ZERO
- call toggleCountB
- movf countC, f
- btfsc ZERO
- call toggleCountC
- goto loop
- ;-------------------------------------------------------------------------------
- ; Subrutinas de configuración
- ;-------------------------------------------------------------------------------
- config_io:
- banksel TRISA
- clrf TRISA
- clrf TRISB
- clrf TRISC
- clrf TRISD
- clrf TRISE
- banksel ANSEL
- clrf ANSEL
- clrf ANSELH
- banksel PORTA
- clrf PORTA
- clrf PORTB
- clrf PORTC
- clrf PORTD
- clrf PORTE
- return
- config_osc:
- banksel OSCCON
- bsf IRCF2
- bsf IRCF1
- bcf IRCF0 ; IRCF = 110 = 4MHz
- bsf SCS ; Internal oscilator for system clock
- return
- config_tmr1:
- banksel T1CON
- bsf T1CKPS1
- bcf T1CKPS0
- restartTMR1
- bsf TMR1ON
- return
- config_interrupt:
- ; clear flags
- banksel PIR1
- bcf T0IF
- bcf TMR1IF
- ; set Enabled bits
- banksel PIE1
- bsf T0IE
- bsf PEIE
- bsf TMR1IE
- banksel INTCON
- bsf GIE
- return
- ;-------------------------------------------------------------------------------
- ; Subrutinas contador
- ;-------------------------------------------------------------------------------
- toggleCount:
- movlf _count, count
- movlw 00000001B
- xorwf PORTB, f
- return
- toggleCountA:
- movlf _countA, countA
- movlw 00000010B
- xorwf PORTB, f
- return
- toggleCountB:
- movlf _countB, countB
- movlw 00000100B
- xorwf PORTB, f
- return
- toggleCountC:
- _movff countCValue, countC
- movlw 00001000B
- xorwf PORTB, f
- return
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement