;********************************************************************** ; This file is a basic code template for assembly code generation * ; on the PICmicro PIC16F876. This file contains the basic code * ; building blocks to build upon. * ; * ; If interrupts are not used all code presented between the ORG * ; 0x004 directive and the label main can be removed. In addition * ; the variable assignments for 'w_temp' and 'status_temp' can * ; be removed. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler (Document DS33014). * ; * ; Refer to the respective PICmicro data sheet for additional * ; information on the instruction set. * ; * ; Template file assembled with MPLAB V4.00 and MPASM V2.20.00. * ; * ;********************************************************************** ; * ; Filename: xxx.asm * ; Date: * ; File Version: * ; * ; Author: * ; Company: * ; * ; * ;********************************************************************** ; * ; Files required: * ; * ; * ; * ;********************************************************************** ; * ; Notes: * ; * ; * ; * ; * ;********************************************************************** list p=16f876 ; list directive to define processor #include ; processor specific variable definitions ; __CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _RC_OSC & _WRT_ENABLE_ON & _LVP_ON & _DEGUB_OFF & _CPD_OFF ; '__CONFIG' directive is used to embed configuration data within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. ;***** VARIABLE DEFINITIONS w_temp EQU 0x70 ; variable used for context saving status_temp EQU 0x71 ; variable used for context saving TEMP1 equ 0x20 ;Temp variables TEMP2 equ 0x21 TEMP3 equ 0x22 ;********************************************************************** ORG 0x000 ; processor reset vector clrf PCLATH ; ensure page bits are cleared goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere main CLRF STATUS ; Bank0 CLRF PORTB ; Initialize PORTB by clearing output ; data latches BSF STATUS, RP0 ; Select Bank1 MOVLW 0xE1 ; Value used to initialize data direction MOVWF TRISB ; E1 :11100001 - CF PORTB<3:0> = inputs, PORTB<5:4> = outputs ; PORTB<7:6> = inputs BCF STATUS, RP0 ; remaining code goes here CLRF STATUS LOOP MOVLW 0x10 MOVWF PORTB call DELAY MOVLW 0x08 MOVWF PORTB call DELAY MOVLW 0x04 MOVWF PORTB call DELAY MOVLW 0x02 MOVWF PORTB call DELAY goto LOOP ;Repeat ;*************************************** ;* This routine is a software delay. * ;* Fosc = 1/Tosc; Tcycle = 4 x Tosc * ;* Delay = TEMP1xTEMP2xTEMP3xTcycle * ;*************************************** DELAY movlw 0xFF movwf TEMP1 ;TEMP1 = 255 movwf TEMP2 ;TEMP2 = 255 movlw 0x07 movwf TEMP3 ;TEMP3 = 7 DLOOP decfsz TEMP1, F goto DLOOP decfsz TEMP2, F goto DLOOP decfsz TEMP3, F goto DLOOP retlw 0x00 END ; directive 'end of program'