Hi tenaja,
I'll try your suggestion...
Thanks
jessey
Hi tenaja,
I'll try your suggestion...
Thanks
jessey
Hello tenaja,
I tried your suggestion and still no go. Can you or anyone else here think of any other avenues that I could explore to get it working?
Thanks
jessey
Code:Enter_Access_Code: select_dtmf = 1 ' Enable the data output from the MT8870 Pause 1 ' Pause 1 mS to let data settle dtmf_digit = (PORTB >> 4) ' Read the top nibble of PORTB for DTMF data ' Use LOOKUP to change the DTMF data to an ASCII character LookUp dtmf_digit, ["_1234567890*#ABCD"], dtmf_digit dtmf_wait2: IF dtmf_ready Then dtmf_wait2 ' Loop here until DTMF signal stops select_dtmf = 0 ' Disable the MT8870 data output ' access code is 2457316 Select Case dtmf_digit ' Take action based on the dtmf digit '6th # in the correct sequence --- 1 = A Case "1" ' sets A var to 1 if 1 is pressed and If-Then below is correct.. 'IF (A=0) AND (B=1) AND (C=1) AND (D=1) AND (E=1) AND (F=0) AND (G=1) THEN A=1 IF (A=0) then if (B=1) then if (C=1) then if (D=1) then if (E=1) then if (F=0) then if (G=1) THEN A=1 endif endif endif endif endif endif ELSE A=2 ' 2681 ENDIF ' 2639 ' 52 '1st # in the correct sequence --- 2 = B Case "2" ' sets B var to 1 if 2 is pressed and If-Then below is correct.. 'IF (A=0) AND (B=0) AND (C=0) AND (D=0) AND (E=0) AND (F=0) AND (G=0) THEN B=1 IF (A=0) then if (B=0) then if (C=0) then if (D=0) then if (E=0) then if (F=0) then if (G=0) THEN B=1 endif endif endif endif endif endif ELSE B=2 ENDIF '5th # in the correct sequence --- 3 = C Case "3" ' sets C var to 1 if 3 is pressed and If-Then below is correct.. 'IF (A=0) AND (B=1) AND (C=0) AND (D=1) AND (E=1) AND (F=0) AND (G=1) THEN C=1 IF (A=0) then if (B=1) then if (C=0) then if (D=1) then if (E=1) then if (F=0) then if (G=1) THEN C=1 endif endif endif endif endif endif ELSE C=2 ENDIF '2nd # in the correct sequence --- 4 = D Case "4" ' sets D var to 1 if 4 is pressed and If-Then below is correct.. 'IF (A=0) AND (B=1) AND (C=0) AND (D=0) AND (E=0) AND (F=0) AND (G=0) THEN D=1 IF (A=0) then if (B=1) then if (C=0) then if (D=0) then if (E=0) then if (F=0) then if (G=0) THEN D=1 endif endif endif endif endif endif ELSE D=2 ENDIF '3rd # in the correct sequence --- 5 = E Case "5" ' sets E var to 1 if 5 is pressed and If-Then below is correct.. 'IF (A=0) AND (B=1) AND (C=0) AND (D=1) AND (E=0) AND (F=0) AND (G=0) THEN E=1 IF (A=0) then if (B=1) then if (C=0) then if (D=1) then if (E=0) then if (F=0) then if (G=0) THEN E=1 endif endif endif endif endif endif ELSE E=2 ENDIF '7th # in the correct sequence --- 6 = F Case "6" ' sets F var to 1 if 6 is pressed and If-Then below is correct.. 'IF (A=1) AND (B=1) AND (C=1) AND (D=1) AND (E=1) AND (F=0) AND (G=1) THEN F=1 IF (A=1) then if (B=1) then if (C=1) then if (D=1) then if (E=1) then if (F=0) then if (G=1) THEN F=1 endif endif endif endif endif endif ELSE F=2 ENDIF '4th # in the correct sequence --- 7 = G Case "7" ' sets G var to 1 if 6 is pressed and If-Then below is correct.. 'IF (A=0) AND (B=1) AND (C=0) AND (D=1) AND (E=1) AND (F=0) AND (G=0) THEN G=1 IF (A=0) then if (B=1) then if (C=0) then if (D=1) then if (E=1) then if (F=0) then if (G=0) THEN G=1 endif endif endif endif endif endif ELSE G=2 ENDIF Case "8" A=2 ' If the #8 key is pressed then it's a no go Case "9" A=2 ' If the #9 key is pressed then it's a no go Case "0" A=2 ' If the #0 key is pressed then it's a no go End Select 'IF (A=1) AND (B=1) AND (C=1) AND (D=1) AND (E=1) AND (F=1) AND (G=1) THEN IF (A=1) then if (B=1) then if (C=1) then if (D=1) then if (E=1) then if (F=1) then if (G=1) THEN access_code = is_verified FreqOut DTMF_out, 500, 800 ' Play 3 tones to confirm to the caller that PAUSE 100 ' the correct access code has been entered FreqOut DTMF_out, 500, 800 PAUSE 100 FreqOut DTMF_out, 500, 800 endif endif endif endif endif endif ENDIF IF k = 0 THEN listen
Change this type of code to
to this type of code throughout the case structures.Code:Case "1" ' sets A var to 1 if 1 is pressed and If-Then below is correct.. IF (A=0) AND (B=1) AND (C=1) AND (D=1) AND (E=1) AND (F=0) AND (G=1) THEN A=1 '1st # in the correct sequence --- 2 = B Case "2" ' sets B var to 1 if 2 is pressed and If-Then below is correct.. IF (A=0) AND (B=0) AND (C=0) AND (D=0) AND (E=0) AND (F=0) AND (G=0) THEN B=1
Code:Case "1" ' sets A var to 1 if 1 is pressed and If-Then below is correct.. IF (A=0) AND (B=1) AND (C=1) AND (D=1) AND (E=1) AND (F=0) AND (G=1) THEN A=1 endif '1st # in the correct sequence --- 2 = B Case "2" ' sets B var to 1 if 2 is pressed and If-Then below is correct.. IF (A=0) AND (B=0) AND (C=0) AND (D=0) AND (E=0) AND (F=0) AND (G=0) THEN B=1 endif
Two things to try... first, don't convert your dtmf_digit value to a string (ascii) value. (And if you must, then use a second variable to put the result in.) If you did this just to make the code more readable, then use constants in your CASE's. This, at the least, will allow you to eliminate a code-hungry command.
Second, if those vars are all bits (and it does look like it) then put them all in one byte, and compare byte values. So, instead of seven compares, you only have one that's efficient and easy to read ... and you can use constants for them, too...
Code:Case 1 'note it's a byte, not a string if bByte_Values = %00111101 then bByte_Values.6 = 1 endif Case cdtmf_value_2 'note the constant. if bByte_Values = 0 then 'can replace BV compare value with constant like cBV_dtmf_2 bByte_Values.1 = 1 endif 'etc...
Hiya Jessey.
Combination recognition?
Seems like I've been down this road before.
Well, ... I'm not going to try to fix what you have.
I'd suggest highlighting the entire area, and press Delete.
Much easier ways to go about it.
Although the text of this post only partially applies to your case,
I think the code example is more like what you want.
https://www.picbasic.co.uk/forum/showthread.php?p=32566
There are several other examples in that thread too.
HTH,
DT
Happy New Year everyone!
Thanks so much tenaja, Jerson & Darrel
Hi Darrel,
Your code sure looks good, I can't wait to try it out. I'm at a friends place visiting for a while so I can't try it out until I get home but it'll be the first thing on my to do list.....
Thanks Again
jessey
Code:combocount VAR BYTE Enter_Access_Code: select_dtmf = 1 ' Enable the data output from the MT8870 Pause 1 ' Pause 1 mS to let data settle dtmf_digit = (PORTB >> 4) ' Read the top nibble of PORTB for DTMF data ' Use LOOKUP to change the DTMF data to an ASCII character LookUp dtmf_digit, ["_1234567890*#ABCD"], dtmf_digit dtmf_wait2: IF dtmf_ready Then dtmf_wait2 ' Loop here until DTMF signal stops select_dtmf = 0 ' Disable the MT8870 data output ' access code is 2457316 IF (combocount = 0) AND (dtmf_digit = 2) THEN GoodKey IF (combocount = 1) AND (dtmf_digit = 4) THEN GoodKey IF (combocount = 2) AND (dtmf_digit = 5) THEN GoodKey IF (combocount = 3) AND (dtmf_digit = 7) THEN GoodKey IF (combocount = 4) AND (dtmf_digit = 3) THEN GoodKey IF (combocount = 5) AND (dtmf_digit = 1) THEN GoodKey IF (combocount = 6) AND (dtmf_digit = 6) THEN GoodKey combocount = 0 'invalid keypress IF k = 0 THEN listen GoodKey: combocount = combocount + 1 IF combocount = 6 THEN access_code = is_verified FreqOut DTMF_out, 500, 800 ' Play 3 tones to confirm to the caller that PAUSE 100 ' the correct access code has been entered FreqOut DTMF_out, 500, 800 PAUSE 100 FreqOut DTMF_out, 500, 800 ENDIF IF k = 0 THEN listen
There ya go.
With no PIC or compiler in front of you .... Pretty good!
Just a couple comments for when you get home.
Make sure the program can't accidently "Fall" into the GoodKey routine.
If it does fall-in, it was a bad key, so you definately don't want to run the GoodKey routine.
And the example has seven digits.
IF combocount = 7 THEN have a
Happy New Year!
DT
Bookmarks