You are on page 1of 27

;****************************************************************************** ; This file is a basic template for assembly code for a PIC18F4550.

Copy * ; this file into your project directory and modify or add to it as needed. * ; * *

; The PIC18FXXXX architecture allows two interrupt configurations. This ; template code is written for priority interrupt levels and the IPEN bit * ; in the RCON register must be set to enable priority levels. If IPEN is * ; left in its default zero state, only the interrupt vector at 0x008 will *

; be used and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables will not * ; be needed. ; * * *

; Refer to the MPASM User's Guide for additional information on the ; features of the assembler. ; * * * *

; Refer to the PIC18FXX50/XX55 Data Sheet for additional ; information on the architecture and instruction set. ; *

;****************************************************************************** ; ; Filename: PlantillaASM ; Date: 12/01/11 * * * * * * *

; File Version: 1.0 ;

; Author: Ing. Alejandro Vicente Lugo Silva ; Company: Acad. Computacin ICE - ESIME Zac. ; *

;****************************************************************************** ; ; Files required: P18F4550.INC * *

;******************************************************************************

LIST P=18F4550, F=INHX32 #include <P18F4550.INC>

;directive to define processor ;processor specific variable definitions

;****************************************************************************** ;Configuration bits

CONFIG PLLDIV = 5

;(20 MHz crystal on PICDEM FS USB board)

CONFIG CPUDIV = OSC1_PLL2 CONFIG USBDIV = 2 CONFIG FOSC ;Clock source from 96MHz PLL/2

= HSPLL_HS

CONFIG FCMEN = OFF CONFIG IESO CONFIG PWRT CONFIG BOR CONFIG BORV = OFF = OFF = ON =3 ;USB Voltage Regulator

CONFIG VREGEN = ON config WDT = OFF

config WDTPS = 32768 config MCLRE = ON config LPT1OSC = OFF config PBADEN = OFF main() function. ;By default the RB4 I/O pin is used to detect if the ;firmware should enter the bootloader or the main application ;NOTE: modifying this value here won't have an effect ;on the application. See the top of the

;firmware after a reset. In order to do this, it needs to ;configure RB4 as a digital input, thereby changing it from ;the reset value according to this configuration bit. config CCP2MX = ON config STVREN = ON config LVP = OFF ; Dedicated In-Circuit Debug/Programming ; Extended Instruction Set

config ICPRT = OFF config XINST = OFF config CP0 config CP1 config CP2 config CP3 config CPB config CPD config WRT0 config WRT1 config WRT2 config WRT3 config WRTB config WRTC config WRTD = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF

; Boot Block Write Protection

config EBTR0 = OFF config EBTR1 = OFF config EBTR2 = OFF config EBTR3 = OFF config EBTRB = OFF ;******************************************************************************

;Variable definitions ; These variables are only needed if low priority interrupts are used. ; More variables may be needed to store other special function registers used ; in the interrupt routines. VAR EQU 0X00 VAR1 EQU 0X01 VAR2 EQU 0X02 limite1 equ 0x03 salto equ 0x04 limite2 equ 0x05 corriizq equ 0x06 ;****************************************************************************** ;Reset vector ; This code will start executing when a reset occurs.

RESET_VECTOR ORG

goto

Main

;go to start of main code

;******************************************************************************

;****************************************************************************** ;Start of main program ; The main program code is placed here. ORG Main call cfgptos contador movlw 0x08 movwf limite1 0x1000 ; *** main code goes here **

movlw 0x08 movwf limite2 movlw 0x01 movwf salto cicloder

movf salto,w movwf LATB rlncf salto call retardo2 decfsz limite1 goto cicloder goto cicloizq cicloizq rrncf salto movf salto,w movwf LATB call retardo2 decfsz limite2 goto cicloizq goto contador

; end of main ;******************************************************************************

; Start of subrutines ;******************************************************************************

cfgptos movlw 0x0f movwf ADCON1 movlw 0x07 movwf CMCON movlw 0x00 movwf TRISB return retardo push w movlw d'240' movwf VAR otra NOP NOP DECFSZ VAR goto otra pop w return retardo1 movlw d'100' movwf VAR1 otra1 call retardo DECFSZ VAR1 goto otra1 return retardo2

movlw d'10' movwf VAR2 otra2 call retardo1 DECFSZ VAR2 goto otra2 return ;****************************************************************************** ;End of program END

;****************************************************************************** ; This file is a basic template for assembly code for a PIC18F4550. Copy * ; this file into your project directory and modify or add to it as needed. * ; * *

