Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "p18F45K20.inc"
- ;*******************************************************************************
- ; *
- ; Microchip licenses this software to you solely for use with Microchip *
- ; products. The software is owned by Microchip and/or its licensors, and is *
- ; protected under applicable copyright laws. All rights reserved. *
- ; *
- ; This software and any accompanying information is for suggestion only. *
- ; It shall not be deemed to modify Microchip?s standard warranty for its *
- ; products. It is your responsibility to ensure that this software meets *
- ; your requirements. *
- ; *
- ; SOFTWARE IS PROVIDED "AS IS". MICROCHIP AND ITS LICENSORS EXPRESSLY *
- ; DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING *
- ; BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS *
- ; FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL *
- ; MICROCHIP OR ITS LICENSORS BE LIABLE FOR ANY INCIDENTAL, SPECIAL, *
- ; INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO *
- ; YOUR EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR *
- ; SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY *
- ; DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER *
- ; SIMILAR COSTS. *
- ; *
- ; To the fullest extend allowed by law, Microchip and its licensors *
- ; liability shall not exceed the amount of fee, if any, that you have paid *
- ; directly to Microchip to use this software. *
- ; *
- ; MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF *
- ; THESE TERMS. *
- ; *
- ;*******************************************************************************
- ; *
- ; Filename: *
- ; Date: *
- ; File Version: *
- ; Author: *
- ; Company: *
- ; Description: *
- ; *
- ;*******************************************************************************
- ; *
- ; Notes: In the MPLAB X Help, refer to the MPASM Assembler documentation *
- ; for information on assembly instructions. *
- ; *
- ;*******************************************************************************
- ; *
- ; Known Issues: This template is designed for relocatable code. As such, *
- ; build errors such as "Directive only allowed when generating an object *
- ; file" will result when the 'Build in Absolute Mode' checkbox is selected *
- ; in the project properties. Designing code in absolute mode is *
- ; antiquated - use relocatable mode. *
- ; *
- ;*******************************************************************************
- ; *
- ; Revision History: *
- ; *
- ;*******************************************************************************
- ;*******************************************************************************
- ; Processor Inclusion
- ;
- ; TODO Step #1 Open the task list under Window > Tasks. Include your
- ; device .inc file - e.g. #include <device_name>.inc. Available
- ; include files are in C:\Program Files\Microchip\MPLABX\mpasmx
- ; assuming the default installation path for MPLAB X. You may manually find
- ; the appropriate include file for your device here and include it, or
- ; simply copy the include generated by the configuration bits
- ; generator (see Step #2).
- ;
- ;*******************************************************************************
- ; TODO INSERT INCLUDE CODE HERE
- ;*******************************************************************************
- ;
- ; TODO Step #2 - Configuration Word Setup
- ;
- ; The 'CONFIG' directive is used to embed the configuration word within the
- ; .asm file. MPLAB X requires users to embed their configuration words
- ; into source code. See the device datasheet for additional information
- ; on configuration word settings. Device configuration bits descriptions
- ; are in C:\Program Files\Microchip\MPLABX\mpasmx\P<device_name>.inc
- ; (may change depending on your MPLAB X installation directory).
- ;
- ; MPLAB X has a feature which generates configuration bits source code. Go to
- ; Window > PIC Memory Views > Configuration Bits. Configure each field as
- ; needed and select 'Generate Source Code to Output'. The resulting code which
- ; appears in the 'Output Window' > 'Config Bits Source' tab may be copied
- ; below.
- ;
- ;*******************************************************************************
- ; TODO INSERT CONFIG HERE
- ; CONFIG1H
- CONFIG FOSC = INTIO7 ; Oscillator Selection bits (Internal oscillator block, CLKOUT function on RA6, port function on RA7)
- CONFIG FCMEN = OFF ; Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
- CONFIG IESO = OFF ; Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
- ; CONFIG2L
- CONFIG PWRT = OFF ; Power-up Timer Enable bit (PWRT disabled)
- CONFIG BOREN = SBORDIS ; Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
- CONFIG BORV = 18 ; Brown Out Reset Voltage bits (VBOR set to 1.8 V nominal)
- ; CONFIG2H
- CONFIG WDTEN = OFF ; Watchdog Timer Enable bit (WDT is controlled by SWDTEN bit of the WDTCON register)
- CONFIG WDTPS = 32768 ; Watchdog Timer Postscale Select bits (1:32768)
- ; CONFIG3H
- CONFIG CCP2MX = PORTC ; CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
- CONFIG PBADEN = OFF ; PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
- CONFIG LPT1OSC = OFF ; Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
- CONFIG HFOFST = ON ; HFINTOSC Fast Start-up (HFINTOSC starts clocking the CPU without waiting for the oscillator to stablize.)
- CONFIG MCLRE = ON ; MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
- ; CONFIG4L
- CONFIG STVREN = ON ; Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
- CONFIG LVP = OFF ; Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
- CONFIG XINST = OFF ; Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
- ; CONFIG5L
- CONFIG CP0 = OFF ; Code Protection Block 0 (Block 0 (000800-001FFFh) not code-protected)
- CONFIG CP1 = OFF ; Code Protection Block 1 (Block 1 (002000-003FFFh) not code-protected)
- CONFIG CP2 = OFF ; Code Protection Block 2 (Block 2 (004000-005FFFh) not code-protected)
- CONFIG CP3 = OFF ; Code Protection Block 3 (Block 3 (006000-007FFFh) not code-protected)
- ; CONFIG5H
- CONFIG CPB = OFF ; Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
- CONFIG CPD = OFF ; Data EEPROM Code Protection bit (Data EEPROM not code-protected)
- ; CONFIG6L
- CONFIG WRT0 = OFF ; Write Protection Block 0 (Block 0 (000800-001FFFh) not write-protected)
- CONFIG WRT1 = OFF ; Write Protection Block 1 (Block 1 (002000-003FFFh) not write-protected)
- CONFIG WRT2 = OFF ; Write Protection Block 2 (Block 2 (004000-005FFFh) not write-protected)
- CONFIG WRT3 = OFF ; Write Protection Block 3 (Block 3 (006000-007FFFh) not write-protected)
- ; CONFIG6H
- CONFIG WRTC = OFF ; Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
- CONFIG WRTB = OFF ; Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
- CONFIG WRTD = OFF ; Data EEPROM Write Protection bit (Data EEPROM not write-protected)
- ; CONFIG7L
- CONFIG EBTR0 = OFF ; Table Read Protection Block 0 (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
- CONFIG EBTR1 = OFF ; Table Read Protection Block 1 (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
- CONFIG EBTR2 = OFF ; Table Read Protection Block 2 (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
- CONFIG EBTR3 = OFF ; Table Read Protection Block 3 (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)
- ; CONFIG7H
- CONFIG EBTRB = OFF ; Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)
- ;*******************************************************************************
- ;
- ; TODO Step #3 - Variable Definitions
- ;
- ; Refer to datasheet for available data memory (RAM) organization assuming
- ; relocatible code organization (which is an option in project
- ; properties > mpasm (Global Options)). Absolute mode generally should
- ; be used sparingly.
- ;
- ; Example of using GPR Uninitialized Data
- ;
- ; GPR_VAR UDATA
- ; MYVAR1 RES 1 ; User variable linker places
- ; MYVAR2 RES 1 ; User variable linker places
- ; MYVAR3 RES 1 ; User variable linker places
- ;
- ; ; Example of using Access Uninitialized Data Section (when available)
- ; ; The variables for the context saving in the device datasheet may need
- ; ; memory reserved here.
- ; INT_VAR UDATA_ACS
- ; W_TEMP RES 1 ; w register for context saving (ACCESS)
- ; STATUS_TEMP RES 1 ; status used for context saving
- ; BSR_TEMP RES 1 ; bank select used for ISR context saving
- ;
- ;*******************************************************************************
- INT_VAR UDATA_ACS
- timer_on RES 1
- btn RES 1
- ;*******************************************************************************
- ; Reset Vector
- ;*******************************************************************************
- RES_VECT CODE 0x0000 ; processor reset vector
- GOTO RUN ; go to beginning of program
- ;*******************************************************************************
- ; TODO Step #4 - Interrupt Service Routines
- ;
- ; There are a few different ways to structure interrupt routines in the 8
- ; bit device families. On PIC18's the high priority and low priority
- ; interrupts are located at 0x0008 and 0x0018, respectively. On PIC16's and
- ; lower the interrupt is at 0x0004. Between device families there is subtle
- ; variation in the both the hardware supporting the ISR (for restoring
- ; interrupt context) as well as the software used to restore the context
- ; (without corrupting the STATUS bits).
- ;
- ; General formats are shown below in relocatible format.
- ;
- ;------------------------------PIC16's and below--------------------------------
- ;
- ; ISR CODE 0x0004 ; interrupt vector location
- ;
- ; <Search the device datasheet for 'context' and copy interrupt
- ; context saving code here. Older devices need context saving code,
- ; but newer devices like the 16F#### don't need context saving code.>
- ;
- ; RETFIE
- ;
- ;----------------------------------PIC18's--------------------------------------
- ;
- ISRHV CODE 0x0008
- GOTO HIGH_ISR
- ; ISRLV CODE 0x0018
- ; GOTO LOW_ISR
- ;
- ; ISRH CODE ; let linker place high ISR routine
- ;HIGH_ISR
- ; <Insert High Priority ISR Here - no SW context saving>
- ; RETFIE FAST
- ;
- ; ISRL CODE ; let linker place low ISR routine
- ; LOW_ISR
- ; <Search the device datasheet for 'context' and copy interrupt
- ; context saving code here>
- ; RETFIE
- ;
- ;*******************************************************************************
- ; TODO INSERT ISR HERE
- ;*******************************************************************************
- ; MAIN PROGRAM
- ;*******************************************************************************
- MAIN_PROG CODE ; let linker place main program
- HIGH_ISR
- MOVLW 0x01
- XORWF timer_on, 1
- BTG T0CON, 1
- BCF INTCON, 1
- INCF btn
- RETFIE FAST
- POLL
- MOVLW 0x01
- CPFSEQ timer_on ; if timer_on != 1, go back to LED
- GOTO LED
- BTFSS INTCON, 2
- GOTO POLL
- BCF INTCON, 2
- MOVLW 0x0B
- MOVF TMR0H
- MOVLW 0xDC
- MOVF TMR0L
- RETURN
- RUN
- ; Oscillo
- MOVLW b'00010100' ; 0: Sleep = Deep sleep, 101 = 4Mhz, 0 = Internal, 1 = Stable, 00 = Primary Clock
- MOVWF OSCCON
- ; Timer
- MOVLW b'10001011'
- MOVWF T0CON
- ; Outputs
- MOVLW b'00000000'
- MOVWF TRISD
- ; Interrupts
- MOVLW b'10010000'
- MOVWF INTCON
- MOVLW b'11000001'
- MOVWF INTCON2
- MOVLW 0x01
- MOVWF timer_on
- LED
- MOVLW 0x01
- CPFSEQ timer_on ; if timer_on != 1, go back to LED
- GOTO LED
- ; Check Timer On
- ; LEDs on
- MOVLW b'01010101'
- MOVWF LATD
- CALL POLL
- ; LEDs off
- MOVLW 0xFF
- XORWF LATD, 1
- CALL POLL
- GOTO LED
- GOTO $
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement