From: Subject: Date: Sun, 4 Feb 2007 18:18:16 -0500 MIME-Version: 1.0 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Content-Location: http://www.ecs.umass.edu/ece/sdp/sdp04/janaswamy/Sdppic.asm X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
;*************************************************************=
*****************
;* Senior Design Project PIC
;*
;*                 University of Massachusetts, Amherst
;*
;*Program last modified:
;*      Date:   3/22/2004
;************************************************************************=
******

        include "p16f877a.inc"   ;Include file for p16f877A chip.
        errorlevel -302         ;Disable error for switching from bank =
0.
temp_status     equ     0x20
temp_w          equ     0x21
AC_1            equ     0x22
AC_2            equ     0x23
AC_3            equ     0x24
AC_4            equ     0x25
Write_point     equ     0x26
Read_point      equ     0x27
temp_FSR        equ     0x28
last_portB      equ     0x29
;pointer for memory, start storage at 0x2A
reset
        org     0x00            ;Start at the reset vector.
        goto    usart_ports_setup
        org     0x04
        goto    I_control	;4 inst (2 for interrupt, 2 for goto)
        org     0x05

usart_ports_setup                       ;Initialization of USART.=20
                       =20
        bsf     STATUS,RP0      ;Bank 1
                       =20
        movlw   0x24     ;B'00100100' Enables trransmission,async. mode.
        movwf   TXSTA
        movlw   0x19            ;Sets up SPBRG to hex 19 (25 decimal) =
for 9600baud rate
        movwf   SPBRG  =20
	bcf	TRISC,0x06	;*Setting up TRISC and TRISB, RB7=3DOverflow,RB6=3DC (EG =
3-1-04)
				;*
	movlw	b'01100000'	;*
	movwf	TRISB		;*
	clrf	TRISD
        bcf     STATUS,RP0      ;Bank 0

        movlw   0x90            ;B'10010000' Sets async. mode and =
continuous recieving.
        movwf   RCSTA  =20
        ;RB7:RB4 interrupt on change, compared to last value READ from =
portB, flag in INTCON,RBIF              =20
        bsf     INTCON,RBIE             ;Activates PORTB condition =
change interrupts

main
        clrf    AC_1
        clrf    AC_2
        clrf    AC_3
        clrf    AC_4
        clrf    last_portB
        movlw   0x29                    ;memory starts at 2A, but will =
start pointers at 29, pointers represent NEXT
        movwf   Write_point             ;address to read/write
        movwf   Read_point                ;reads '00' for RB7 and RB6
		bcf		PORTD,0x00
		bsf		PORTD,0x04
        bsf     INTCON,GIE              ;Activates all unmasked =
interrupts.
main_loop
	nop
	nop
	nop
	nop
	nop
        goto    main_loop
       =20
I_control                               ;ISR for PORTB change inerrupts

        movwf   temp_w                  ;saves values in W and STATUS.
        swapf   STATUS,W
        movwf   temp_status             ;saves FSR
        movf    FSR,W
        movwf   temp_FSR

	bcf	INTCON,RBIF
        movfw	PORTB			;reads the value out of PORTB should end mis-match =
condition				=09
        andlw	0x40			;*(EG 3-22-04) checking RB7, overflow=20
        xorwf   last_portB,W		;*
        btfsc   STATUS,Z
        goto    C_interrupt		;z=3D1, then Overflow same as before so =
must be C (11 inst)
        goto    O_interrupt		;z=3D0, then Overflow different, so must be =
O (12 inst)

O_interrupt
	;movlw	A'V'			;*(EG 3-22-04) Testing only!!
	;movwf	TXREG			;*
	;call	wait_loopTest		;*
	btfss	PORTD,0x00
	goto	set_test
	bcf		PORTD,0x00
	goto	end_test
set_test
	bsf		PORTD,0x00
end_test
	movlw	0x40			;* (EG 3-22-04) Saving new value of PORTB
        andwf	PORTB,W			;*=20
        movwf   last_portB		;*

        goto    end_it
;18 inst

C_interrupt
btfss	PORTD,0x04
	goto  set_test2
	bcf		PORTD,0x04
	goto    end_it
set_test2
bsf		PORTD,0x04
	;movlw	A'C'			;*(EG 3-22-04) Testing only!!
	;movwf	TXREG			;*
	;call	wait_loopTest		;*

;25 inst

end_it =20
        movf    temp_FSR,W              ;restores FSR
        movwf   FSR
                                        ;may want to put some nops here =
for timing
        swapf   temp_status,W           ;restores values of W and =
STATUS.
        movwf   STATUS
        swapf   temp_w,F
        swapf   temp_w,W=20
        retfie =20
;9 inst
wait_loopTest				;*(EG 3-22-04) Testing only!!
        btfss   PIR1,TXIF		;*
        goto    wait_loopTest		;*
	return       			;*                =20
        end
; O total 4 + 12 + 18 + 9 =3D 43
; C total 4 + 11 + 25 + 9 =3D 49
;(1/instr)*f*747us=3DBikes
;Coditional tests that evaluate to true and inst which change program =
counter take 2 cycles