; The PIC18FXXXX architecture allows two interrupt configurations. This ; template code is written for priority interrupt levels and the IPEN bit * ; in the RCON register must be set to enable priority levels. If IPEN is * ; left in its default zero state, only the interrupt vector at 0x008 will *

; be used and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables will not * ; be needed. ; * * *

; Refer to the MPASM User's Guide for additional information on the ; features of the assembler. ; * * * *

; Refer to the PIC18FXX50/XX55 Data Sheet for additional ; information on the architecture and instruction set. ; *

;****************************************************************************** ; ; Filename: PlantillaASM ; Date: 12/01/11 * * * * * * *

; File Version: 1.0 ;

; Author: Ing. Alejandro Vicente Lugo Silva ; Company: Acad. Computacin ICE - ESIME Zac. ; *

;****************************************************************************** ; ; Files required: P18F4550.INC * *

;******************************************************************************

LIST P=18F4550, F=INHX32 #include <P18F4550.INC>

;directive to define processor ;processor specific variable definitions

;****************************************************************************** ;Configuration bits

CONFIG PLLDIV = 5

;(20 MHz crystal on PICDEM FS USB board)

CONFIG CPUDIV = OSC1_PLL2 CONFIG USBDIV = 2 CONFIG FOSC ;Clock source from 96MHz PLL/2

= HSPLL_HS

CONFIG FCMEN = OFF CONFIG IESO CONFIG PWRT CONFIG BOR CONFIG BORV = OFF = OFF = ON =3 ;USB Voltage Regulator

CONFIG VREGEN = ON config WDT = OFF

config WDTPS = 32768 config MCLRE = ON config LPT1OSC = OFF config PBADEN = OFF main() function. ;By default the RB4 I/O pin is used to detect if the ;firmware should enter the bootloader or the main application ;NOTE: modifying this value here won't have an effect ;on the application. See the top of the

;firmware after a reset. In order to do this, it needs to ;configure RB4 as a digital input, thereby changing it from ;the reset value according to this configuration bit. config CCP2MX = ON config STVREN = ON config LVP = OFF ; Dedicated In-Circuit Debug/Programming ; Extended Instruction Set

config ICPRT = OFF config XINST = OFF config CP0 config CP1 config CP2 config CP3 config CPB config CPD config WRT0 config WRT1 config WRT2 config WRT3 config WRTB config WRTC config WRTD = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF

; Boot Block Write Protection

config EBTR0 = OFF config EBTR1 = OFF config EBTR2 = OFF config EBTR3 = OFF config EBTRB = OFF ;******************************************************************************

;Variable definitions ; These variables are only needed if low priority interrupts are used. ; More variables may be needed to store other special function registers used ; in the interrupt routines.

;****************************************************************************** ;Reset vector ; This code will start executing when a reset occurs.

RESET_VECTOR ORG

goto

Main

;go to start of main code

;******************************************************************************

;****************************************************************************** ;Start of main program ; The main program code is placed here. ORG Main 0x1000 ; *** main code goes here ** call cfgptos movlw 0x00 movwf TBLPTRU movlw 0x11 movwf TBLPTRH ciclo movf PORTA,w movwf TBLPTRL TBLRD*

movf TABLAT,w movwf LATB goto ciclo

; end of main ;****************************************************************************** ; Start of subrutines ;****************************************************************************** cfgptos movlw 0x0f movwf ADCON1 movlw 0X07 movwf CMCON movlw 0X00 movwf TRISB movlw 0X03 movwf TRISA RETURN

ORG 0X1100 Tabla DB 0x76,0x3f,0x38,0x77

;****************************************************************************** ;End of program END

;****************************************************************************** ; This file is a basic template for assembly code for a PIC18F4550. Copy * ; this file into your project directory and modify or add to it as needed. * ; * *

; The PIC18FXXXX architecture allows two interrupt configurations. This ; template code is written for priority interrupt levels and the IPEN bit * ; in the RCON register must be set to enable priority levels. If IPEN is * ; left in its default zero state, only the interrupt vector at 0x008 will *

; be used and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables will not * ; be needed. ; * * *

; Refer to the MPASM User's Guide for additional information on the ; features of the assembler. ; * * * *

; Refer to the PIC18FXX50/XX55 Data Sheet for additional ; information on the architecture and instruction set. ; *

;****************************************************************************** ; ; Filename: PlantillaASM ; Date: 12/01/11 * * * * * * *

; File Version: 1.0 ;

