; This file is a basic code template for assembly code generation *
; on the PIC16F819. 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 PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files required: *
; *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************
list p=16f819 ; list directive to define processor
#include <E:\Program Files\Microchip\MPASM Suite\p16F819.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _DEBUG_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
;***** VARIABLE DEFINITIONS
w_temp EQU 0x7E ; variable used for context saving
status_temp EQU 0x7F ; variable used for context saving
;**********************************************************************
ORG 0x000 ; processor reset vector
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
btfss INTCON, TMR0IF ;TMR0IF is set when the timer interrupt is called
goto skp1
comf PORTB, 1
;BANKSEL PORTA
;btfss PORTA, 2
;goto SETP
;bcf PORTA, 2
;goto skp1
;SETP
;bsf PORTA, 2
skp1
BANKSEL TMR0
movlw 8 ;we actually need the prescale to be 100 so we subtract 27 from the count down
movwf TMR0
bcf INTCON, TMR0IF ;we must clear this flag for interrupts and program to run properly
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
main
;Setup the I/O Pins
call SetupOscillator
call SetupPortA
call SetupPortB
call SetupTimerInterrupt
; remaining code goes here
Live
btfss PORTA, 0
goto skp
bsf PORTA, 1
goto Live
skp
bcf PORTA, 1
goto Live
SetupOscillator
movlw b'01110000'
movwf OSCCON
return
SetupPortA
BANKSEL PORTA
CLRF PORTA
BANKSEL ADCON1
MOVLW 0x06 ;All pins on port A are outputs
MOVWF ADCON1
MOVLW b'00000001'
MOVWF TRISA
return
SetupPortB
BANKSEL PORTB
CLRF PORTB
MOVLW 0x00
BANKSEL TRISB
MOVWF TRISB
return
SetupTimerInterrupt
CLRWDT
BANKSEL OPTION_REG
MOVLW b'10000100' ;Use Prescale value of 128, Internal Oscillator
MOVWF OPTION_REG
BANKSEL TMR0
movlw 8 ;we actually need the prescale to be 100 so we subtract 27 from the count down
movwf TMR0
;enable the interrupts
bsf INTCON, TMR0IE
bsf INTCON, GIE
return
; initialize eeprom locations
ORG 0x2100
DE 0x00, 0x01, 0x02, 0x03
END ; directive 'end of program'