Hey There-
I do have it working - came up late last night and my solution looks pretty much like Enrik's suggestion. Code follows for others to use or learn:
I really like the bit manipulation and the use of the tables - a lot.Code:'------------------------------------------------------------------------------------------ 'Variable List i var byte 'Loop counter var Table var byte[16] BANKA 'Array input is the value of the 4 inputs; 0-15 from the binary weight tflag var table.3 'timer flag TableIn var byte 'Entry into array from inputs temp var byte 'Temp var to use as a debounce '--------------------------------------------------------------------------------------------- '######################################################################################################################### '# We are going to setup this Pig! '######################################################################################################################### Initialize: unsecure=0 'Esures the relay is not active lock=0 'Ensures lock valve is not active unlock=0 'Ensures unlock valve is not active i=0 Table[0]=6 Table[1]=2 Table[2]=6 Table[3]=2 Table[4]=6 Table[5]=6 Table[6]=6 Table[7]=6 Table[8]=5 ' Table[9]=0 Table[10]=5 ' Table[11]=0 Table[12]=4 Table[13]=6 Table[14]=6 Table[15]=6 goto Startmain 'Steps around the subroutines '######################################################################################################################### '# Subroutines '######################################################################################################################### Wait2sec: pause 2000 return get_input: TableIn=PORTA & %00110011 'Selects the correct input pins TableIn=(TableIn & %00000011) + (TableIn & %00110000)>>2 'Selects A0,A1 then selects A4,A5 moves to A2, A3 and adds to A0,A1 'Therefore, the array entry is (Command - DPI - Bolt - Deadlck) 'Remembering that Command and DPI are ACTIVE LOW 'When we get a command to open it is LOW, when door is closed=LOW 'Bolt and Deadlck posotion sensors are ACTIVE HIGH return '######################################################################################################################### '# Startmain - where the MAGIC starts! '######################################################################################################################### Startmain: 'Main wait loop gosub get_input 'Get inputs temp=TableIn pause 100 gosub get_input if TableIn <> temp then goto startmain 'Var and temp var did not match so must have been noise, go back if TableIn = 9 then if tflag=1 then Main1X unlock=0 unsecure=0 lock=1 pause 2000 lock=0 tflag=1 Main1X: lock=0 unlock=0 unsecure=0 goto startmain endif PORTC=Table[TableIn] 'Sets the port output to the table byte goto startmain 'Start all over
That's the good news, the not so good news is I have discovered 2 conditions which I hadn't counted;
1. Coming out of the timed function, IF DPI goes from 0 to a 1, I just need to change state of the relay.
IF after staying at 1, DPI goes back to a 0, then start the timing sequence again....... Dang.
2. If after the timed section, if DPI=0 AND deadlock goes from a 1 to a 0 just change the relay state.
Now that I have the truth table, understand the bit manipulation, got the array to work - now I find a 'transitional' state.
Mickey Mouse logic in its day was pretty involved - almost as interesting as the relay-logic trees!
Summation, thanks for the assist, I learned quite a number of 'finer' parts of PBP and registers.
Now I am setting sites on how to know where I am, and watch for certain transitions......
-Steve




Bookmarks