{{ Quench. Remote Control Program 3-19-08 3-15-08, last working program for both ends. }} CON _CLKMODE = XTAL1 + PLL16X _XINFREQ = 5_000_000 VAR Long rxStr_stack[20],RD_stack[20] Long Recieved_Data_Stack[20], LS1_Stack[20] Byte datain[20], datain_2[20], Recieved_Data_Array[20] Byte TValue_1, TValue_2, TValue_3,rxStr_array[20],RD_array[20] Byte Lock_ID 'Note: Always declare LONG's WORD's & BYTES in this order. OBJ data : "FullDuplexSerial" data_LCD: "FullDuplexSerial" PUB Main Lock_ID:=locknew dira[4..6]~ 'pins 4,5 & 6 are inputs. dira[16]~~ dira[19]~~ dira[23]~~ 'Output Pins on my Prop board that currently using to simulate cognew(rxStr(9,@rxStr_array),@rxStr_stack) 'Start new Cog to monitor input from the Keypad. 'it would be a good idea to load this AFTER you start the serial cogs cognew(Read_Limit_Switchs,@LS1_Stack) 'Starts new Cog to read Limit Switch's. data.Stop 'not needed, the driver does this data.start(1,0,%0010,9600) 'Set up Serial Port for the Tranceiver. data_LCD.Stop 'not needed, the driver does this data_LCD.start(3,2,0,19200) 'Set up Serial Port for the LCD. LCD_Setup 'Set up initial Start-up screen for the LCD. Recieved_Data(9,@RD_Array) 'Cog "0" is running in a loop looking for incoming data via the 'Tranceiver. PUB LCD_Setup 'Set up serial protocall and Baud rate for LCD 'data.start(3,2,0,19200) repeat until not lockset(Lock_ID) data_LCD.tx(254) data_LCD.tx(69) 'Clear Display buffer. data_LCD.tx(254) data_LCD.tx(88) 'Clear LCD and goto home position. Note: 'LCD is a serial (4 by 20) LCD by Matrix 'Orbital sold by Parallax, set up for TTL 'interfacing. data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(1) data_LCD.tx(1) 'Have the LCD cursor goto location 'collume-1 Row-2 data_LCD.tx(254) data_LCD.tx(83) 'Turn blinking cursor on. data_LCD.str(string("Quench. Station 3/4")) data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(1) data_LCD.tx(2) data_LCD.str(string("T_1:")) data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(9) data_LCD.tx(2) data_LCD.str(string("Status")) data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(1) data_LCD.tx(3) data_LCD.str(string("T_2:")) data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(9) data_LCD.tx(3) data_LCD.str(string("Status")) data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(1) data_LCD.tx(4) data_LCD.str(string("T_3:")) data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(9) data_LCD.tx(4) data_LCD.str(string("Status")) data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(5) data_LCD.tx(2) lockclr(Lock_ID) PUB RxStr(Num_of_Chars,strPtr) | char,index 'strPtr holds the "16 bit location" of the rxStr_array. index:= 0 'Set Array pointer to location "0" repeat repeat until not lockset(Lock_ID) char := data_LCD.rx 'Get input from the Keypad. case index 'The following takes care of incrementing the LCD cursor 'depending on how many bytes have been received. 0: data_LCD.tx(254) data_LCD.tx(84) 1..3: data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(Num_of_Chars+5-1) data_LCD.tx(2) 4..6: data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(Num_of_Chars+5-4) data_LCD.tx(3) 7..9: data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(Num_of_Chars+5-7) data_LCD.tx(4) '----------------------------------------------------------------------- 'The following takes care of the conversion from the Keypad and 'translates it to a decimal equivelent number that shows on the LCD. if char == (88) char := 1 data_LCD.dec(char) if char == (83) char := 2 data_LCD.dec(char) if char == (78) char := 3 data_LCD.dec(char) if char == (87) char := 4 data_LCD.dec(char) if char == (82) char := 5 data_LCD.dec(char) if char == (77) char := 6 data_LCD.dec(char) if char == (86) char := 7 data_LCD.dec(char) if char == (81) char := 8 data_LCD.dec(char) if char == (76) char := 9 data_LCD.dec(char) if char == (80) char := 0 data_LCD.dec(char) if char == (73) 'char := "A" data_LCD.tx(char) data_LCD.tx(254) data_LCD.tx(88) if char == (72) 'char := "B" data_LCD.tx(char) data_LCD.tx(254) data_LCD.tx(88) if char == (71) 'char := "C" data_LCD.tx(char) data_LCD.tx(254) data_LCD.tx(88) if char == (70) data_LCD.tx(254) data_LCD.tx(88) lockclr(Lock_ID) byte[strPtr][index] := char 'Write char to the "rxStr" array. index++ 'increment array position if index == Num_of_Chars+1 'need the '+1' because of where we increment index 'Check to see if "9" bytes have been received via the Keypad. Handle_Numbers(strPtr) 'Set TValue_1 to 1st 3 digits. 'Set TValue_2 to 2nd 3 digits. 'Set TValue_3 to 3rd 3 digits. repeat until not lockset(Lock_ID) Print_Status_To_LCD(strPtr) 'Display numbers on LCD that were entered via the Keypad. Transmit_Timer_values(strPtr) 'Transmit timer values entered by the Keypad to the remote Prop. data.rxflush 'Flush the Transmitters receive buffer. data_LCD.rxflush 'Flush the LCD's receive buffer. data_LCD.tx(254) 'Set LCD cursor back to start point. data_LCD.tx(71) 'This shouldn't be necessary because we set the position for every character data_LCD.tx(5) data_LCD.tx(2) lockclr(Lock_ID) index:= 0 PUB Handle_Numbers(numPtr) TValue_1 := byte[numPtr][0]*100+byte[numPtr][1]*10+byte[numPtr][2] TValue_2 := byte[numPtr][3]*100+byte[numPtr][4]*10+byte[numPtr][5] TValue_3 := byte[numPtr][6]*100+byte[numPtr][7]*10+byte[numPtr][8] 'This should probably use a lock 'Assign Math computed value to both local and Global varible 'for the first 3 digit number. PUB Print_Status_to_LCD(statusPtr)|index 'This method takes care of printing the number transmitted from the 'Keypad to the LCD. repeat index from 0 to 8 data_LCD.tx(254) data_LCD.tx(71) data_LCD.tx(index//3+18) 'x position data_LCD.tx(index/3+2) 'y position data_LCD.dec(byte[statusPtr][index])'number PUB Transmit_Timer_values(dataPtr)|index 'This method is receiving the address of the rxStr array. repeat index from 0 to 8 data.dec(byte[dataPtr][index]) 'Transmit Global Timer Varibles to the remote Prop. Pub Recieved_Data(Num_of_nums, datains) | rxbyte, index 'This method is receiving the address of the "RD_Array" as an parameter. index:= 0 'Set index pointer back to "0". repeat rxbyte := data.rx if (rxbyte => 48) AND (rxbyte =< 57) rxbyte := rxbyte-48 if rxbyte == (58) rxbyte := 0 '---------------------------------- byte[datains][index] := rxbyte index++ if index == Num_of_nums+1 'If we have received "9" bytes from the Tranceiver Execute 'the indented code. Handle_Numbers(datains) 'Do Math and save the result in TValue_1, TValue_2 & TValue_3. repeat until not lockset(Lock_ID) Print_Status_To_LCD(datains) 'This method will print the status of the RD_Array to the LCD. data_LCD.rxflush lockclr(Lock_ID) 'Flush Serial Port buffers. data.rxflush bytefill(datains,0,9) index:= 0 'Reset Array pointer to location "0". PUB Output(Seconds,Pin) repeat while Seconds > 0 'Repeat until Count_4 = "0". outa[Pin]:= 1 'Turn on output "16". waitcnt(80_000_000 + cnt) 'Wait "1" second. data.dec(Seconds) 'Transmit the current dec.value of 'TValue_1 to the remote Prop. Seconds-- 'Decrement Count_4, & Loop until 'Count_4 = "0". outa[Pin]:=0 'Turn output "16" off. PUB Read_Limit_Switchs|Temp_4,Temp_5,Temp_6 dira[4]~ dira[5]~ dira[6]~ dira[16]~~ 'Pins 16,19 & 23 are outputs. dira[19]~~ dira[23]~~ 'Note: Because this Method is running in 'it's own Cog "Inputs & Outputs" have to 'be defined again here. repeat 'Running in a constant loop via seperate Cog. Temp_4 := ina[4] 'Which are bits 2, 1 & 0 of the input register. Temp_5 := ina[5] Temp_6 := ina[6] if Temp_4==1 'If limit switch "1" is made, goto "Output" 4 method. Output(TValue_1,16) if Temp_5==1 'If limit switch "1" is made, goto "Output" 5 method. Output(TValue_2,19) if Temp_6==1 'If limit switch "1" is made, goto "Output" 6 method. Output(TValue_3,23)