Ok guys, I've replicated the functionality of the original 8 pin chip, here's the code - any thoughts?
This is why there's pin fiddling on BUTTONA and BUTTONB
Attachment 2617
Thanks some more 
Code:
' Configure the FUSE options for the compiler
@ device pic16F628A, hs_osc, wdt_off, pwrt_on, lvp_off, protect_off, bod_on, cpd_off, pwrt_off, mclr_off
' Running a 20Mhz clock
DEFINE OSC 20
DEFINE PULSIN_MAX 3000
CMCON = 7
VRCON = 0
ALL_DIGITAL
' Setup the USART
DEFINE HSER_RCSTA 90h ' Receive register to receiver enabled
DEFINE HSER_TXSTA 20h ' Transmit register to transmitter enabled
DEFINE HSER_BAUD 19200 ' Set baud rate
' Alias our pins
BEEP VAR PORTA.0 ' Buzzer
RFIN VAR PORTA.1 ' Remote input
RELAY1 VAR PORTB.4 ' Relay 1 output
RELAY2 VAR PORTB.5 ' Relay 2 output
BUTTONA VAR PORTB.6 ' Primary panel button input
BUTTONB VAR PORTB.7 ' Secondary panel button input
' Set the pin directions
INPUT RFIN
INPUT BUTTONA
INPUT BUTTONB
OUTPUT BEEP
OUTPUT RELAY1
OUTPUT RELAY2
' Configure the output pins as low
LOW BEEP
LOW RELAY1
LOW RELAY2
' Turn on weak pull-ups - IMPORTANT: After making relays and beepers low...
OPTION_REG.7 = 0
' Set us up some variables
PBITS VAR BYTE[24] ' The bits we've read
RAW VAR WORD ' The raw pulsin value
ADDRESS VAR WORD ' Storage for the address
DBYTE VAR BYTE ' Storage for the data
LOOPADDRESS VAR WORD ' Second loop storage of first loop addres
LOOPDBYTE VAR BYTE ' Second loop storage of first loop data byte
X VAR BYTE ' Loop/TMP var
Y VAR BYTE ' Loop/TMP var
STATE VAR BYTE ' Current state of the device
' Constants
STATE_STOPPED CON 0 ' Screen is stopped
STATE_GOING_UP CON 1 ' Screen is going up
STATE_GOING_DOWN CON 2 ' Screen is going down
' Default state
STATE = STATE_STOPPED
' Reset all the primary RF variables
TOP:
ADDRESS = 0 : RAW = 0 : DBYTE = 0
' This is the real main - almost all the looping comes back here
MAIN:
' Set both buttons for input
INPUT BUTTONA
INPUT BUTTONB
' Check to see if the individual buttons are toggled
IF NOT BUTTONA THEN GOSUB subDown
IF NOT BUTTONB Then GOSUB subUp
' Fiddle with the inputs to see if the middle button is pushed
LOW BUTTONB
X = BUTTONA ' If it's LOW then there's a good chance the middle button is down
HIGH BUTTONB
INPUT BUTTONB
LOW BUTTONA
Y = BUTTONB ' If it's LOW then there's a good chance the middle button is down
HIGH BUTTONA
INPUT BUTTONB
INPUT BUTTONA
IF NOT Y AND NOT X THEN GOSUB subStop ' Both register as LOW then the middle button is down!
' Look for one huge low pulse
PULSIN RFIN, 0, RAW
' 2350 is about mean average
IF RAW < 2340 OR RAW > 2360 THEN MAIN
' Read 16 address bits and 8 data bits
FOR X = 0 TO 23
PULSIN RFIN, 0, RAW
' Check the pulse parameters
IF RAW < 30 OR RAW > 240 THEN MAIN
PBITS[x] = NCD RAW
NEXT X
' Gather the address
ADDRESS = 65535 ' Maxmimum known ID
FOR X = 0 to 15
IF PBITS[x] > 7 THEN ADDRESS.0[X] = 0
NEXT X
' Gather the data
DBYTE = 255 ' Maximum known data value
Y=0
FOR X = 16 TO 23
IF PBITS[X] > 7 THEN DBYTE.0[Y] = 0
Y = Y + 1
NEXT X
' If we've done a loop...
IF ADDRESS == LOOPADDRESS AND DBYTE == LOOPDBYTE THEN
SELECT CASE DBYTE
CASE 3
GOSUB subUp
CASE 12
GOSUB subStop
CASE 192
GOSUB subDown
END SELECT
LOOPDBYTE = 0
LOOPADDRESS = 0
ELSE
' Start a loop
LOOPDBYTE = DBYTE
LOOPADDRESS = ADDRESS
ENDIF
GOTO TOP
END
subUp:
IF STATE != STATE_GOING_UP THEN
HIGH BEEP ' Start making noise
HSEROUT ["UP",10,13] ' DEBUG
LOW RELAY1 ' Make sure the down relay is off (Don't know what happens otherwise, don't want to know!)
PAUSEUS 65355 ' Wait a bit
HIGH RELAY2 ' Turn the up relay on
LOW BEEP ' STFU :)
STATE = STATE_GOING_UP
ENDIF
RETURN
subStop:
IF STATE != STATE_STOPPED THEN
HIGH BEEP ' Start making noise
HSEROUT ["STOP", 10, 13] ' DEBUG
LOW RELAY1 ' Turn off the down relay
LOW RELAY2 ' Turn off the up relay
PAUSEUS 65355 ' Wait a bit
LOW BEEP ' STFU :)
STATE = STATE_STOPPED
ENDIF
RETURN
subDown:
IF STATE != STATE_GOING_DOWN THEN
HIGH BEEP ' Start making noise
HSEROUT ["DOWN",10,13] ' DEBUG
LOW RELAY2 ' Make sure the up relay is off (Don't know what happens otherwise, don't want to know!)
PAUSEUS 65355 ' Wait a bit
HIGH RELAY1 ' Turn the down relay on
LOW BEEP ' STFU :)
STATE = STATE_GOING_DOWN
ENDIF
RETURN
Bookmarks