title Parallel interface control routines for 3100 project. ; ; Link between 4-bit data bus on RA0:3, strobe on RA4 and an 8-bit ; parallel output interface on RB0:7. ; Data 0 to 7 turns on RB pins, 8 to F turns off RB pins ; ; ------------------------------------------------------------------- ; Current status: assembles without error. ; EE storage added, conditional on "use_EE" being defined. ; Tested without EE use but not with it. ;-------------------------------------------------------------------- #include "\pic\include\P16C84.INC" __CONFIG H'3FFD' ;XT, watchdog, start timer. dbus equ H'10' #define page_0 bcf STATUS,5 ;switch to page 0 #define page_1 bsf STATUS,5 ;switch to page 1 ;************************************************************************* org 0 ;reset address in 16C84 reset goto init org 4 interrupt bcf INTCON,2 ;clear RTCC interrupt flag retfie ;========================================================== init clrf STATUS clrf PORTA clrf PORTB clrf TMR0 clrw page_1 clrf TRISB ;all port B pins are outputs movlw H'1F' ;set port A pins to input mode movwf TRISA movlw B'10000000' ;no pull-ups,f/4 to RTCC,prescale 000 movwf OPTION_REG page_0 clrf INTCON ;no interrupts allowed ifdef use_EE ; set default output from EE memory store clrf EEADR ;select EE address zero page_1 ;to access EE control reg bsf EECON1,RD ;read enable active page_0 movf EEDATA,w ;retrieve EE data movwf PORTB ;set port pins endif ; wait for a start signal (low on RA4) idle clrwdt ;reset watchdog while idle btfsc PORTA,4 ;monitor for start signal goto idle movf PORTA,w ;retrieve the bus data andlw H'0F' ;only keep data bits movwf dbus ;save it rlf dbus,f ;double it to scale jump offsets movf dbus,w ;prepare for addition addwf PCL,f ;form jump table bsf PORTB,0 ;0 = set RB0 goto save bsf PORTB,1 ;1 = set RB1 goto save bsf PORTB,2 ;2 = set RB2 goto save bsf PORTB,3 ;3 = set RB3 goto save bsf PORTB,4 ;4 = set RB4 goto save bsf PORTB,5 ;5 = set RB5 goto save bsf PORTB,6 ;6 = set RB6 goto save bsf PORTB,7 ;7 = set RB7 goto save bcf PORTB,0 ;8 = reset RB0 goto save bcf PORTB,1 ;9 = reset RB1 goto save bcf PORTB,2 ;A = reset RB2 goto save bcf PORTB,3 ;B = reset RB3 goto save bcf PORTB,4 ;C = reset RB4 goto save bcf PORTB,5 ;D = reset RB5 goto save bcf PORTB,6 ;E = reset RB6 goto save bcf PORTB,7 ;F = reset RB7 save ifdef use_EE ; write new bit pattern to EE memory address 0 clrwdt ;don't restart while writing EE movf PORTB,w ;read the new port contents movwf EEDATA ;put in EE data register clrf EEADR ;select EE address zero page_1 ;to access EE control regs bsf EECON1,WREN ;write enable active movlw H'55' ;unlock sequence... movwf EECON2 movlw H'AA' movwf EECON2 bsf EECON1,WR ;initiate write to EE bcf EECON1,WREN ;write enable inactive EE_still_writing btfsc EECON1,WR ;wait for completion signal goto EE_still_writing page_0 ;back to page zero endif ; check strobe on RA4 has finished (RA4 is high) before finishing wait clrwdt ;reset watchdog while idle btfss PORTA,4 ;monitor for start signal goto wait goto idle ;wait for more END