;NEW october 26 18f4550_____PORT E_________________________________________________________ LIST P=18F4550 ;directive to define processor #include ;processor specific variable definitions #include "migrate.inc" Errorlevel -302 ;****************************************************************************** ;Configuration bits ;Microchip has changed the format for defining the configuration bits, please ;see the .inc file for futher details on notation. Below are a few examples. ; Oscillator Selection: ;CONFIG FOSC = HS ;XT oscillator, XT used by USB config FOSC = HSPLL_HS ; HS config PLLDIV = 5 ; PLL prescaler i.e. 20/5=4 MHz (96MHz PLL) config CPUDIV = OSC1_PLL2 ; PLL divided by 2 (96/2=48MHz) to feed CPU; config USBDIV = 2 ; if full speed (FSEN=1) USB is fed by PLL ; divided by 2 (96/2=48MHz) config IESO = OFF config PWRT = OFF config BOR = OFF config BORV = 2 config VREGEN = ON config WDT = OFF config WDTPS = 32768 config MCLRE = OFF config LPT1OSC = OFF config PBADEN = OFF config CCP2MX = OFF config STVREN = OFF config LVP = OFF config ICPRT = OFF config XINST = OFF config DEBUG = OFF config CP0 = OFF config CP1 = OFF config CP2 = OFF config CPB = OFF config CPD = OFF config WRT0 = OFF config WRT1 = OFF config WRT2 = OFF config WRT3 = OFF config WRTB = OFF config WRTC = OFF config WRTD = OFF config EBTR0 = OFF config EBTR1 = OFF config EBTR2 = OFF config EBTRB = OFF ;****************************************************************************** ;Variable definitions ; These variables are only needed if low priority interrupts are used. ; More variables may be needed to store other special function registers used ; in the interrupt routines. CBLOCK 0x080 WREG_TEMP ;variable used for context saving STATUS_TEMP ;variable used for context saving BSR_TEMP ;variable used for context saving RAND1 ;random file SENSTAT ;veg status hit-delay-over BUTTON1 ;start veg ;INT_PORTS Random temp tempf count1 counta countb DEALY25 DEALY50 DEALY100 CounterA CounterB CounterC EXAMPLE ;example of a variable in access RAM ENDC ;****************************************************************************** ;EEPROM data ; Data to be programmed into the Data EEPROM is defined here ORG 0xf00000 DE "Test Data",0,1,2,3,4,5 ;****************************************************************************** ;Reset vector ; This code will start executing when a reset occurs. ORG 0x0000 goto Main1 ;go to start of main code ;****************************************************************************** ;High priority interrupt vector ; This code will start executing when a high priority interrupt occurs or ; when any interrupt occurs if interrupt priorities are not enabled. ORG 0x0008 bra HighInt ;go to high priority interrupt routine ;****************************************************************************** ;Low priority interrupt vector and routine ; This code will start executing when a low priority interrupt occurs. ; This code can be removed if low priority interrupts are not used. ORG 0x0018 ;movff STATUS,STATUS_TEMP ;save STATUS register ;movff WREG,WREG_TEMP ;save working register ;movff BSR,BSR_TEMP ;save BSR register ; movff BSR_TEMP,BSR ;restore BSR register ; movff WREG_TEMP,WREG ;restore working register ; movff STATUS_TEMP,STATUS ;restore STATUS register ; GOTO HOLD ; retfie ;****************************************************************************** ;High priority interrupt routine ; The high priority interrupt code is placed here to avoid conflicting with ; the low priority interrupt vector. HighInt:; *** high priority interrupt code goes here *** OVER MOVLW B'00000000' ;all Veg down MOVWF PORTD CLRF PORTC CALL DELAY100 MOVLW B'0000010' ; MOVWF PORTC CALL DELAY100 MOVLW B'00000000' ; MOVWF PORTC ; MOVLW b'00000000' ; MOVWF INTCON;,GIE CLRF RAND1 CLRF SENSTAT CLRF BUTTON1 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 GOTO HOLD_INT ;retfie FAST ; Start of main program ; The main program code is placed here. Main1: GOTO INT_PORTS Main2 GOTO HOLD GOTO Main2 ;********** INITIALIZING *********** INT_PORTS CLRF UCON ;disable usb CLRF LATA ;clear latches MOVLW 07h ;turn off compartors MOVWF CMCON CLRF PORTA ;******PortA INPUT MOVLW 0Fh MOVWF ADCON1 MOVLW 0fh ;inputs MOVWF TRISA CLRF PORTB ;*****PortB INPUT CLRF LATB ;clear latches MOVLW 0Fh ;1111 MOVWF ADCON1 MOVLW b'11111111' ;inputs MOVWF TRISB CLRF PORTC ;*****PortC Output CLRF LATC ;clear latches MOVLW b'00000000' ;outputs MOVWF TRISC CLRF PORTD ;********PortD OUTPUT CLRF LATD ;clear latches MOVLW b'00000000' ;outputs MOVWF TRISD CLRF PORTE CLRF LATE ;clear latches MOVLW 07h ;turn off comparators MOVWF CMCON MOVLW b'11111111' ;inputs MOVWF TRISE MOVLW b'11011000' ; MOVWF b'01111111' MOVWF OSCTUNE MOVWF b'00000000' MOVWF WDTCON MOVWF INTCON;,GIE bcf RCON,IPEN ;disable priorities and enable Compatibility Mode GOTO Main2 ;*************************** ;clear all ports coming back to the hold function for restart. HOLD_INT MOVLW b'11010000' ;restore inturrupts MOVWF INTCON; CLRF PORTB CLRF PORTC CLRF PORTD CLRF PORTE HOLD CLRF PORTB CLRF PORTC CLRF PORTD CLRF PORTE CLRF Random CLRF BUTTON1 MOVLW b'00000010' ;clear latch RC1=time gate reset MOVWF PORTC ;PortC Bits only work RCO,RC1,RC2,RC6, RC7 CALL DELAY10 MOVLW B'00000000' ;clear portC MOVWF PORTC MOVLW B'00000000' ;clear portB inputs MOVWF PORTB GOTO HOLD2 ;####???? REMOVE DELAY RETURN ##################################### HOLD2 ;inter loop MOVF PORTE,W ;PORT-B, RB3 (INPUT) Stat Button pressed MOVWF BUTTON1 ;Button MOVF BUTTON1,W XORLW B'00000011' ; Fast-Start Bit0 speed, bit1 start BTFSC STATUS,Z GOTO VegFAST ;goto Fast veg MOVF BUTTON1,W XORLW B'00000010' ; Slow-start bit0 speed, bit1 start BTFSC STATUS,Z GOTO VegSLOW ;goto Slow veg GOTO HOLD2 VegSLOW ;This is the Main loop to run until timer is complete. Set-up MOVLW B'10000000' ;( RC7 clear-S MOVWF PORTC ; CALL DELAY100 CALL DELAY100 CLRF BUTTON1 MOVLW B'00000100' ;start timer RC0 MOVWF PORTC CALL DELAY200 ;fast ;MOVLW B'00000010' ;RC1 reset timer latch ;MOVWF PORTC ;CALL DELAY200 MOVLW B'00000001' ;RC0 time gate enabled remain on to end MOVWF PORTC GOTO SlowRAND ;Best Random Code ---------------------------------------------- SlowRAND movlw .123 movwf Random ReadS call RandS ; call RandS ;Call Rand 4 times call RandS ; call RandS ; movf Random,W ; andlw d'15' ; sublw d'13' ;allow 0 to 13 only btfss STATUS,C ; ; goto ReadS ;if not 15 call Rand one mor time again;;New code movf Random,W ;move # in Random to count number in table. andlw .15 PAGESEL Tables call TableS movwf PORTD call DelaySlow goto ReadS TableS movwf temp movlw high(datatab) movwf PCLATH rlncf temp,W addlw low(datatab) btfsc STATUS,Z incf PCLATH,F movwf PCL datatab ;data table for bit pattern on PORT D retlw b'00000010' ;Larry retlw b'00010000' ;JR retlw b'00000100' ;Laura retlw b'00001000' ;L-Boy retlw b'00000001' ;BOB retlw b'00010000' ;JR retlw b'00000100' ;Laura retlw b'00000010' ;Larry retlw b'00000001' ;Bob retlw b'00000010' ;Larry retlw b'00000100' ;Laura retlw b'00000001' ;Bob retlw b'00010000' ;JR retlw b'00001000' ;L-Boy RandS rlcf Random,w ;shift and move to W andlw 0x82 ;keep bits 7 and 1 addlw 0x7e ;xor into bit 7 addlw 0x80 ;move to carry bit rlcf Random,f ;shift into seed return DelaySlow ;return; added for testing*******Remove movlw d'200' ;delay 250 ms (4 MHz-clock) movwf count1 S1 movlw d'100' ;change values for speed or call more times movwf counta movlw d'10' movwf countb Delay_S decfsz counta, f goto $+2 decfsz countb, f goto Delay_S decfsz count1 ,f goto S1 retlw 0x00 ;------------------------------------------------------------- VegFAST ;This is the Main loop to run until timer is complete. SetupF ;This is the Main loop to run until timer is complete. Set-up MOVLW B'10000000' ;( RC7 clear-S MOVWF PORTC ; CALL DELAY100 CALL DELAY100 CLRF BUTTON1 MOVLW B'00000100' ;start timer RC0 MOVWF PORTC CALL DELAY200 ;fast ;MOVLW B'00000010' ;RC1 reset timer latch ;MOVWF PORTC ;CALL DELAY200 MOVLW B'00000001' ;RC0 time gate enabled remain on to end MOVWF PORTC GOTO FastRAND ;Best Random Code ---------------------------------------------- FastRAND movlw .123 movwf Random ReadF call RandF ; call RandF ;Call Rand 4 times call RandF ; call RandF ; movf Random,W ; andlw d'15' ; sublw d'13' ;allow 0 to 13 only btfss STATUS,C ; goto ReadF ;if not 15 call Rand one mor time again;;New code movf Random,W ;move # in Random to count number in table. andlw .15 PAGESEL TableF call TableF movwf PORTD call DelayFast goto ReadF TableF movwf tempf movlw high(datatabF) movwf PCLATH rlncf tempf,W addlw low(datatabF) btfsc STATUS,Z incf PCLATH,F movwf PCL ;data table for bit pattern on PORT D datatabF retlw b'00000010' ;Larry retlw b'00010000' ;JR retlw b'00000100' ;Laura retlw b'00001000' ;L-Boy retlw b'00000001' ;BOB retlw b'00010000' ;JR retlw b'00000100' ;Laura retlw b'00000010' ;Larry retlw b'00000001' ;Bob retlw b'00000010' ;Larry retlw b'00000100' ;Laura retlw b'00000001' ;Bob retlw b'00010000' ;JR retlw b'00001000' ;L-Boy RandF rlcf Random,w ;shift and move to W andlw 0x82 ;keep bits 7 and 1 addlw 0x7e ;xor into bit 7 addlw 0x80 ;move to carry bit rlcf Random,f ;shift into seed return DelayFast ;return; added for testing movlw d'200' ;delay 250 ms (4 MHz clock) movwf count1 F1 movlw d'100' movwf counta movlw d'1' movwf countb Delay_F decfsz counta, f goto $+2 decfsz countb, f goto Delay_F decfsz count1 ,f goto F1 retlw 0x00 ;------------------------------------------------------------- DELAY200 ;return ;long delay******************////?Remove movlw D'10' movwf CounterC movlw D'5' movwf CounterB movlw D'1' movwf CounterA LOOP200 decfsz CounterA,f goto LOOP200 decfsz CounterB,f goto LOOP200 decfsz CounterC,f goto LOOP200 RETURN ;************************************ DELAY100 ;return ;short*****************/////?? Remove movlw D'50' movwf CounterC movlw D'10' movwf CounterB movlw D'1' movwf CounterA LOOP100 decfsz CounterA,f goto LOOP100 decfsz CounterB,f goto LOOP100 decfsz CounterC,f goto LOOP100 RETURN DELAY10 ;return ;very short delay**********************////??Remove movlw D'25' movwf CounterC movlw D'15' movwf CounterB movlw D'1' movwf CounterA LOOP10 decfsz CounterA,f goto LOOP10 decfsz CounterB,f goto LOOP10 decfsz CounterC,f goto LOOP10 RETURN END