;********************************************************** ;*SEASONG #1 - OCEAN WAVE RECORDER+LOGGER * ;********************************************************** ;...as of may 1st 2011 LIST P=16F74 ;--------------USER DIRECTIVE-------------------------------- ;BEGINS RECORD ON PRESS OF BUTTON 1 FOR 1 SECOND ; (GREEN TO RED) ..LED FLASHES CONTINUOUSLY ;TO STOP RECORDING, PRESS AND HOLD UNTIL LED GOES RED & FLICKERS ONCE ;CONNECT TO PC [115.2KBAUD] AND TYPE "D" {an * will be returned} ;DATA OUTPUT WILL COMMENCE AFTER 12 SECONDS.(TIME TO START LOGGER) ;//TO ERASE DATA, PRESS AND HOLD BUTTON 1 UNTIL LED GOES OUT, THEN ;//PRESS AGAIN WITHIN 3 SECONDS BRIEFLY ;------------------------------------------------------------ ; ;-------------OPERATION-------------------------------------- ;BY SAMPLING A FULL PULSE WIDTH (H&L) FROM SEA-CAP. OSC ;ONCE EVERY 0.1 SECONDS, THE CAPACITANCE CAN BE FOUND.TO LOG BY ;REAL SECONDS, A QUARTZ TIME PIECE SENDS .5 HZ, AND TRANSITION ;INCR. FOR NEXT SECOND. DURATION IS NOTED IN BUFS ___,___ BUT CAN ;ONLY BE READ USING "DUMP ALL" FROM PC (flash) ;AN ESTIMATED TIME SERIES OF 19 MORE SAMPLES ARE TAKEN, BUT TICK ;TRANSITION KEEPS IT ALIGNED FOR PERFECT TIME SYNC. ;AFTER A "DUMP ALL" IS RX'ED, AND 10 SECS PASSES, A .WAV FILE IS ;COMPOSED IN MONO/48000/PCM THAT CAN BE LOGGED AS .TXT --->.WAV ;------------------------------------------------------------ ; ;------------Ports / pins Used------------------------------- ;adc0(battery voltage/2), ___(LED),___(BUTTON),_ _ _ _(S-RAM) ;__(tick in), RA2(sensor in 555), RA5(4510 IN),__(MAX-232 chip Vdd on) ;------------------------------------------------------------- ; ; ;****NOTE:::must check rxusrt / reset RX bit that locks it up! ;LOWER BANK..... INDF EQU 0X00 TMR0 EQU 0X01 PCL EQU 0X02 STATUS EQU 0X03 FSR EQU 0X04 PORTA EQU 0X05 PORTB EQU 0X06 PORTC EQU 0X07 PORTD EQU 0X08 PORTE EQU 0X09 PCLATH EQU 0X0A INTCON EQU 0X0B PIR1 EQU 0X0C PIR2 EQU 0X0D TMR1L EQU 0X0E TMR1H EQU 0X0F T1CON EQU 0X10 TMR2 EQU 0X11 T2CON EQU 0X12 SSPBUF EQU 0X13 SSPCON EQU 0X14 CCPR1L EQU 0X15 CCPR1H EQU 0X16 CCP1CON EQU 0X17 RCSTA EQU 0X18 TXREG EQU 0X19 RCREG EQU 0X1A CCPR2L EQU 0X1B CCPR2H EQU 0X1C CCP2CON EQU 0X1D ADRES EQU 0X1E ADCON0 EQU 0X1F TIMER0 EQU 0X20 TIMER1 EQU 0X21 TIMER2 EQU 0X22 SSTATUS EQU 0X23 ;SS FLAGS(SEE BELOW) SDCFLAGS EQU 0X24 ;flags for SC CARD FUNC'S RXBP EQU 0x25 SRBUF EQU 0X26 ;S-RAM SPI BUFFER SECS EQU 0X27 MINS EQU 0X28 TMR0LAST EQU 0X29 ;TO SHOW CHANGE IN TMR0 TIMEFLAGS EQU 0X2A ;SEE BITS BELOW BEEPCNT EQU 0X2B ;COUNTS 120 SECS BEFORE BEEP STOPS LOGFLAGS EQU 0X2C ;ALL FLAGS FOR REGULAR SLOWLOGS TEMP EQU 0X2D ;TO BE USED *LOCALLY* ONLY TEMP2 EQU 0X2E ; TEMP3 EQU 0X2F ;USED IN USART RX, USE IF NO RX INVOLVED ;------------------------------------------------USART TX/(RX) BUFFERS:: UBUF0 EQU 0X30 ;UPPER UBUF'S USED TEMP AS BUFFERS.. UBUF1 EQU 0X31 UBUF2 EQU 0X32 UBUF3 EQU 0X33 UBUF4 EQU 0X34 UBUF5 EQU 0X35 UBUF6 EQU 0X36 UBUF7 EQU 0X37 UBUF8 EQU 0X38 UBUF9 EQU 0X39 UBUF10 EQU 0X3A UBUF11 EQU 0X3B SDAD0 EQU 0X3C ;SD CARD ADDRESS 0-->256 SDAD1 EQU 0X3D ;SD CARD ADDRESS 256-->65,536 SDAD2 EQU 0X3E ;SD CARD ADDRESS 65K-->16,777,215 SDAD3 EQU 0X3F ;SD CARD ADDRESS 16M-->4.294 gig MAD0 EQU 0X40 MAD1 EQU 0X41 MAD2 EQU 0X42 MAD3 EQU 0X43 ;--- TEMP4 EQU 0X58 ;USED IN SRAM WRITE/READ BUTBUF EQU 0X59 ;ACCUM FOR BUT EXCLUSIVE PCCOM EQU 0X5A ;PC COMMAND (SEE BITS BELOW) SENSCNTMSB EQU 0X5F SENSCNTLSB EQU 0X60 FLASH_COUNT EQU 0X61 UBUFPOINT EQU 0X62 ;---------------------------------------------- MATHFLAGS EQU 0X76 ;FLAGS FOR MATH ROUTINES(see below) SPI_TX EQU 0X77 ;SPI_TX, CAN BE USED ELSEWHERE SPI_RX EQU 0X78 ;SPI_RX BUFFER, CAN BE USED ELSEWHERE ;---------------------------------------------- DUMPFLAGS EQU 0X79 ;0=DUMP SRAM->SDCARD, ;---------------------------------------------- SEL4066 EQU 0X7A ;Holds RLF FOR ADCx 4066 SELECT(0001) LOG4066 EQU 0X7B ;Holds upper row select for ADCLOG table SRADMSB EQU 0X7C ;SRAM CURRENT ADDRESS MSB (BIT 7=DONTCARE) SRADLSB EQU 0X7D ;SRAM CURRENT ADDRESS LSB DATABYTE EQU 0X7E ;HOLDS DATA TO BE WRITTEN/READ FROM S-RAM SECCNT EQU 0X7F ;COUNTS 256 SECONDS AND ROLLS ;(FOR H/EBATTS AND WHATEVER) ;---------------------------------------------- ;UPPER BANK..... OPTION_REG EQU 0X81 TRISA EQU 0X85 TRISB EQU 0X86 TRISC EQU 0X87 TRISD EQU 0X88 TRISE EQU 0X89 PIE1 EQU 0X8C PIE2 EQU 0X8D PCON EQU 0X8E PR2 EQU 0X92 SSPADD EQU 0X93 SSPSTAT EQU 0X94 TXSTA EQU 0X98 SPBRG EQU 0X99 ADCON1 EQU 0X9F HRS EQU 0XD0 ;TICK HRS (MIN SEC IN LO RAM) DAYS EQU 0XD1 ;TICK DAY MONS EQU 0XD2 ;TICK MON YEARS EQU 0XD3 ;TICK YEAR WEEKDAY EQU 0XD4 ;TICK WEEKDAY(IF NEEDED) ;------LOGGABLE DATA BUFFERS--------- A0-C7 ;---------------------------------------------- ;***eQUate bits***....__________________ ;SSTATUS BYTE FLAG: RECMODE EQU .0 ;SET WHEN RECORDING RXWAIT EQU .1 ; CARD EQU .2 ; DIAG EQU .3 ; RECSTOP EQU .4 ; RETFLAG EQU .5 ; XXXXXXX EQU .6 ; ;EEPFLAGS BYTE: EEPRTW EQU .0 ;Ready to write flag EEPRTWS EQU .1 ;Ready to write settings flag(from NMEA ram) EEPMULTI EQU .2 ;Set for multibyte EEPDUMP EQU .3 ;DUMPREQ sent,waiting for GO EEPDUMP1ST EQU .4 ;Stops ADDR reload after 1ST byte ;REUSE EQU .5 ;Set to return from a routine re-use ;TXSTA BITS TXEN EQU .5 BRGH EQU .2 ;MAY NOT USE,JUST USE BYTE TRMT EQU .1 SYNC EQU .4 ;RCSTA BITS SPEN EQU .7 CREN EQU .4 OERR EQU .1 ;PIR1 BITS TMR1IF equ .0 TMR2IF EQU .1 ;SET WHEN TMR2 DONE TXIF EQU .4 RCIF EQU .5 ;SSPSTAT BF EQU .0 ;BF (BUFFER FULL) BIT 0 ;PORTC 0,1,2 FOR SERIAL RAM SI EQU .0 ;SRAM SI SO EQU .1 ;SRAM SO CK EQU .2 ;SRAM CK CS EQU .0 ;SRAM CHIP SELECT(PORTD,0) ;PCCOM LIVE EQU .0 ;+++++ ORG 0000 GOTO START ORG 0004 NOP ;INTERUPT VECTOR ORG 0005 START CLRRAM2 ;CLEARS BOTH PAGES OF RAM 0020 TO 00FF movlw 0x20 ;initialize pointer movwf FSR ;to RAM CLRRAM2LP clrf INDF ;clear INDF register BSF FSR,7 ;UPPER RAM CLRF INDF BCF FSR,7 incf FSR ;inc pointer btfss FSR,7 ;all done? goto CLRRAM2LP ;no, clear next BYTE ;------------------SETUP PORTS------------------ ; 1 ADC FOR BATTERY MONITOR (EMERGE SAVE) ; LED OUT, BUTTON IN, SENSOR IN, TICK IN, RS232 OFF ; SDC SPI(CS,CK,DI,DO), S-RAM SPI(CS,CK,DI,DO MANUAL), USART I/O CLRF FSR BSF STATUS,5 ;TRISES ARE IN UPPER MEM! MOVLW B'11111111' ;RA,2=NC .RA4-TMR0 INPUT MOVWF TRISA MOVLW B'00000111' ;ONLY LAST 3 ARE PORT DIRECTION!! MOVWF TRISE MOVLW B'00111111'; 4=SDC SWITCH, 7&6 for led 5=BUTTON MOVWF TRISB ; **CHANGE** MOVLW B'11111000' ;0=CS FOR SRAM,1=CS FOR SDC,2=BEEPER GND, 7 555 INPUT MOVWF TRISD ; MOVLW B'11010010' ;C0=SRAM SI,C1=SO,C2=CK MOVWF TRISC MOVLW .1 ;FOR USART BAUD RATE GEN WAS .25 MOVWF SPBRG ;115,200 BAUD BCF TXSTA,BRGH ;SET HISPEED BAUD GEN WAS =1 BCF TXSTA,SYNC ;SET TO ASYNC MODE BCF STATUS,5 MOVLW B'11000000' MOVWF PORTB ;LIGHT BOTH LEDS CLRF PORTC MOVLW 0X30 MOVWF RXBP ;????? BSF RCSTA,SPEN ;SETS TO USART SERIAL PORTS BSF RCSTA,CREN ;SET TO CONTIN. RX movlw B'00110101' ;SETUP TMR1 MODULE APRIL2011 MOVWF T1CON ;/8 PRESCALE movlw B'00100110' ;SETUP TMR2 MODULE MOVWF T2CON ;/16 PRESCALE,/5post MOVLW .7 MOVWF PCLATH ;UPPER RAM BSF STATUS,5 BSF TXSTA,TXEN ;SET USART TO TX,NEXTBYTE WRIT WILL START IT BsF OPTION_REG,5 ;USE TMR0 ON EXT CLK(TICK) BSF OPTION_REG,3 ;SELECTS OUT PRESCALER MOVLW B'00000101' ; Configure 2 ADC PINS MOVWF ADCON1 ; as anal inputs movlw .250 ;TMR2 MODULE COMPARE (/250) MOVWF PR2 ;LOWER RAM BCF STATUS,5 MOVLW B'10000001' MOVWF ADCON0 CALL DELAY2 ;1 SECOND DELAY AT STARTUP... CLRF TMR0 CLRF DUMPFLAGS CLRF PORTB ;DOUSE LEDS BSF PORTD,CS ;??NEED? MOVLW .40 ;"Sea-Song" CALL MESSAGES MOVLW .32 ;"NOCARD" BTFSC PORTB,4 ;CARD IN? CALL MESSAGES ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAINLOOP NOP ;This area left somewhat for learning curve reduction! ;Record on: Check BUTTON, CHECK TMR0 (1/10s sample time) ;RECORD off: Check BUTTON, Check USARTRX ;LIVE mode on: Check USARTRX, CHECK TMR0 USARTRXQ ;check for rx from ped BTFSS PIR1,RCIF GOTO TICKQ ; GOTO PC_COMMANDS USARTRX_RET NOP TICKQ ;COMPARE TMR0 FOR CHANGE ONCE EVERY 2 SECONDS! MOVF TMR0,W XORWF TMR0LAST,W BTFSS STATUS,2 ;SKIP IF STILL SAME SECOND(INC TMR0LAST IF NOT) CALL TICK SAMPCHECK ;IF TMR1H/L>0XC350 1/(50,000 * 8[prescale])*10[1/10TH SEC!] ;now @ 15MHZ CLK=46,875 ;..or .1 secs/.25uS/8 or .1/8*cyc MOVLW 0XB7 ;1/10 SECOND SUBWF TMR1H,W BTFSS STATUS,0 ;SKIP IF >C3 GOTO EVENTQ ;FOR NOW MOVLW 0X1B SUBWF TMR1L,W BTFSS STATUS,0 GOTO EVENTQ MOVLW 0XB7 SUBWF TMR1H ;REDUCE BY 1/10 SECOND MOVLW 0X1B SUBWF TMR1L CALL GETSAMP ;**********HERE ONLY EVERY 1/10 SECOND******* BUTTONQ ;CHECK BUTTON BTFSS PORTB,5 GOTO PIEZO PIERET BTFSS PORTB,5 INCF BUTBUF MOVF BUTBUF,W ;TEST FOR ZERO BTFSC STATUS,2 GOTO BUTDONE BTFSC PORTB,5 GOTO BUT_RELEASE MOVLW .10 SUBWF BUTBUF,W BTFSS STATUS,0 GOTO BUT2 BCF PORTB,7 ;TURN OFF GLED, TURN ON RED BSF PORTB,6 BUT2 MOVLW .20 XORWF BUTBUF,W BTFSC STATUS,2 BCF PORTB,6 ;TURN OFF RED BUTDONE BTFSC PORTB,5 BCF PORTB,6 ;TURN OFF RED(FROM SDCWRITE) IF BUTTON NOT PRESSED GOTO LIVEQ LIVEQ BTFSC PCCOM,LIVE ;IN LIVE MODE? CALL LIVETX ; ********--------END 1/10TH------------------****************- EVENTQ ;CHECKS A SERIES OF FLAGS FOR UPDATES IN RECORD OR NOT BTFSC DUMPFLAGS,0 CALL SDC_WRITE ;SAVE SRAM TO SDC, GOTO BATTERY_TEST ;CHECK BATTERY HERE, GOOD PLACE BTRET NOP ;WILL SAVE ONE MORE (6.4 SECS THEN STOP) ;RXUSART ERR FIX:only possible during testing as pedistalpic will only ;send a _2 BYTE_ code to clear channel...or something like that ;an extra buffer or 2 should be assigned in any case for RCREG(call>) ;BTFSS RCSTA,OERR ;FIRST:CHECK FOR RX USART OVERRUN ERROR ;GOTO EVENT1 ;BCF RCSTA,CREN ;RESET RX USART ; NOP ; BSF RCSTA,CREN EVENT1 BTFSC PORTB,4 ;LOW IF CARD INSERTED GOTO EVENT4 ;NO CARD BTFSC SSTATUS,CARD GOTO EVENT2 ;ALREADY SET CALL DELAY2 ;DEBOUNCE BTFSC PORTB,4 GOTO EVENT4 ;NO CARD PC_J CALL SPI_SETUP BCF PORTB,6 ;RED OFF BSF PORTB,7 ;GREEN CALL DELAY2 ;1 SEC DELAY MOVLW .24 ;"CARDin" CALL MESSAGES CALL SDCINI BCF PORTB,7 EVENT2 GOTO MAINLOOP ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EVENT4 BTFSC SSTATUS,CARD CALL DELAY2 ;1 SEC DELAY BCF SSTATUS,CARD BSF PORTB,6 GOTO EVENT2 BATTERY_TEST MOVLW B'10000001' ;BITS 5-3 SEL PIN USING /32 MOVWF ADCON0 bsf ADCON0,2 NOP ADCWT2 BTFSC ADCON0,2 ;WAIT FOR ADCi DONE(JUST IN CASE) GOTO ADCWT2 MOVF ADRES,W SUBLW 0XB1 ;JUST BEFORE BATTERIES FAIL BELOW 5 V ON REG! BTFSC STATUS,0 ;SKIP IF OK GOTO RECORD_STOP GOTO BTRET PIEZO BSF STATUS,5 MOVLW B'11111000' ;BIT D,2=BEEPER GND MOVWF TRISD ; TURN ON BEEPER BCF STATUS,5 CLRF BEEPCNT BSF PORTB,7 ;TURN ON GREEN LED GOTO PIERET ;~~~~~~~~~~~~~~~~~~~~~RECORD START~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ONCE RECORD BUTTON PRESSED, IT COMES HERE. THE S-RAM IS ; INITIALIZED WITH A 44 BYTE .WAV HEADER SPACE, THEN 4 BYTES ARE ; FILLED WITH THE SAME SENSOR DATA SO AS TO START AT BYTE 48 ; THE FIRST 44 BYTES (IN 512BYTE BLOCK) WILL BE LOADED ; TO S-RAM, WRITTEN IN, THEN RE-SAVED TO SD CARD AFTER SIZE ; OF .WAV IS KNOWN!(AT RECSTOP) [FROM A TABLE FOR RIFF/WAV/FORMAT ETC] RECORD CALL SDAD_CLR ;CLEAR SD CARD ADDRESS POINTER FOR NEW.. MOVLW .2 ;WRITE 44-47 MOVWF TEMP2 ;COUNT 2BYTES MOVLW .44 MOVWF SRADLSB ;CLEAR TO S-RAM START CLRF SRADMSB BSF SSTATUS,RECMODE call SEASONG ;TO LOAD 1ST VALUES INTO S-RAM "PAGE" RECLP1 MOVF SENSCNTLSB,W ;LITTLE ENDIAN DATA MOVWF UBUF8 ;FOR FIRST AVERAGE MOVWF DATABYTE CALL SRAMSAVE INCF SRADLSB ;NEXT ADDR IN SRAM MOVF SENSCNTMSB,W ;LITTLE ENDIAN DATA MOVWF UBUF9 ;FOR FIRST AVERAGE MOVWF DATABYTE CALL SRAMSAVE INCF SRADLSB ;NEXT ADDR IN SRAM DECFSZ TEMP2 GOTO RECLP1 ; ***NOW SENSOR DATA CAN FOLLOW STARTING AT 48 ADDR IN S-RAM RETURN RECORD_STOP ;CAN ALSO COME HERE FROM A VOLTAGE DROP BELOW $B1 BTFSS SSTATUS,RECMODE ;VERIFIY IN REC MODE! GOTO MAINLOOP ;NOPE BSF SSTATUS,RECSTOP ;SO REC WILL STOP AT END OF BLOCK! NOP ;***CLOSE .WAV FILE AND FILL VALUES ETC APPROPRIATELY GOTO MAINLOOP RECORD_START ;FROM PC_COMMAND BTFSc SSTATUS,RECMODE ;VERIFIY not IN REC MODE already! GOTO MAINLOOP ;it is BSF STATUS,5 MOVLW B'11111000' ;BIT D,2=BEEPER GND MOVWF TRISD ; TURN ON BEEPER FOR 2 MINS BCF STATUS,5 CLRF BEEPCNT MOVLW .47 ;47 * 6.4 SECONDS = ABOUT 5 MINUTES MOVWF FLASH_COUNT MOVLW .8 ;"RECON" MESSAGE CALL MESSAGES MOVLW 0X0D ;RETURN CALL READRAMTX CALL RECORD GOTO MAINLOOP ;~~~~~~~~~~~~~~~~~GET sample~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~ GET 20 SAMPLES/TICK USING TMR1 @10HZ (400,000 CYC) BUT ~ ;~ USE 8:1 PRESCALE = 50,000.IF TMR1H>0XC3 (0XC350) THEN GO~ ; GET NEXT SAMPLE. ;~SAVE LAST 2 BYTE SAMPLE TO S-RAM, ALONG WITH 3 AVERAGES ~ TICK ;2 SECONDS HAS PASSED! MOVF TMR0,W MOVWF TMR0LAST CLRF TMR1H ;RESET FOR NEXT SAMPLE CLRF TMR1L INCF BEEPCNT MOVF BEEPCNT,W XORLW .60 ;2 MINUTES BTFSS STATUS,2 GOTO GETSAMP BSF STATUS,5 MOVLW B'11111100' ;RELEASE D,2=BEEPER GND MOVWF TRISD BCF STATUS,5 GETSAMP ;1/10TH SEC SAMPLES CALL SEASONG ;GET 1ST SAMPLE of 20 (THIS TICK) NOW BTFSS SSTATUS,RECMODE ;IF RECMODE=0 THEN NOT RECORDING, RETURN GOTO SVDONE ;RETURN-just to use sample time delay(1/10S) MOVF UBUF8,W ;SLIDE DOWN LAST DATA-LSB MOVWF UBUF0 ;LSB LAST MOVF UBUF9,W ;MSB MOVWF UBUF1 ;MSB LAST MOVF SENSCNTLSB,W ;put NEW data in UBUF9,8 MOVWF UBUF8 MOVF SENSCNTMSB,W ;LITTLE ENDIAN HERE! MOVWF UBUF9 CALL SDAVERAGE ;FILL SPOTS BETWEEN WITH AVERAGE DATA ;NOW MUST BE UBUFFED IN, ONLY UBUF 0 TO 7 BUT IN THIS ORDER FOR .WAV! MOVLW 0X30 MOVWF UBUFPOINT ;(OLD TO NEWEST, BUT NOT THE ACTUAL LAST SAMPLE) ; in 4's...right? april14th so only 128 actual samples can fit.. SVSAMP1 MOVF UBUFPOINT,W MOVWF FSR MOVF INDF,W MOVWF DATABYTE CALL SRAMSAVE INCFSZ SRADLSB ;NEXT ADDR IN SRAM !!CHECK TO SEE IF THIS INITIALIZED!! GOTO SVSAMP2 INCF SRADMSB MOVLW 0X02 ;512 BYTES? XORWF SRADMSB,W BTFSC STATUS,2 BSF DUMPFLAGS,0 ;TO JUMP TO SDCSAVE FLAG RETURN SVSAMP2 INCF UBUFPOINT BTFSS UBUFPOINT,3 ;>UBUF7? WAIT FOR NEXT SAMPLE TIME (.1SECS) GOTO SVSAMP1 SVDONE RETURN BUT_RELEASE BCF PORTB,7 ;TURN OFF G LED BCF PORTB,6 ;TURN OF R LED MOVLW .10 ;<1 SECOND SUBWF BUTBUF,W BTFSS STATUS,0 GOTO BUTTON1 MOVLW .20 ;>1,<2 SECS SUBWF BUTBUF,W BTFSS STATUS,0 GOTO BUTTON2 MOVLW .30 SUBWF BUTBUF,W BTFSS STATUS,0 GOTO BUTTON3 ;>2,<3 SECS BUTTON4 ;>4 SECONDS CLRF BUTBUF GOTO RECORD_STOP BUTTON1 ;FAST BUTT PRESS..RESTART REC FLASHING CLRF BUTBUF MOVLW .47 ;47 * 6.4 SECONDS = ABOUT 5 MINUTES MOVWF FLASH_COUNT GOTO BUTDONE BUTTON2 CLRF BUTBUF GOTO RECORD_START BUTTON3 CLRF BUTBUF GOTO BUTDONE ;~~~~~~~~~~~~~~~~~~~~~~SENSOR ROUTINE~~~~~~~~~~~~~~~~~~~~~~~ ;Sensor is on PORTA,1. The 2 bytes:SENSCNTMSB & SENSCNTLSB ~ ;increment after a low->hi, then after a hi->lo, and lastly~ ;a low->hi stops count. Data can be logged to 256 samps ~ ;(64 REAL SAMPLES, THE REST AVERAGED) to ~ ;the SRAM, at which point it will be dumped to SD card ~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SEASONG CLRF SENSCNTMSB CLRF SENSCNTLSB ;**USE FLAG TO JUMP TO ALTERNATE(4510)PORTA,5 INPUT! NEED TO DUPLICATE WHOLE THING! ;BTFSC ?? SHOULD i EVEN GO DIRECT????? PROLLY NOT!! GOTO aSEALOOP1 ;------------------DIRECT FROM 555 TIMER SEALOOP1 BTFSS PORTD,7 ;WAIT FOR LOW GOTO SEA2 SL1 BTFSS PORTD,7 ;WAIT FOR LOW GOTO SEA2 BTFSS PORTD,7 ;WAIT FOR LOW GOTO SEA2 INCFSZ SENSCNTLSB ;TIMEOUT GUARD GOTO SEALOOP1 INCFSZ SENSCNTMSB GOTO SL1 GOTO SEADONE ;ERROR: =0X0000 SEA2 CLRF SENSCNTMSB CLRF SENSCNTLSB SEALOOP2 BTFSC PORTD,7 ;WAIT FOR HI GOTO SEASTART SL2 BTFSC PORTD,7 ;WAIT FOR HI GOTO SEASTART BTFSC PORTD,7 ;WAIT FOR HI GOTO SEASTART INCFSZ SENSCNTLSB ;TIMEOUT GUARD GOTO SEALOOP2 INCFSZ SENSCNTMSB GOTO SL2 GOTO SEADONE ;ERROR: =0X0000 SEASTART ;READY TO COUNT MOVLW 0X01 ;REMOVE DELAY FROM PROBE/UNIT CAPACITANCE ;=0033(estimate--no probe) MOVWF SENSCNTMSB ;MAY READ THIS FROM SDCARD IN FUTURE! MOVLW 0X33 MOVWF SENSCNTLSB STDLY NOP ;8CYC PER NOP NOP NOP NOP DECFSZ SENSCNTLSB GOTO STDLY DECFSZ SENSCNTMSB GOTO STDLY SEALOOP3 NOP ;TIMING=8CYC/SAMPLE NOP NOP SEALP3 BTFSS PORTD,7 ;COUNT UNTIL LOW GOTO SEAFINISH INCFSZ SENSCNTLSB ;COUNT GOTO SEALOOP3 INCFSZ SENSCNTMSB GOTO SEALP3 GOTO SEATOPPED ;ERROR: =0X0000 SEAFINISH NOP ;TIMING=8CYC/SAMPLE NOP NOP SEALP4 BTFSC PORTD,7 ;COUNT UNTIL HIGH GOTO SEADONE INCFSZ SENSCNTLSB ;COUNT GOTO SEAFINISH INCFSZ SENSCNTMSB GOTO SEALP4 GOTO SEATOPPED ;ERROR: =0X0000 SEADONE ;COUNT IS IN SENSCNTMSB & SENSCNTLSB ;IF BOTH = 0X00, THEN THERE WAS AN ERROR,HANDLE AS DATA BUT ;SHOULD THERE BE A SIGNAL LIKE FAST FLASHING LED?? RETURN ;now mov ubuff9,8 to 1,0 and load these into 9,8 ;then fill betweens with SDAVERAGE ;-----------FROM 4510-------------- aSEALOOP1 ;9/CYC 11/CYC-on MSB inc. BTFSS PORTA,5 ;WAIT FOR LOW GOTO aSEA2 aSL1 BTFSS PORTA,5 ;WAIT FOR LOW GOTO aSEA2 BTFSS PORTA,5 ;WAIT FOR LOW GOTO aSEA2 INCFSZ SENSCNTLSB ;TIMEOUT GUARD GOTO aSEALOOP1 INCFSZ SENSCNTMSB GOTO aSL1 GOTO SEADONE ;ERROR: =0X0000 aSEA2 CLRF SENSCNTMSB CLRF SENSCNTLSB aSEALOOP2 BTFSC PORTA,5 ;WAIT FOR HI GOTO aSEASTART aSL2 BTFSC PORTA,5 ;WAIT FOR HI GOTO aSEASTART BTFSC PORTA,5 ;WAIT FOR HI GOTO aSEASTART INCFSZ SENSCNTLSB ;TIMEOUT GUARD GOTO aSEALOOP2 INCFSZ SENSCNTMSB GOTO aSL2 ;TAKE UP 2 GOTO SEADONE ;ERROR: =0X0000 aSEASTART ;READY TO COUNT MOVLW 0X02 ;REMOVE DELAY FROM PROBE/UNIT CAPACITANCE=021E(no probe) MOVWF SENSCNTMSB ;MAY READ THIS FROM SDCARD IN FUTURE! MOVLW 0X00 MOVWF SENSCNTLSB aSTDLY NOP ;8CYC PER NOP NOP NOP NOP DECFSZ SENSCNTLSB GOTO aSTDLY DECFSZ SENSCNTMSB GOTO aSTDLY ;CLRF SENSCNTMSB ;CLRF SENSCNTLSB aSEALOOP3 NOP ;TIMING=8CYC/SAMPLE NOP NOP aSEALP3 BTFSS PORTA,5 ;COUNT UNTIL LOW GOTO aSEAFINISH INCFSZ SENSCNTLSB ;COUNT GOTO aSEALOOP3 INCFSZ SENSCNTMSB GOTO aSEALP3 GOTO SEATOPPED ;ERROR: =0X0000 aSEAFINISH NOP ;TIMING=8CYC/SAMPLE NOP NOP aSEALP4 BTFSC PORTA,5 ;COUNT UNTIL HIGH GOTO SEADONE INCFSZ SENSCNTLSB ;COUNT GOTO aSEAFINISH INCFSZ SENSCNTMSB GOTO aSEALP4 GOTO SEATOPPED ;ERROR: =0X0000 SEATOPPED ;HERE IF OVERFLOW, SET TO FFFF DECF SENSCNTMSB DECF SENSCNTLSB GOTO SEADONE ;~~~~~~~~~~~~~~~~~~~~"REAL" SPI SETUP~~~~~~~~~~~~~~~~~~~~~~~~ ;COMES HERE ON POWER UP OR CARD IN (LOW ON RD 7 WHILE SSTATUS,CARD =0 SPI_SETUP ;SET UP SPI BUS TO SDCARD BSF SSTATUS,CARD BSF STATUS,5 ;TRISES,SSPSTAT ARE IN UPPER MEM! ;MOVLW B'11010001' ;XX010XXX--->ALREADY SET AT START ;MOVWF TRISC MOVLW B'11000000' ;PHASE BIT(7)..BF (bit0)=1 MEANS RXBUFFER FULL ;BIT 6 MAKES CLK EDGE L-H MOVWF SSPSTAT BCF STATUS,5 ;SSPCON IN LOW MEM! MOVLW B'00100001' ;CLK QUIES=LOW, FRQ/16 CLK RATE MOVWF SSPCON MOVLW 0XFF MOVF SSPBUF ;DUMMY TO GET BF SET!!! RETURN ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SD CARD INITIALIZATION~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;INIT's SDC, CLEARS ADDRESSES, SEND RESPONSE AND "ok" SDCINI BTFSS SSTATUS,CARD ;CARD IN? GOTO NOCARD BSF PORTD,1 ;(SDC cs) MOVLW .10 ;10*8=SEND 80 CLOCKS TO SDC MOVWF TEMP SDCINI1 MOVLW 0XFF MOVWF SPI_TX CALL SPI_IO DECFSZ TEMP GOTO SDCINI1 BCF PORTD,1 ;CS MOVLW B'01000000' ;CMD0 CALL SD_COMMAND ;* * * TEMP TO SEND RESPONSE DATA MOVF SPI_RX,W CALL BIN2HEX ;RETURNS HEX$ DATA IN TIMER0,1(1 IS MSB) MOVF TIMER1,W CALL READRAMTX ;USE RAM TX ROUTINE TO SEND MOVF TIMER0,W CALL READRAMTX SDCOCR ;GET OCR (VOLTAGE ETC) CALL DELAY5MS MOVLW B'01111010' ;CMD58 CALL SD_COMMAND MOVLW 0X30 MOVWF FSR SDCOCRLP MOVLW 0XFF ;DUMMY MOVWF SPI_TX CALL SPI_IO ;GET OTHER 4 BYTES IN OCR, PUT TO UBUF0-3 MOVF SPI_RX,W MOVWF INDF ;TEMP MOVF SPI_RX,W CALL BIN2HEX ;RETURNS HEX$ DATA IN TIMER0,1(1 IS MSB) MOVF TIMER1,W CALL READRAMTX ;USE RAM TX ROUTINE TO SEND MOVF TIMER0,W CALL READRAMTX ;/TEMP INCF FSR BTFSS FSR,2 GOTO SDCOCRLP BTFSS UBUF1,7 ;OCR SHOULD = 00FF8000.BIT23=3.6V RETURN ;BAD CARD ETC.COULD RETURN ERROR CODE VIA RS232? ;SEND CMD1 TO INITIALIZE CARD CMD1 MOVLW B'01000001' ;CMD1...SHOULD BE ACMD41 CALL SD_COMMAND ;KEEP SENDING UNTIL r1 RESPONSE D,0=0 CALL DELAY5MS ;5MS BTFSC SPI_RX,0 GOTO CMD1 MOVLW .0 ;"O.K." CALL MESSAGES CLRF SDAD0 ;LSB ALWAYS 0 FOR ADDRESSING CLRF SDAD1 CLRF SDAD2 CLRF SDAD3 ;CLEAR ADDRESS TO 0 (REMEMBER IN 512'S!) RETURN NOCARD MOVLW .32 ;"noCARD" CALL MESSAGES RETURN ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SDC READ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; SDC_READ ;READ A BLOCK STARTING AT SDAD3,2,1,0! PUT TO USART OR SRAM ;ENTERS HERE WITH PCCOMMAND "M" (MAXTIME) BTFSS SSTATUS,CARD ;CARD IN? RETURN MOVLW 0X02 MOVWF TEMP2 ;256's MOVLW B'01010001' ;**CMD17 CALL SD_COMMAND CLRF TEMP SDC_RWT CALL SPI_IO ;GET TOKEN MOVF SPI_RX,W ;CHECK...SHOULD BE 0XFE XORLW 0XFE BTFSS STATUS,2 GOTO SDC_RWT ;DO AGAIN IF NOT ;CHECK FOR 0XFE HERE! ;--SHOULD HAVE RESPONSE CHECK HERE?- SDC_READLP CALL SPI_IO ;GET DATA MOVF SPI_RX,W BTFSC DUMPFLAGS,3 GOTO SDCRAM_ONLY BTFSC DUMPFLAGS,2 GOTO SDCRAW ;SEND RAW DATA DIRECTLY(FOR DUMP) CALL BIN2HEX ;RETURNS HEX$ DATA IN TIMER0,1(1 IS MSB) MOVF TIMER1,W CALL READRAMTX ;USE RAM TX ROUTINE TO SEND MOVF TIMER0,W SDCRAW CALL READRAMTX SDCRAM DECFSZ TEMP GOTO SDC_READLP DECFSZ TEMP2 GOTO SDC_READLP ;DONE DATA CALL SPI_IO ;GET CRC JUNK CALL SPI_IO ;GET CRC JUNK SDC_INC INCF SDAD1 ;ADD512 USED ALSO BY WRITE INCFSZ SDAD1 GOTO SDC_READX INCFSZ SDAD2 GOTO SDC_READX INCF SDAD3 ;SHOULD HAVE A MAX SIZE HERE FFFFFFFF=4GIG SDC_READX RETURN ;RET TO "F" PC-COMMAND FOR NOW SDCRAM_ONLY ;ONLY SAVE TO SRAM (DUMPFLAGS,3) MOVWF DATABYTE CALL SRAMSAVE INCFSZ SRADLSB GOTO SDCRAM INCF SRADMSB GOTO SDCRAM ;SKIPPING ALL THIS NOW!! DAMN! ;SDCRAW ;SEND RAW DAT [ MODIFIED: - 0X8000 UNLESS <44 .wav file data ] MOVWF DATABYTE ;(TEMP USE) BTFSS TEMP,0 ;IS MSB? fe,fc,fa,f9 ETC-LITTLE ENDIAN GOTO SDCRAW2 ;NO SO SKIP MODIFYING AT ALL MOVF SDAD1,W ;CHECK IF AT 00000000 ADDR BTFSS STATUS,2 ;RESULTS ZERO? GOTO SDCRAW1 ;NOPE, SO DO SUBTRACT MOD MOVF SDAD2,W BTFSS STATUS,2 ;RESULTS ZERO? GOTO SDCRAW1 ;NOPE, SO DO SUBTRACT MOD MOVF SDAD3,W BTFSS STATUS,2 ;RESULTS ZERO? GOTO SDCRAW1 ;NOPE, SO DO SUBTRACT MOD BTFSS TEMP2,1 ;CHECK TEMP2 IN FIRST 256? GOTO SDCRAW1 ;NOPE, SO DO SUBTRACT MOD DECF TEMP,W ;GET TO FF IF AT 0 ADDLW 0X2C BTFSC STATUS,0 ;<44? GOTO SDCRAW2 SDCRAW1 MOVLW 0X80 ;********OH BOY WHAT A MESS SUBWF DATABYTE SDCRAW2 MOVF DATABYTE,W CALL READRAMTX GOTO SDCRAM ;---------------------------SEND A COMMAND TO SD CARD------------------------------------------------ SD_COMMAND ;FOLLOWING 4 BYTES WILL BE ADDRESS, UNLESS A SPECIAL(SETUP) ;REMEMBER SDAD0-3 HAVE ACTUAL SDC ADDRESS DATA! IF NEED TO ;PRESERVE, TRANSFER TO UBUF2,3,4,5 AS THEY HAVE BEEN WRITTEN MOVWF SPI_TX ;COMMAND CODE IS IN W CALL SPI_IO MOVLW 0X3F ;NEXT 4 BYTES ADDR, MSB FIRST MOVWF FSR SD_COMLP MOVF INDF,W MOVWF SPI_TX CALL SPI_IO DECF FSR BTFSC FSR,2 GOTO SD_COMLP MOVLW 0X95 ;CRC FOR FIRST, IGNORED IN SPI MODE MOVWF SPI_TX CALL SPI_IO ;WAIT FOR RESPONSE CODE 0-8 BYTES MOVLW 0XFF ; MOVWF TEMP ;TIME-OUT...NO CARD? SD_COMLP2 MOVWF SPI_TX CALL SPI_IO BTFSS SPI_RX,7 ;FLAG OF RESPONSE RETURN ;SPI_RX HAS RESPONSE DECFSZ TEMP GOTO SD_COMLP2 RETURN ;ERROR RETURN:TEMP=0 ;--------------------------------------------------------------------------------------------------------------------------- SPI_IO ;MOVWF SPI_TX ;..so W can just be loaded NOP SPILOOP BSF STATUS,5 BTFSS SSPSTAT, BF ;Has data been received (transmit complete)? GOTO SPILOOP BCF STATUS,5 MOVF SSPBUF, W ;DUMMY READ TO EMPTY IT MOVWF SPI_RX MOVF SPI_TX,W MOVWF SSPBUF ;SEND RETURN ;~~~~~~~~~~~~~~~~~~~~~~~SDC WRITE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;~ SAVE RAM INTO SDC CARD, ram is full. Destroys ram addr buffers! ;~ Remember they are in little endian format! SDAD3-0 IS SDCARD ADDRESS ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SDC_WRITE BCF DUMPFLAGS,0 ;RESET DUMPFLAG, HERE NOW BTFSS SSTATUS,CARD ;CARD IN? RETURN MOVF FLASH_COUNT,W BTFSS STATUS,2 ; BSF PORTB,6 ;TURN ON RED LED TO SHOW RECORDING BTFSS STATUS,2 DECF FLASH_COUNT ;ONLY FLASHES 255 TIMES THEN GOES "SILENT" ;UNLESS BUTTON IS TOUCHED (<1 SEC> CLRF SRADMSB ;CLEAR SRAM ADDRESS POINTERS CLRF SRADLSB MOVLW 0X58 ;(COM24) '01XX XXXX',4BYTES ADDRESS,CRC(7),1 CALL SD_COMMAND MOVLW 0XFF MOVWF SPI_TX CALL SPI_IO ;SEND 1 FILL BYTE MOVLW 0XFE ;COM24 SINGLE BLOCK WRITE TOKEN MOVWF SPI_TX CALL SPI_IO SDADLP2 CALL SRAMLOAD ;(in W)GET DATA UNTIL>511 MOVWF SPI_TX CALL SPI_IO INCFSZ SRADLSB GOTO SDADLP2 INCF SRADMSB BTFSS SRADMSB,1 ;512? GOTO SDADLP2 MOVLW 0XFF ;FAKE CRC BYTES AT END MOVWF SPI_TX CALL SPI_IO CALL SPI_IO CLRF SRADMSB ;CLEAR SRAM ADDRESS FOR NEXT CLRF SRADLSB WRR CALL SPI_IO ;GET RESPNSE (1BYTE+) BTFSC SPI_RX,4 GOTO WRR BTFSC SPI_RX,1 ;CHECK RESPONSE BYTE HERE.. GOTO SDC_WRITE ;TRY AGAIN,SHOULD PUT A TIMEOUT HERE! BTFSC SPI_RX,3 GOTO SDC_WRITE SDCW_BUSY ;NEEDED TO DEAL WITH "BUSY" HERE ;MOVLW "." ;CALL READRAMTX MOVLW 0XFF MOVWF SPI_TX CALL SPI_IO MOVF SPI_RX,W XORLW 0XFF ;ALL STILL HIGH? ....THIS ISNT WORKING... BTFSS STATUS,2 ;IS LOW WHEN BUSY....? GOTO SDCW_BUSY INCF SDAD1 ;ADD512 USED ALSO BY WRITE INCFSZ SDAD1 GOTO SDC_WRIX INCFSZ SDAD2 GOTO SDC_WRIX INCF SDAD3 ;SHOULD HAVE A MAX SIZE HERE FFFFFFFF=4GIG SDC_WRIX BTFSC SSTATUS,RECSTOP ;WAS A REC.STOP REQUESTED? GOTO RECDONE RETURN ; ;~~~~~~~~~~~~~~~~~~~~~RECORD DONE~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;CREATE .WAV HEADER AND SAVE "NEXT" BLOCK ADDRESS TO SD CARD SO UNIT ;CAN BE POWERED DOWN, YET STILL DUMP IT'S FILE TO PC RECDONE BCF SSTATUS,RECMODE BCF SSTATUS,RECSTOP ;get SDC 10 00 00 00 into SRAM and modify with new address MAX ;then save back to SDC 10000000. DUMP will get this address and load to MAD0-3 ;send est. minute count [512/80 =6.4 seconds per block , so time=blocks*6.4...or blocks/10*64] ;or just use TICK and return in seconds,mins,hrs CALL SDAD_MAD CALL SDAD_CLR BSF DUMPFLAGS,3 ;SET SDC_READ TO NOT SEND ANY DATA TO USART! CLRF SRADLSB CLRF SRADMSB CALL SDC_READ ;GET FIRST BLOCK into SRAM, TO MODIFY FOR .WAV WAVE_HEADER ;MODIFY SRAM CONTENTS, USE TABLE? CLRF SRADLSB CLRF SRADMSB WAVLP MOVF SRADLSB,W CALL WAV_TABLE MOVWF DATABYTE CALL SRAMSAVE INCF SRADLSB MOVLW .44 XORWF SRADLSB,W BTFSS STATUS,2 ;END OF HEADER? GOTO WAVLP ;* NOW FILL THE ADDRESS (SIZE) PARAMETERS CALL MAD_SDAD ; FIRST .WAV PARAM IS 8 LESS, SECOND IS 24 LESS WAVCN2 ;NOW SUB 8 ;FOR FIRST MOVLW 0X08 SUBWF SDAD0 BTFSS STATUS,0 ;CARRY? *CHECK THIS &&& CALL WAVESUB ;SUBTRACT MOVLW .4 ;WAVHEADR POSITION, NEXT IS 40 MOVWF SRADLSB CALL SDAD_SRAM ; SUB ANOTH 16 = 24 MOVLW 0X10 ;16 SUBWF SDAD0 BTFSS STATUS,0 ;CARRY? *CHECK THIS &&& CALL WAVESUB ;SUBTRACT MOVLW .40 ;WAVHEADR POSITION 40 MOVWF SRADLSB CALL SDAD_SRAM ;END WAVEHEADER FILE LENGTH ENTRY CALL SDAD_CLR CALL SDC_WRITE ;SAVE SRAM BLOCK BACK TO SDC ;NOW BACKUP MAX ADDRESSES TO 10 00 00 00 IN SDC ;*THIS ROUTINE SHOULD BE AT STOP RECORD REALLY.... ;*COULD READ THIS BLOCK FIRST TO GET ANY SETTINGS DATA?? CLRF SRADLSB ;START OF BACKUP BLOCK CLRF SRADMSB CALL MAD_SDAD ;LOAD SDAD'S AGAIN WITH PROPER MAX ADDRESS CALL SDAD_SRAM ;PUT IN SRAM 0-3 LSB FIRST CALL SDAD_CLR BSF SDAD3,4 ;268 MEG ADDRESS(10 00 00 00) FOR MAD0-3 + INFO CALL SDC_WRITE ;**FORGOT TO ADD LOL! ;DONE ADDRESS BACKUP BCF DUMPFLAGS,3 ;REPLY MOVLW .16 ;"READY" CALL MESSAGES return ;~~~~~~~~~~~~~~~~~S-RAM WRITE,READS~~~~~~~~~~~~~~~~~~~~~~~~ ;USE SRADMSB/LSB TO SELECT ADDRESS IN RAM TO READ OR WRITE~ ;"DATBYTE" IS LOADED FOR SAVE, OR LOADED FROM LOAD........~ ;CALLING ROUTINE MUST SET/INC ADDR'S AND DATA(SAVE).......~ ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;NOTES: The only time this will be used is during accumilation of data ;from sensor, then as as load 512 bytes from SDcard.Does there need ;to be a max ADDR?(2bytes) stored? SRAMSAVE BCF PORTD,CS MOVLW B'00000010' ;WRITE BYTE INSTRUCTION MOVWF SRBUF CALL SRAMWRITE MOVF SRADMSB,W ;LOAD ADDRESS TO SRAM MOVWF SRBUF CALL SRAMWRITE MOVF SRADLSB,W MOVWF SRBUF CALL SRAMWRITE MOVF DATABYTE,W ;DATABYTE MAY BE CHANGED?? MOVWF SRBUF CALL SRAMWRITE BSF PORTD,CS RETURN SRAMLOAD BCF PORTD,CS MOVLW B'00000011' ;READ BYTE INSTRUCTION MOVWF SRBUF CALL SRAMWRITE MOVF SRADMSB,W ;LOAD ADDRESS MOVWF SRBUF CALL SRAMWRITE MOVF SRADLSB,W MOVWF SRBUF CALL SRAMWRITE NOP CALL SRAMREAD BSF PORTD,CS ;PUT CS BACK HI MOVF SRBUF,W MOVWF DATABYTE ;DATA FROM SPECIFIED ADDR IN RAM IS NOW HERE RETURN SRAMWRITE ;WRITES A BYTE (IN SRBUF) TO SRAM. ;CS MUST BE HANDLED BY CALLING ROUTINE MOVLW .8 MOVWF TEMP4 ;COUNTDOWN FOR CK SRWLP BTFSS SRBUF,7 GOTO SRW0 BTFSC SRBUF,7 GOTO SRW1 SRWCN NOP ;STABILIZE BSF PORTC,CK NOP NOP NOP RLF SRBUF BCF PORTC,CK DECFSZ TEMP4 GOTO SRWLP RETURN SRW0 NOP NOP BCF PORTC,SI GOTO SRWCN SRW1 BSF PORTC,SI GOTO SRWCN SRAMREAD MOVLW .8 MOVWF TEMP4 ;COUNTDOWN FOR CK SRRLP BSF PORTC,CK RLF SRBUF NOP NOP NOP NOP NOP NOP BTFSS PORTC,SO GOTO SRR0 BTFSC PORTC,SO GOTO SRR1 SRRCN BCF PORTC,CK DECFSZ TEMP4 GOTO SRRLP RETURN SRR0 NOP NOP BCF SRBUF,0 GOTO SRRCN SRR1 BSF SRBUF,0 GOTO SRRCN SDAVERAGE ;FILL IN UBUF2,3,4,5,6,7 TO AVERAGE x4 ;DO 4,5 FIRST,THEN AV 2,3 & 6,7 FROM THOSE ;***LITTLE ENDIAN.IF UBUF LOW>UBUF HI, THEN MATHFLAG,0=1(BOR) BCF MATHFLAGS,0 movf UBUF0,W subwf UBUF8,W MOVWF UBUF4 movf UBUF1,W btfss STATUS,0 incfsz UBUF1,W subwf UBUF9,W ;NUMB TO BE SUB FROM(ITS HIGHER) MOVWF UBUF5 BTFSC STATUS,0 ;SKIP IF WAS NEGATIVE GOTO SDA1 BSF MATHFLAGS,0 ;SET MEANS WAS NEG UBUF9&8 WAS < UBUF1&0 COMF UBUF5 COMF UBUF4 INCFSZ UBUF4 GOTO SDA1 INCF UBUF5 SDA1 BCF STATUS,0 ;HALF THE DIFFERENCE RRF UBUF5 RRF UBUF4 MOVF UBUF5,W ;STORE FOR NEXT AVERAGES MOVWF UBUF11 BCF STATUS,0 RRF UBUF11 ;HALF AGAIN MOVF UBUF4,W MOVWF UBUF10 RRF UBUF10 BTFSS MATHFLAGS,0 ;GOING DOWNWARD WAV GOTO SDA2 ;GOING UPWARD WAV ;ADD TO 8&9 FOR 5&4 ^^ movf UBUF8,W addwf UBUF4 movf UBUF9,W btfsc STATUS,0 incfsz UBUF9,W addwf UBUF5 movf UBUF10,W ;ADD HALFED TO 9&8 FOR 7&6 addwf UBUF8,W MOVWF UBUF6 movf UBUF11,W btfsc STATUS,0 incfsz UBUF11,W addwf UBUF9,W MOVWF UBUF7 ;ADD SAME TO 5&4 FOR 3&2 movf UBUF10,W addwf UBUF4,W MOVWF UBUF2 movf UBUF11,W btfsc STATUS,0 incfsz UBUF11,W addwf UBUF5,W MOVWF UBUF3 GOTO SDA3 SDA2 movf UBUF0,W ;ADD TO 1&0 FOR 5&4 addwf UBUF4 movf UBUF1,W btfsc STATUS,0 incfsz UBUF1,W addwf UBUF5 movf UBUF10,W ;ADD HALFED TO 1&0 FOR 3&2 addwf UBUF0,W MOVWF UBUF2 movf UBUF11,W btfsc STATUS,0 incfsz UBUF11,W addwf UBUF1,W MOVWF UBUF3 ;ADD SAME TO 5&4 FOR 7&6 movf UBUF10,W addwf UBUF4,W MOVWF UBUF6 movf UBUF11,W btfsc STATUS,0 incfsz UBUF11,W addwf UBUF5,W MOVWF UBUF7 SDA3 ;GOTO SDAVERAGE RETURN ;-------------PC COMMANDS------------------------------------------------------- ;PC COMMAND: L "LIVE MODE" -sends a live 2-byte stream off of sensor ;pc COMMAND: l "LIVE MODE STOP" -stops sending raw sensor stream ;PC COMMAND: D "DUMP ALL" -followed by 10 sec. "silence" to start logger ;PC COMMAND: B "DUMP BLOCK#" -512 bytes during record or stby ;PC COMMAND: F "FORMAT SD" -erase SD card,*may wait until FAT incorperated ;PC COMMAND: R "RECORD NOW" -turns off "LIVE MODE" also ;PC COMMAND: X "RECORD STOP" -returns # of samples done ;PC COMMAND: V "Battery Check" -returns ADC value ;PC COMMAND: S "SET SAMPLE SIZE"-"1"=THRU 4510, "0"=DIRECT FROM 555 ;PC COMMAND: M "SET MAX TIME" -in hours(will reset to inf. after a dump) ;PC COMMAND: G "GET DUMP SRAM" -sends 512 bytes from SRAM bottom. ;PC COMMAND: W "WRITE TO SRAM" -following bytes will be saved to ram(test) ;PC COMMAND: C "SAVE TO SD C" -SRAM 512 will be saved to SD card(test) ;PC COMMAND: P "PIC RAM DUMP" -same as dashpic, dumps pic ram ;PC COMMAND: ! "RESET PIC" -resets pic as a power-up ;PC COMMAND: @"DIAG MODE" -puts pic into diagnostics mode, USART send-all ;------------------------------------------------------------------------------- PC_COMMANDS ;****IF HERE THEN RX WAS SENSED IN MAINLOOP**** ;READS NEXT USARTRX [IF WITHIN 2.5 MS] CALL RXBYTE MOVWF TEMP2 XORLW "X" ;RECORD STOP BTFSC STATUS,2 GOTO RECORD_STOP ;SAME AS BUTTON PRESS MOVF TEMP2,W BTFSC STATUS,2 ;CHECK FOR A /0(FROM FLASH) GOTO PCCRET ;IGNORE /0 BTFSC SSTATUS,RECMODE ;IGNORE THE REST IF IN RECORD MODE! GOTO PCCRET MOVF TEMP2,W XORLW "L" ;LIVE MODE SETS PCCOM BIT 0 BTFSC STATUS,2 BSF PCCOM,LIVE ;TURN ON FLAG FOR SEASONG SEND BYTES MOVF TEMP2,W XORLW "l" ;SMALL "L" CANCEL LIVE MODE BTFSC STATUS,2 BCF PCCOM,LIVE MOVF TEMP2,W XORLW "D" ;START DUMP OF SD CARD (AFTER 10SECS) BTFSC STATUS,2 GOTO DUMPALL MOVF TEMP2,W XORLW "B" ;START DUMP OF SD CARD BLOCK BTFSC STATUS,2 GOTO DUMPBLOCK MOVF TEMP2,W XORLW "F" ;START FORMAT OF SDC BTFSC STATUS,2 GOTO SDC_FORMAT MOVF TEMP2,W XORLW "R" ;RECORD NOW BTFSC STATUS,2 GOTO RECORD_START ;SAME AS BUTTON PRESS MOVF TEMP2,W XORLW "V" ;ADC BATTERY CHECK (/2 VOLTAGE AT ADC0) BTFSC STATUS,2 GOTO BATT_CHECK ; MOVF TEMP2,W XORLW "S" ;SET SAMPLE SIZE (WIDTH OF PULSE 4510 OR NOT) BTFSC STATUS,2 GOTO SAMPLE_SIZE MOVF TEMP2,W XORLW "M" ;MAX TIME("0"=OPEN "1"=1HR "2"=2HR "3"=3HR "4"=4HR "5"=8HR ;"6"=12HR "7"=1 DAY "8"=2 DAY "9"=WEEK) STEPPED IN MINUTES BTFSC STATUS,2 GOTO MAX_TIME MOVF TEMP2,W XORLW "G" ;GET DUMP SRAM: DUMP LOWEST 512 BYTES(TEST) BTFSC STATUS,2 GOTO DUMP_SRAM MOVF TEMP2,W XORLW "W" ;WRITE TO SRAM: WRITE BYTES THAT FOLLOW TO SRAM 0-511 BTFSC STATUS,2 GOTO WRITE_SRAM MOVF TEMP2,W XORLW "C" ;CARD WRITE FROM SRAM:FOLLOWED BY ADDR:i.e."C0FDEFE00",LOAD SRAM 1ST BTFSC STATUS,2 GOTO CARD_WRITE MOVF TEMP2,W XORLW "P" ;PIC RAM DUMP (OLD READ RAM ROUTINE FROM DASHPIC(TEST) BTFSC STATUS,2 GOTO PIC_DUMP MOVF TEMP2,W XORLW "!" ;PIC RESET!! BTFSC STATUS,2 GOTO START ;RESET MOVF TEMP2,W XORLW "@" ;DIAGNOSTIC MODE BTFSC STATUS,2 GOTO DIAG_MODE ;DIAG NOP ;IF HERE THEN NO COMMANDS MATCHED GOTO TX_QUESTION_MARK ;TRANSMIT BACK A "?" AND /0 ;-----------RXBYTE-GET A BYTE, TIMEOUT 2.5MS-------------- RXBYTE CLRF TEMP3 URXLP CALL DELAY ;10uS ttl MAX WAIT=2.5MS(timer2) BTFSC PIR1,RCIF GOTO URXFIN BTFSS SSTATUS,RXWAIT ;SET IF COMMAND REQUIRES ADDITONAL ENTRIES DECFSZ TEMP3 GOTO URXLP RETLW .13 ;0 MEANS ERROR OR END... URXFIN MOVF RCREG,W RETURN PCCRET GOTO MAINLOOP ;OR SOMEWHERE IN MAINLOOP.. ;------------------------------------PC COMMANDED ROUTINES---------------------------- ;------------DUMPALL------------------- ;10 SEC DELAY, THEN MOV 512 BLOCK AND ; SEND 512 BYTES. REPEAT UNTIL SIZE PARAMETER IS MET. ;WON'T WORK IN RECORD MODE! USE MAD0-3 FOR ADDRESSES ;( SDAD0-3 NEEDS TO BE PRESERVED IN CASE BAD TX TO PC) ;***PERHAPS BACKUP ADDRESSES TO SDC AFTER A RECORD IS TERMINATED!! DUMPALL ;CALL 12 DELAYS BTFSC SSTATUS,RECMODE GOTO PCCRET ;IN REC MODE, CAN'T DO MOVLW "*" ;A RESPONSE * CALL READRAMTX MOVLW .12 ;12 SECONDS MOVWF TEMP DUMPALLLP1 ;*****This could all be moved to REC_STOP and the loads to dump could be pulled off SDC ;10 00 00 00 where backup will be...try to make read/write this block a separate unit? ;...so the following up until DUMPLP needs to be moved & addr data writ dir. to SDC ;..this way any setup data would remain on the Card indefinitely. ; ;1)Rec-stop: Load SDC 10000000 -->Sram ;2)Update Addresses from Next SDAD0-3, ;3)WRite back to SDC (remember to clrf SDAD1 as it'll have advanced 2) ;4)Dump: Once "D" sent, load SRAM (SDC_READ...remember flags!)with SDC 10000000 ; and load MAD0-3 & UBUF0,1 off it.[send hex'd addr to usart perhaps...] ;5)Continue with dumploop. I fails, even after shutoff,max addresses are still there!" ; Settings such as max time, samp.source., Shutdown Volts, can be saved on SDC. CALL DELAY2 ;USES TIMER0,1,2 DECFSZ TEMP GOTO DUMPALLLP1 CLRF SRADLSB CLRF SRADMSB CALL SDAD_CLR BSF SDAD3,4 ;LAST RECORD MAX ADDRESS IN 10 00 00 00 IN SD CARD BSF DUMPFLAGS,3 ;SET SDC_READ TO NOT SEND ANY DATA TO USART! CALL SDC_READ ; BCF DUMPFLAGS,3 ;READ SRAM 00 - 03 & PUT INTO MAD 0-3 CLRF SRADLSB CLRF SRADMSB CALL SRAM_MAD ;- - - - - INSERT ANY OTHE DATA READ HERE - - - - - - - CALL SDAD_CLR ;CLEAR ALL TO ZERO FOR NEXT ;ADD: - 512 +(SRAM NEXT-1) ;***SET PREFIX OF WAVE. SIZE ETC(44 BYTES) LOAD SDC#0 TO SRAM. MODIFY, SAVE TO sdc ;SET A FLAG( ) TO SKIP THIS PART IF DUMP FAILS DUMPLP ;-------Main Dump Loop------ BSF DUMPFLAGS,2 ;SO USART SENDS RAW DATA CALL SDC_READ ;AUTO-INCS SDAD0,3 MOVF SDAD3,W XORWF MAD3,W BTFSS STATUS,2 ;MAX ADDR MATCH3? GOTO DUMPLP MOVF SDAD2,W XORWF MAD2,W BTFSS STATUS,2 ;MAX ADDR MATCH2? GOTO DUMPLP MOVF SDAD1,W XORWF MAD1,W BTFSS STATUS,2 ;MAX ADDR MATCH1? GOTO DUMPLP ;------------end Main Dump Loop------------------ DUMPCN2 ; CALL SDAD_CLR ;CLEAR ALL TO ZERO CLRF DUMPFLAGS BSF SSTATUS,RXWAIT ;...WILL WAIT FOR ANY RS232 SIGNAL TO FINISH CALL RXBYTE BCF SSTATUS,RXWAIT GOTO PC_J ;RE-INITIALIZES SPI & SDC ; GOTO PCCRET SDAD_CLR CLRF SDAD1 CLRF SDAD2 CLRF SDAD3 CLRF SDAD0 RETURN WAVESUB DECFSZ SDAD1 RETURN DECFSZ SDAD2 RETURN DECF SDAD3 RETURN SDAD_SRAM ;SAVE SEQUENCIALLY SDAD0-3 INTO SRAM ADDR SRADLSB/MSB MOVF SDAD0,W MOVWF DATABYTE CALL SRAMSAVE INCF SRADLSB MOVF SDAD1,W MOVWF DATABYTE CALL SRAMSAVE INCF SRADLSB MOVF SDAD2,W MOVWF DATABYTE CALL SRAMSAVE INCF SRADLSB MOVF SDAD3,W MOVWF DATABYTE CALL SRAMSAVE INCF SRADLSB RETURN SRAM_MAD ;LOAD SRAM DATA STARTING AT SRADLSB, TO MAD 0-3 CALL SRAMLOAD MOVF DATABYTE,W MOVWF MAD0 INCF SRADLSB CALL SRAMLOAD MOVF DATABYTE,W MOVWF MAD1 INCF SRADLSB CALL SRAMLOAD MOVF DATABYTE,W MOVWF MAD2 ;LOAD PRESENT SDC READ ADDRESSES TO COMPARE TO INCF SRADLSB CALL SRAMLOAD MOVF DATABYTE,W MOVWF MAD3 ;LOAD PRESENT SDC READ ADDRESSES TO COMPARE TO INCF SRADLSB RETURN MAD_SDAD MOVF MAD1,W ;PUT MAX ADDRESSES BACK INTO SDAD'S & ADD SRAM AD'S MOVWF SDAD1 MOVF MAD2,W MOVWF SDAD2 MOVF MAD3,W MOVWF SDAD3 MOVF MAD0,W MOVWF SDAD0 ;FOR ADDRESS BACKUP RETURN SDAD_MAD ;PUT SDAD'S TO MAD'S MOVF SDAD1,W ;PUT MAX ADDRESSES BACK INTO SDAD'S & ADD SRAM AD'S MOVWF MAD1 MOVF SDAD2,W MOVWF MAD2 MOVF SDAD3,W MOVWF MAD3 MOVF SDAD0,W MOVWF MAD0 ;FOR ADDRESS BACKUP RETURN DUMPBLOCK ;ONLY 1 BLOCK, NOT DURING RECORD ;*********INCOMPLETE!********* ;IN HYPERTERM, THE FULL 8 DIGIT ADDR MUST BE ENTERED ;: SDC ADDRESS: ;"B0FDEFE00" WILL READ 512 BYTE BLOCK 0FDEFE00 BTFSC SSTATUS,RECMODE GOTO PCCRET ;IN REC MODE, CAN'T DO MOVLW 0X30 ;**GET ADDRESS MOVWF TEMP ;FOR HEX2BIN POINTERS, AUTO INCREMENTS BSF SSTATUS,RXWAIT ;SET TO CAUSE ENDLESS DELAY (UNTIL EXIT) DUMPBLKLP1 MOVWF 0X34 ;FOR HEX GET START MOVWF TEMP2 CALL RXBYTE MOVWF UBUF4 CALL RXBYTE MOVWF UBUF5 CALL HEX2BIN2 BTFSS TEMP,2 ;=0X34? DONE GOTO DUMPBLKLP1 BCF SSTATUS,RXWAIT NOP ;SDC ADDRESS NOW IN UBUF0,1,2,3 (msb first) ;--CALLS: ;--ROUTINE TO GET BLOCK (ADDR UBUF0-3) FROM SDC-->SRAM ;--ROUTINE TO SEND BLOCK FROM SRAM VIA USART ;-- GOTO PCCRET CARD_WRITE ;CARD WRITE FROM SRAM:ADDR+,LOAD SRAM 1ST! TEST DIAGNOSTICS! CALL SDC_WRITE GOTO PCCRET SDC_FORMAT ;FORMAT SDCARD, COPY'S SRAM TO BLOCKS, SO MUST CLR SRAM FIRST ;[ USE W TO CLEAR TO ALL ZERO'S ;* * * DOESN'T ERASE "SETTINGS AREA", ONLY LOWER 268 MEGS MOVLW .48 ;"-sure?" CALL MESSAGES BSF SSTATUS,RETFLAG CALL WRITE_SRAM ;CLEAR SRAM TO 00's BCF SSTATUS,RETFLAG CALL SDAD_CLR ;START AT BOTTOM CALL RXBYTE ;CLEAN OUT IN CASE OF LINE FEED FORMATLP CALL RXBYTE XORLW .13 ;13=TIMEOUT-IF ANYTHING OUT THAN NO RX THEN STOP BTFSS STATUS,2 GOTO FORMAT_DONE MOVLW "." ;SEND A DOT FOR EVERY 512BYTE BLOCK CALL READRAMTX CALL SDC_WRITE ;AUTO INCREMENTS 512 BTFSS SDAD3,4 GOTO FORMATLP FORMAT_DONE GOTO PCCRET BATT_CHECK ;*done tested in SIM ;JUST A READ FROM THE ADC RETURNED AS 2 HEX CHARS ;----ADCi ROUTINE------MAY UPDATE TO AVERAGE MOVLW B'10000001' ;BITS 5-3 SEL PIN USING /32 MOVWF ADCON0 bsf ADCON0,2 NOP ADCWAIT BTFSC ADCON0,2 ;WAIT FOR ADCi DONE(JUST IN CASE) GOTO ADCWAIT MOVF ADRES,W ;GET ADC DATA, DOESN'T WORK IN SIM... TX1BYT CALL BIN2HEX ;RETURNS HEX$ DATA IN TIMER0,1(1 IS MSB) MOVF TIMER1,W CALL READRAMTX ;USE RAM TX ROUTINE TO SEND MOVF TIMER0,W CALL READRAMTX CLRW CALL READRAMTX GOTO PCCRET ;----END ADCi ROUTINE---- SAMPLE_SIZE ;SET SAMPLE SIZE.x10: PORT , IS DIRECT FROM 555, PORT , IS THRU 4510 MAX_TIME CALL SDC_READ ;TEMP USE! GOTO PCCRET DUMP_SRAM CLRF SRADLSB CLRF SRADMSB DSRLP1 CALL SRAMLOAD ;GET SRAM BYTE MOVF DATABYTE,W CALL TX1BYTR ;SEND INCFSZ SRADLSB GOTO DSRLP1 INCF SRADMSB BTFSS SRADMSB,1 ;512? GOTO DSRLP1 BTFSC SSTATUS,RETFLAG ;RETURN TO FORMAT ROUTINE RETURN GOTO PCCRET WRITE_SRAM ;WRITES FOLLOWING BYTES TO SRAM, IF NO DATA THEN ;WRITES ALL 00 TO SRAM INSTEAD. GOES TO DUMP_SRAM TO READ CLRF SRADLSB CLRF SRADMSB BSF SSTATUS,RXWAIT ;SET TO CAUSE ENDLESS DELAY UNTIL WSRLP1 BTFSS SSTATUS,RXWAIT ;IF CLR NO MORE ENTRIES GOTO WSF0 CALL RXBYTE MOVWF TEMP3 XORLW .13 ;CARRAGE RETRUN BTFSC STATUS,2 ;TEST FOR NO MORE RX, SO WRITE "00'S" GOTO WSF0 MOVF TEMP3,W GOTO WSDAT WSF0 MOVLW 0X00 BCF SSTATUS,RXWAIT GOTO WSDAT2 WSDAT MOVWF TIMER2 CALL HEX2BIN ;CONVERT TO MS-NIBBLE SWAPF TIMER2,W MOVWF SENSCNTMSB ;TEMP USE CALL RXBYTE MOVWF TIMER2 CALL HEX2BIN ;CONVERT TO NIBBLE MOVF TIMER2,W IORWF SENSCNTMSB,W ;COMBINE TO SAVE ASCII TO BIN VALUE WSDAT2 MOVWF DATABYTE CALL SRAMSAVE INCFSZ SRADLSB GOTO WSRLP1 INCF SRADMSB BTFSS SRADMSB,1 ;512? GOTO WSRLP1 BCF SSTATUS,RXWAIT GOTO DUMP_SRAM DIAG_MODE BSF SSTATUS,DIAG ;ONCE SET ALWAYS SET UNTIL RESET MOVLW "*" CALL READRAMTX GOTO PCCRET TX_QUESTION_MARK ;SEND "?" MOVLW "?" CALL READRAMTX GOTO PCCRET PIC_DUMP CALL READRAM GOTO PCCRET LIVETX MOVF SENSCNTMSB,W ;GET MSB OF SEASONG CALL BIN2HEX ;RETURNS HEX$ DATA IN TIMER0,1(1 IS MSB) MOVF TIMER1,W CALL READRAMTX ;USE RAM TX ROUTINE TO SEND MOVF TIMER0,W CALL READRAMTX MOVF SENSCNTLSB,W ;GET LSB OF SEASONG TX1BYTR ;CAN RE-USE THIS FOR SINGLE BYTE TX WITH RETURN CALL BIN2HEX ;RETURNS HEX$ DATA IN TIMER0,1(1 IS MSB) MOVF TIMER1,W CALL READRAMTX ;USE RAM TX ROUTINE TO SEND MOVF TIMER0,W CALL READRAMTX CLRW CALL READRAMTX RETURN ;-----------------converters----------------------------------------------- ;-----------MUL10 MULTIPLY X 10--- MUL10 ;VAL IN TIMER2, RETURNS IN TIMER0 TIMER2 NOT MODIFIED MOVF TIMER2,W MOVWF TIMER0 SWAPF TIMER0 BCF STATUS,0 RRF TIMER0 RLF TIMER2,W ADDWF TIMER0 RETURN ;~~~~~~~~~~~~~~~~~~~DECIMAL(2DIG)TO BIN CONVERTOR~~~~~~~~~ DECIMAL2 ;CONVERTS 2BYTE DECIMAL TO BINARY ;W IS POINTER TO FIRST (MSB) DIGIT.TIMER0, TIMER2 & TEMP2 USED MOVWF FSR DEC2B MOVF INDF,W ;START here if FSR already set by last CALL HERE MOVWF TIMER2 CALL HEX2BIN ;USES TIMER2 CALL MUL10 ;USES TIMER2 MOVF TIMER0,W MOVWF TEMP2 INCF FSR MOVF INDF,W MOVWF TIMER2 CALL HEX2BIN ;USES TIMER2 MOVF TIMER2,W ADDWF TEMP2 ;~~~~~~~~~RETURNS IN TEMP2 INCF FSR ;FOR NEXT READ IF THERE IS RETURN ;~~~~~~~~~~~~~~~~~~HEX2BIN2 BYTES~~~~~~~~~~~~~~~~~~~~~~~ HEX2BIN2 ;CONVERTS 2 HEX BYTES STARTING AT INTO BINARY BYTE SENT ;TO LOCATION . *HEX2BIN USES TIMER2*...INCS TEMP&TEMP2 MOVF TEMP2,W MOVWF FSR MOVF INDF,W MOVWF TIMER2 MOVF TEMP,W MOVWF FSR CALL HEX2BIN SWAPF TIMER2,W MOVWF INDF INCF TEMP2 MOVF TEMP2,W MOVWF FSR MOVF INDF,W MOVWF TIMER2 CALL HEX2BIN MOVF TEMP,W MOVWF FSR MOVF TIMER2,W ADDWF INDF INCF TEMP2 INCF TEMP RETURN HEX2BIN ;RESULTS RETURNED IN TIMER2 (0-F) MOVLW .58 SUBWF TIMER2,W MOVLW .7 BTFSC STATUS,0 SUBWF TIMER2 MOVLW .48 SUBWF TIMER2 RETURN ;~~~~~~~~~~~~~~~~~~~~~~USARTRX~~~~~~~~~~~~~~~~~~~~USARTRX USARTRX ;//// NO LONGER USEFUL... MOVF RCREG,W ;GETS byte MOVWF TIMER2 ;now holds data ANDLW 0XFF ;DUMMY FOR STATUS ZERO check (ignore) BTFSC STATUS,2 GOTO USARTRX_EXIT MOVF TIMER2,W MOVLW 0X5A MOVWF UBUFPOINT USARTRXLP ;GET THE REST UBUF1++ MOVF UBUFPOINT,W MOVWF FSR ;CALL URX_MORE ;GET ANOTHER MOVWF INDF INCF UBUFPOINT MOVLW 0X5F XORWF UBUFPOINT,W ;IF=61 THEN UBUFFS FULL // ;??don't forget error flag in USART!! BTFSC STATUS,2 GOTO USRXXX ;This is for tx w/no /0 MOVF INDF,W ;DUMMY:CHECK SAME UBUF FOR /0 BTFSS STATUS,2 GOTO USARTRXLP ;UBUF'S LOADED, READY TO EXECUTE A PEDISTAL COMMAND: ;NEXT CALLS COMMANDS BELOW USRXXX RETURN ;DATA IN 5A,5B,5C,5D,5E ;-------------------------- USART_ERROR ;**MAY HAVE ERRORED, DEAL WITH USART DISABLED FLAG here.... ; PERHAPS SET A FLAG TO SEND ERR MESSAGE TO PED?? USARTRX_EXIT ;- GOTO USARTRX_RET ;----------------------------------delays---------------------------------- DELAY7uS MOVLW .7 ;2CYC HERE, 2 BACK+2 INI +3*7+1=7Us MOVWF TIMER0 DELAY7uSLP DECFSZ TIMER0 GOTO DELAY7uSLP NOP RETURN DELAY MOVLW 0X12 ;ABOUT 10uS DELAYcust MOVWF TIMER2 DLLP DECFSZ TIMER2 GOTO DLLP RETURN DELAY2 MOVLW 0X00 ;ABOUT 1 SECOND MOVWF TIMER1 CLRF TIMER0 DELAY2LP CALL DELAY DECFSZ TIMER0 GOTO DELAY2LP DECFSZ TIMER1 GOTO DELAY2LP RETURN DELAY5MS MOVLW .124 MOVWF TIMER0 MOVLW .20 MOVWF TIMER1 DELAY5MSLP NOP DECFSZ TIMER0 GOTO DELAY5MSLP DECFSZ TIMER1 GOTO DELAY5MSLP RETURN ;--------------------TEST ROUTINES------------------------------------------- ;(1) READ RAM ;on-chip raed of all of ram (converted to hex)INITIATED BY a rx of "P" ;* Note: this interferes with normal sequence timing as waits for the TXREG to be ;free, READRAM ;MOVLW .7 ;MOVWF PCLATH ;JUST TO BE SURE CLRF TEMP MOVLW "@" CALL READRAMTX CALL READRAMTX MOVLW "r" ;SMALL R CALL READRAMTX READRAMLP MOVF TEMP,W MOVWF FSR MOVF INDF,W CALL BIN2HEX MOVF TIMER1,W CALL READRAMTX MOVF TIMER0,W CALL READRAMTX MOVLW "-" CALL READRAMTX INCFSZ TEMP GOTO READRAMLP MOVLW 0X00 ;/0 CALL READRAMTX RETURN READRAMTX ; THIS COULD BE USED ELSEWHERE BELOW 0800! BTFSC SSTATUS,DIAG ;IN DIAG MODE, SEND ALL GOTO RRDIAG BTFSC SSTATUS,RECMODE ;IF IN RECMODE, NO output UNLESS DIAG MODE RETURN RRDIAG BTFSS PIR1,TXIF GOTO READRAMTX MOVWF TXREG RETURN ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ORG 0700 ;~~~~~~~~~TABLES~~~~~~~~~~~~~~~PCLATH= 7~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;+ANY OTHER COMPUTED GOTO'S.(ADDWF PCL'S) BIN2HEX ;DATA IN "W", RETURNS DATA IN TIMER0 & TIMER 1 MOVWF TIMER0 SWAPF TIMER0,W ANDLW 0X0F ;MSNIBBLE FIRST CALL BIN2HEXT MOVWF TIMER1 ;ASCII HEX MSN MOVF TIMER0,W ANDLW 0X0F CALL BIN2HEXT MOVWF TIMER0 GOTO B2HTR ;RETURN BIN2HEX8 CALL BIN2HEXT B2HTR ;BSF PCLATH,3 RETURN BIN2HEXT ADDWF PCL ;CONVERT 4 BIT BINARY TO HEX ASCII. 0 - 15 = "0" TO "F" RETLW .48 ;"0" RETLW .49 RETLW .50 RETLW .51 RETLW .52 RETLW .53 RETLW .54 RETLW .55 RETLW .56 RETLW .57 ;"9" RETLW .65 ;"A" RETLW .66 RETLW .67 RETLW .68 RETLW .69 RETLW .70 ;"F" BIN2FLAGS8 CALL BIN2FLAGS ; BSF PCLATH,3 RETURN BIN2FLAGS ;0-7 = 00000001 TO 10000000 ;FOR DUMP FLAGS ETC addwf PCL RETLW B'00000001' ;0 RETLW B'00000010' RETLW B'00000100' RETLW B'00001000' RETLW B'00010000' RETLW B'00100000' RETLW B'01000000' RETLW B'10000000' ;7 WAV_TABLE ;WAVE HEADER: dont for get they are all LITTLE ENDIAN ADDWF PCL RETLW "R" RETLW "I" RETLW "F" RETLW "F" RETLW 0XFF ;-8 lsb RETLW 0XFF RETLW 0X00 RETLW 0X00 ;msb RETLW "W" RETLW "A" RETLW "V" RETLW "E" RETLW "f" RETLW "m" RETLW "t" RETLW " " RETLW 0X10 ;CHECK THIS RETLW 0X00 RETLW 0X00 RETLW 0X00 RETLW 0X01 RETLW 0X00 RETLW 0X01 ;MONO RETLW 0X00 RETLW 0X80 ;CHANGED THIS TO 48KBPS RETLW 0XBB RETLW 0X00 RETLW 0X00 RETLW 0X00 ;HERE TOO RETLW 0X77 RETLW 0X01 RETLW 0X00 RETLW 0X02 ;CHECK BLK ALIGN RETLW 0X00 ;PG2 RETLW 0X10 RETLW 0X00 RETLW "d" RETLW "a" RETLW "t" RETLW "a" RETLW 0XFF ;DATA CHUNK SIZE (EVEN UP?) lsb RETLW 0XFF RETLW 0X00 RETLW 0X00 ; msb ;data block follows MESSAGES ;ALL 8 BYTE - USES TIMER0,1 ;O.K. = 0 / REC ON=8 / READY=16 / CARDin =24 / NoCARD = 32 /Sea-Song =40 -Sure? MOVWF TIMER0 MOVLW .8 MOVWF TIMER1 MESSLP MOVF TIMER0,W CALL MESSTAB CALL READRAMTX INCF TIMER0 DECFSZ TIMER1 GOTO MESSLP RETURN MESSTAB ADDWF PCL RETLW .13 RETLW .10 RETLW "O" RETLW "." RETLW "K" RETLW "." RETLW .13 RETLW .10 RETLW .13 RETLW .10 RETLW "R" RETLW "E" RETLW "C" RETLW " " RETLW "O" RETLW "N" RETLW "-" RETLW "R" RETLW "E" RETLW "A" RETLW "D" RETLW "Y" RETLW .13 RETLW .10 RETLW "C" RETLW "A" RETLW "R" RETLW "D" RETLW "i" RETLW "n" RETLW .13 RETLW .10 RETLW "N" RETLW "o" RETLW "C" RETLW "A" RETLW "R" RETLW "D" RETLW .13 RETLW .10 RETLW "S" RETLW "e" RETLW "a" RETLW "-" RETLW "S" RETLW "o" RETLW "n" RETLW "g" RETLW .10 RETLW .13 RETLW "S" RETLW "u" RETLW "r" RETLW "e" RETLW "?" RETLW " " ORG 0800 ;NOP ; END