; Author: Ing. Alejandro Vicente Lugo Silva ; Company: Acad. Computacin ICE - ESIME Zac. ; *

;****************************************************************************** ; ; Files required: P18F4550.INC * *

;******************************************************************************

LIST P=18F4550, F=INHX32 #include <P18F4550.INC>

;directive to define processor ;processor specific variable definitions

;****************************************************************************** ;Configuration bits

CONFIG PLLDIV = 5

;(20 MHz crystal on PICDEM FS USB board)

CONFIG CPUDIV = OSC1_PLL2 CONFIG USBDIV = 2 CONFIG FOSC ;Clock source from 96MHz PLL/2

= HSPLL_HS

CONFIG FCMEN = OFF CONFIG IESO CONFIG PWRT CONFIG BOR CONFIG BORV = OFF = OFF = ON =3 ;USB Voltage Regulator

CONFIG VREGEN = ON config WDT = OFF

config WDTPS = 32768 config MCLRE = ON config LPT1OSC = OFF config PBADEN = OFF main() function. ;By default the RB4 I/O pin is used to detect if the ;firmware should enter the bootloader or the main application ;NOTE: modifying this value here won't have an effect ;on the application. See the top of the

;firmware after a reset. In order to do this, it needs to ;configure RB4 as a digital input, thereby changing it from ;the reset value according to this configuration bit. config CCP2MX = ON config STVREN = ON config LVP = OFF ; Dedicated In-Circuit Debug/Programming ; Extended Instruction Set

config ICPRT = OFF config XINST = OFF config CP0 config CP1 config CP2 config CP3 config CPB config CPD config WRT0 config WRT1 config WRT2 config WRT3 config WRTB config WRTC config WRTD = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF

; Boot Block Write Protection

config EBTR0 = OFF config EBTR1 = OFF config EBTR2 = OFF config EBTR3 = OFF config EBTRB = OFF ;******************************************************************************

;Variable definitions ; These variables are only needed if low priority interrupts are used. ; More variables may be needed to store other special function registers used ; in the interrupt routines. VAR EQU 0X00 VAR0 EQU 0X01 VAR1 EQU 0X02 VAR2 EQU 0X03 CONTA EQU 0X04

;****************************************************************************** ;Reset vector ; This code will start executing when a reset occurs.

RESET_VECTOR ORG

goto

Main

;go to start of main code

;******************************************************************************

;****************************************************************************** ;Start of main program ; The main program code is placed here. ORG Main 0x1000 ; *** main code goes here ** call cfgptos inicio BTFSS PORTA,0 goto inicio movlw 0x00

movwf TBLPTRU MOVLW 0X11 MOVWF TBLPTRH ciclo CLRF CONTA CLRF VAR0 movlw 0X09 movwf VAR0

incremento

movf CONTA,w movwf TBLPTRL TBLRD* movf TABLAT,w movwf LATB call retardo2 incf CONTA movf VAR0,W CPFSEQ TBLPTRL,W goto incremento goto ciclo

; end of main ;****************************************************************************** ; Start of subrutines ;****************************************************************************** cfgptos movlw 0x0f movwf ADCON1 movlw 0X07

movwf CMCON movlw 0X00 movwf TRISB movlw 0X01 movwf TRISA return retardo push w movlw d'240' movwf VAR otra NOP NOP DECFSZ VAR goto otra pop w return retardo1 movlw d'100' movwf VAR1 otra1 call retardo DECFSZ VAR1 goto otra1 return retardo2 movlw d'100' movwf VAR2 otra2 call retardo1 DECFSZ VAR2 goto otra2

return

org 0x1100 Tabla DB b'00111111',b'00000110',b'01011011',b'01001111',b'01100110',b'01101101',b'01111101',b'0000 0111',b'01111111',b'01100111'

;****************************************************************************** ;End of program END

;****************************************************************************** ; This file is a basic template for assembly code for a PIC18F4550. Copy * ; this file into your project directory and modify or add to it as needed. * ; * *

; The PIC18FXXXX architecture allows two interrupt configurations. This ; template code is written for priority interrupt levels and the IPEN bit * ; in the RCON register must be set to enable priority levels. If IPEN is * ; left in its default zero state, only the interrupt vector at 0x008 will *

; be used and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables will not * ; be needed. ; * * *

; Refer to the MPASM User's Guide for additional information on the ; features of the assembler. ; * * * *

; Refer to the PIC18FXX50/XX55 Data Sheet for additional ; information on the architecture and instruction set. ; *

