Вы находитесь на странице: 1из 3

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

;
;
Filename:
I2C.asm
;
Date:
November 6, 2012
;
File Version:
1.0
;
;
Author:
Nolan Manteufel
;
*
;
Company:
University of Texas at San Antonio
;
URL:
www.utsa.edu/engineering
;
*
;******************************************************************************
list
p=16f1823
; list directive to define processor
#include <p16f1823.inc> ; processor specific variable definitions
;-----------------------------------------------------------------------------; CONFIGURATION WORD SETUP
;-----------------------------------------------------------------------------__CONFIG _CONFIG1, _CP_OFF & _WDTE_OFF & _FOSC_INTOSC & _PWRTE_OFF & _M
CLRE_ON & _CLKOUTEN_OFF
__CONFIG _CONFIG2, _LVP_OFF & _BORV_HI & _STVREN_ON & _WRT_OFF
;-----------------------------------------------------------------------------; RAM
;-----------------------------------------------------------------------------CBLOCK 0x20
; Location of RAM
x
; Used for pointless math
ENDC
;
;-----------------------------------------------------------------------------; DEFINITIONS
;-----------------------------------------------------------------------------LED
EQU
0x05
; LED location on PORTC
SWITCH EQU
0x05
; Switch location on PORTA
;-----------------------------------------------------------------------------; RESET VECTOR
;-----------------------------------------------------------------------------ORG
0x0000
; Reset vector
nop
;
goto
START
;
;-----------------------------------------------------------------------------; INTERRUPT SERVICE ROUTINE
;-----------------------------------------------------------------------------ORG
0x0004
;
nop
;
btfsc INTCON, IOCIF ;
goto
switch_isr
; set = Switch changed
config_and_return
; clear = Not switch
movlw b'00001000'
;
movwf INTCON
;
retfie
;
;------------------------------------------------------------------------------; Switch Interupt Service Routine

;------------------------------------------------------------------------------switch_isr
;
bcf
INTCON, IOCIF ;
banksel IOCAF
;
btfss IOCAF, SWITCH
;
goto
config_and_return
; clear = wasnt the switch
banksel PORTA
; set = was the switch
btfss PORTA, SWITCH
;
goto
led_off
;
goto
led_on
;
led_off
;
banksel PORTC
;
bcf
PORTC, LED
;
goto
config_and_return
;
led_on
;
banksel PORTC
;
bsf
PORTC, LED
;
goto
config_and_return
;
;-----------------------------------------------------------------------------; MAIN PROGRAM
;-----------------------------------------------------------------------------START
;
clrw
;
;------------------------------------------------------------------------------; Configuring PORTA for Switch, see page 126 and 135 of PIC16F1823 datasheet
;------------------------------------------------------------------------------banksel PORTA
;
bcf
PORTA, SWITCH ;
banksel LATA
;
bcf
LATA, SWITCH
;
banksel TRISA
;
bsf
TRISA, SWITCH ;
banksel IOCAP
;
bsf
IOCAP, SWITCH ;
banksel IOCAN
;
bsf
IOCAN, SWITCH ;
;------------------------------------------------------------------------------; Configuring PORTC for LED, see page 129 of PIC16F1823 datasheet
;------------------------------------------------------------------------------config_PORTC
banksel PORTC
bcf
PORTC, LED
banksel LATC
bcf
LATC, LED
banksel ANSELC
clrf
ANSELC
banksel TRISC
bcf
TRISC, LED
;------------------------------------------------------------------------------; Set LED output to match switch input
;------------------------------------------------------------------------------banksel PORTA
; set = was the switch
btfss PORTA, SWITCH
;
goto
led_off_2
;
goto
led_on_2
;
led_off_2
;

banksel
bcf
goto
led_on_2
banksel
bsf
goto
continue

PORTC
PORTC, LED
continue
PORTC
PORTC, LED
continue

;
;
;
;
;
;
;

;------------------------------------------------------------------------------; Configuring Interrupts, see page 93 of PIC16F1823 datasheet


;------------------------------------------------------------------------------movlw b'10001000'
; GIE == 1
; PEIE == 0
; TMR0IE == 0
; INTE == 0
; IOCIE ==1
; flags == 000
movwf INTCON
;
;------------------------------------------------------------------------------; Pointless math loop,
;------------------------------------------------------------------------------math
;
incf
x,F
;
movlw 0x04
;
sleep
; Send the processor to sleep.
addwf x,F
;
decf
x,F
;
goto
math
;
END

Вам также может понравиться