' ' Story Teller, Model 7 Gallery Controller ' Tom Jennings ' ' $Id: gal.bas,v 1.3 2003/04/25 23:47:42 tomj Exp $ ' ' ' Attached to the story teller buss, this controls the performance by using ' CTS to pause the datastream. It powers up idle, lamp blinking, and CTS ' asserted false, stopping the performance. When the switch is pressed, ' CTS is released, and the performance starts. After a predetermined period ' (about 3 minutes) this code waits for the end of the current record ' (EOT, or a NUL indicating inter-record filler) then asserts CTS false ' to stop further performance. ' ' Note that the hardware contains a NE555 timer. It is no longer used and ' is held reset. ' ' NOTE: The switch is push on/push off -- not momentary, hence ' the juggling. It was chosen for it's physical characteristics. ' (In fact it's easier to use than a momentary -- no missed ' presses, and it remembers it's own last state!) ' ' 25 Apr 2003 ' Serial code brought up to snuff. ' ' 27 Nov 2002 ' Rewrote simplified code to eliminate the hardware ' timer and hangs waiting for idle. ' ' mru 21 Sep 99 ' Changed so that CTS is dropped after every character read. ' I really need to find a UART chip! ' 'mru 20 Sep 99 ' Added DISCHARGE delay after every reset, since the huge ' timing cap takes ~50 mS to discharge. ' new 17 Sep 1999 symbol swlast= bit8 ' last state of the switch symbol c= b3 ' returned serial character symbol serflag= b4 ' char-ready flag for serinp() symbol timer= w3 ' per-state cycle timer symbol ltimer= w4 ' state 2 local loop counter ' PICSTIC I/O pin assignments symbol RXD= 7 ' serial data in pin # symbol CTSpin= pin6 ' CTS pin symbol CTS= 6 ' CTS pin symbol SWpin= pin5 ' bit front panel switch symbol LAMPpin= pin4 ' lamp in switch symbol LAMP= 4 ' lamp in switch ' These are no longer used. symbol TRIG= 3 ' 555 trigger (0=trig) symbol TOUTpin= pin2 ' 555 timer output symbol RESET= 1 ' 555 timer reset (0=reset) symbol RESETpin= pin1 symbol DISCHARGE= 150 ' 555 large C discharge time ' (was measured at 50mS) symbol TINCR1= 1500 ' IDLE: lamp blink time, symbol TINCR2= 3 ' RUNNING: run time, minutes, symbol SPEED= N2400 symbol NUL= 0 ' paper tape NUL, symbol SOH= 1 ' start of header symbol STX= 2 ' start of text (data) symbol ETX= 3 ' end of text (data) symbol EOT= 4 ' end of transmission, symbol ENQ= 5 ' 76543210 dirs= %01011010 ' set directions, pins= %00001010 ' set initial states, RESETpin= 1 ' disable 555, call serini ' init the serial junk, ' ' STATE 1: IDLE. Turn timer off, flash the lamp, ' wait for switch press. ' state1: LAMPpin= 0 ' lamp is off, swlast= SWpin ' seed "current switch" s1a: timer= TINCR1 ' lamp-blink timer, s1b: if SWpin <> swlast then state2 ' go start when switch pressed, timer= timer - 1 ' else wait, if timer <> 0 then s1b ' and blink the lamp, toggle LAMP ' goto s1a ' ' STATE 2: RUNNING. Release CTS, start timing. ' state2: LAMPpin= 0 ' lamp off, swlast= SWpin ' remember current switch, timer= TINCR2 ' start (outer loop) timer, CTSpin= 1 ' release CTS, s2a: ltimer= 599 ' 1 minute inner loop (minus o'head!) s2b: if SWpin <> swlast then state2 ' retrigger if switch pressed, pause 100 ' 10th sec/600th minute, ltimer = ltimer - 1 if ltimer <> 0 then s2b timer = timer - 1 : if timer <> 0 then s2a ' ' STATE 3: WAIT FOR END OF RECORD. Look for an EOT or ' a NUL indicating the current record has ended. This ' will wait forever, however the PTR spews NULs when ' on and idle or in error. ' state3: call serinp ' look for a character, if serflag = 0 then state3 ' if c = EOT then state1 ' end of record, if c = NUL then state1 ' end of record, LAMPpin= 1 ' DEBUG goto state3 ' wait. ASM ; ; Poll for a serial character, returns serflag=1 and character in C ; and CTS 0 if one is present (eg. start bit visible on serial line). ; _serinp clrf _serflag ; set serflag false, bsf portB, _CTS ; assert CTS, btfss portB, _RXD ; if start bit not present, goto done ; exit now. call serin@W ; read character, bcf portb, _CTS ; deassert CTS, movwf _c ; store W in C, bsf _serflag, 0 ; set serflag goto done ; Ready the args for the later serin() call. _serini bcf portB, _CTS ; deassert CTS, movlw _RXD ; Rx pin number, call BP@Pin movlw _SPEED ; port speed, movwf GOP ; (local to ass'y code?) clrf _serflag ; goto done ENDASM end