;****************************************************************************** ; ; Filename: PlantillaASM ; Date: 12/01/11 * * * * * * *

; File Version: 1.0 ;

; Author: Ing. Alejandro Vicente Lugo Silva ; Company: Acad. Computacin ICE - ESIME Zac. ; *

;****************************************************************************** ; ; Files required: P18F4550.INC * *

;******************************************************************************

LIST P=18F4550, F=INHX32 #include <P18F4550.INC>

;directive to define processor ;processor specific variable definitions

;****************************************************************************** ;Configuration bits

CONFIG PLLDIV = 5

;(20 MHz crystal on PICDEM FS USB board)

CONFIG CPUDIV = OSC1_PLL2 CONFIG USBDIV = 2 CONFIG FOSC ;Clock source from 96MHz PLL/2

= HSPLL_HS

CONFIG FCMEN = OFF CONFIG IESO CONFIG PWRT CONFIG BOR CONFIG BORV = OFF = OFF = ON =3 ;USB Voltage Regulator

CONFIG VREGEN = ON config WDT = OFF

config WDTPS = 32768 config MCLRE = ON config LPT1OSC = OFF config PBADEN = OFF main() function. ;By default the RB4 I/O pin is used to detect if the ;firmware should enter the bootloader or the main application ;NOTE: modifying this value here won't have an effect ;on the application. See the top of the

;firmware after a reset. In order to do this, it needs to ;configure RB4 as a digital input, thereby changing it from ;the reset value according to this configuration bit. config CCP2MX = ON config STVREN = ON config LVP = OFF ; Dedicated In-Circuit Debug/Programming ; Extended Instruction Set

config ICPRT = OFF config XINST = OFF config CP0 config CP1 config CP2 config CP3 config CPB config CPD config WRT0 config WRT1 config WRT2 config WRT3 config WRTB config WRTC config WRTD = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF = OFF

; Boot Block Write Protection

config EBTR0 = OFF config EBTR1 = OFF config EBTR2 = OFF config EBTR3 = OFF config EBTRB = OFF ;******************************************************************************

;Variable definitions ; These variables are only needed if low priority interrupts are used. ; More variables may be needed to store other special function registers used ; in the interrupt routines. VAR EQU 0X00 VAR0 EQU 0X01 VAR1 EQU 0X02 VAR2 EQU 0X03 CONTA EQU 0X04 CONTAI equ 0x05 VARI equ 0x06 equ 0x07

CONTAD

VARD equ 0x08

;****************************************************************************** ;Reset vector ; This code will start executing when a reset occurs.

RESET_VECTOR ORG

goto

Main

;go to start of main code

;******************************************************************************

;****************************************************************************** ;Start of main program ; The main program code is placed here. ORG Main 0x1000 ; *** main code goes here **

call cfgptos

movlw 0x00 movwf TBLPTRU MOVLW 0X11 MOVWF TBLPTRH

variables

movlw 0X00 movwf CONTAD movlw 0x09 movwf VARD

movlw 0X09 movwf CONTAI movlw 0x00 movwf VARI

asciende pregunta0 btfsc PORTA,0 goto desciende movf CONTAD,w movwf TBLPTRL TBLRD* movf TABLAT,w movwf LATB call retardo2

incf CONTAD

movf CONTAD,w movwf CONTAI

movf VARD,W CPFSEQ TBLPTRL,W goto asciende goto variables

desciende pregunta1 btfss PORTA,0 goto asciende movf CONTAI,w movwf TBLPTRL TBLRD* movf TABLAT,w movwf LATB call retardo2 decf CONTAI

movf CONTAI,w movwf CONTAD

movf VARI,W CPFSEQ TBLPTRL,W goto desciende goto variables

; end of main ;****************************************************************************** ; Start of subrutines ;****************************************************************************** cfgptos movlw 0x0f movwf ADCON1 movlw 0X07 movwf CMCON movlw 0X00 movwf TRISB movlw 0X01 movwf TRISA return retardo push w movlw d'240' movwf VAR otra NOP NOP DECFSZ VAR goto otra pop w return

retardo1 movlw d'100' movwf VAR1 otra1 call retardo DECFSZ VAR1 goto otra1 return retardo2 movlw d'100' movwf VAR2 otra2 call retardo1 DECFSZ VAR2 goto otra2 return

org 0x1100 Tabla DB b'00111111',b'00000110',b'01011011',b'01001111',b'01100110',b'01101101',b'01111101',b'0000 0111',b'01111111',b'01100111'

;****************************************************************************** ;End of program END

You might also like