I don't know if this is what you had in mind,
but it could be a possibility for your Timeout wishes.
With the extra features of the 12F635, you should be able to to create a WDT based timeout for the SERIN or other command(s).
Starting with the WDT turned off, and DEFINE NO_CLRWDT 1
And this un-tested code ... (don't have a 12F635)Prior to starting a SERIN command, it saves an address to the Timeout1 Label and starts the WDT.Code:DEFINE OSC 4 ' OSCCON defaults to 4MHz on reset DEFINE NO_CLRWDT 1 ' stop kicking the DOG ASM CFG = _INTRC_OSC_NOCLKOUT ; Oscillator CFG=CFG& _WDT_OFF ; Watch Dog Timer <-- Very Important CFG=CFG& _PWRTE_ON ; Power-on Timer CFG=CFG& _MCLRE_OFF ; Master Clear Reset CFG=CFG& _BOD_OFF ; Brown-out Detect CFG=CFG& _IESO_OFF ; Internal External Switchover CFG=CFG& _FCMEN_ON ; Fail-Safe Clock Monitor CFG=CFG& _WUREN_OFF ; Wake-up and Reset CFG=CFG& _CP_OFF ; Code Protect CFG=CFG& _CPD_OFF ; EEPROM Data Protect __CONFIG CFG ENDASM INCLUDE "modedefs.bas" '----[Pin Definations]------------------------------------------------------ LED1 VAR GPIO.0 LED2 VAR GPIO.1 ToTx VAR GPIO.2 ToRx VAR GPIO.3 Monitor VAR GPIO.4 ;----[Variables/Aliases]---------------------------------------------------- TOaddr VAR WORD BANK0 SYSTEM code VAR BYTE WDTO VAR STATUS.4 ; WatchDog Timer Timeout bit SWDTEN VAR WDTCON.0 ; Software WDT Enable BAUD CON N2400 '----[Initialize]----------------------------------------------------------- Init: IF !WDTO THEN ; If the WDT timed out TOGGLE LED2 ASM movf TOaddr + 1, W ; Goto Timeout Address movwf PCLATH movf TOaddr, W movwf PCL ENDASM ELSE ; Power-on, or other Reset CMCON0 = 7 GPIO=0 OPTION_REG = %00000111 WDA.4=1 : WPUDA.4=1 WDTCON = %00010110 ; 1:65536, WDT off ENDIF ;----[Main Program Loop]---------------------------------------------------- Main: TOGGLE LED1 ASM movlw LOW(_TimeOut1) ; Set the Timeout jump Address movwf TOaddr movlw HIGH(_TimeOut1) movwf TOaddr + 1 CLRWDT ; kick the DOG first ENDASM SWDTEN = 1 ' enable the WDT Serin ToRx, BAUD,["pp3"],code SWDTEN = 0 ' disable the WDT SELECT CASE code ' CHECK VALUES FOR THE RECEIVED CODE CASE 0 ' Null code, no action CASE 1 ; do code 1 CASE ELSE ' Unknown Code ; don't know the code. Ignore or Warn END SELECT GOTO Main TimeOut1: ' Timeout occured SWDTEN = 0 ' disable the WTD ; notify user of timeout ; or do timeout cleanup GOTO Main
If the WDT times out during the SERIN command, the processor will RESET.
At the top of the program, it checks to see if the reset was from power-up, or the WDT. If it was from the WDT, it was a Timeout, so it jumps to the timeout label that was saved prior to starting the SERIN command.
All previous Stack levels are discarded. So the label that it jumps to MUST be in the Main loop.
Timeout period can be adjusted by changing the WDTCON prescaler.
Food for thought while drinking Champaigne.
Happy New Year!




Bookmarks