No AND/OR command! How-To decode DTMF board ???

No AND/OR command! How-To decode DTMF board ???

Postby RBSe » Wed Mar 13, 2013 5:29 pm

Hi Daniel,

I just noticed that there is no AND or OR command in Control BASIC.
That is an important part of a conditional branch in the BASIC language.
I wrote this code for the ARMweb to create a <send$> of DTMF tones decoded.

Code: Select all
' Read DTMF tones and create a SEND$ for processing on the ARMweb controller

'===== SETUP =================

INPUT (9) ' Set pin 9 as an input FOR DTMF DETECTED (data valid)
INPUT (10) ' Q4 nibble output
INPUT (11) ' Q3   "      "
INPUT (12) ' Q2   "      "
INPUT (13) ' Q1   "      "

'===== MAIN LOOP =============

WHILE 1 ' Main program loop...

'Goto label..."DTMFDetected:"
DTMFDetected:

IF IN(9) AND 1 THEN ' wait for DTMF valid "1" to decode digits Q4 Q3 Q2 Q1

    IF IN(10)=0 AND IN(11)=0 AND IN(12)=0 AND IN(13)<>0 THEN DIGIT$="1"
    IF IN(10)=0 AND IN(11)=0 AND IN(12)<>0 AND IN(13)=0 THEN DIGIT$="2"
    IF IN(10)=0 AND IN(11)=0 AND IN(12)<>0 AND IN(13)<>0 THEN DIGIT$="3"
    IF IN(10)=0 AND IN(11)<>0 AND IN(12)=0 AND IN(13)=0 THEN DIGIT$="4"
    IF IN(10)=0 AND IN(11)<>0 AND IN(12)=0 AND IN(13)<>0 THEN DIGIT$="5"
    IF IN(10)=0 AND IN(11)<>0 AND IN(12)<>0 AND IN(13)=0 THEN DIGIT$="6"
    IF IN(10)=0 AND IN(11)<>0 AND IN(12)<>0 AND IN(13)<>0 THEN DIGIT$="7"
    IF IN(10)<>0 AND IN(11)=0 AND IN(12)=0 AND IN(13)=0 THEN DIGIT$="8"
    IF IN(10)<>0 AND IN(11)=0 AND IN(12)=0 AND IN(13)<>0 THEN DIGIT$="9"
    IF IN(10)<>0 AND IN(11)=0 AND IN(12)<>0 AND IN(13)=0 THEN DIGIT$="0"
    IF IN(10)<>0 AND IN(11)=0 AND IN(12)<>0 AND IN(13)<>0 THEN DIGIT$="*"
    IF IN(10)<>0 AND IN(11)<>0 AND IN(12)=0 AND IN(13)=0 THEN DIGIT$="#"
    IF IN(10)<>0 AND IN(11)<>0 AND IN(12)=0 AND IN(13)<>0 THEN DIGIT$="A"
    IF IN(10)<>0 AND IN(11)<>0 AND IN(12)<>0 AND IN(13)=0 THEN DIGIT$="B"
    IF IN(10)<>0 AND IN(11)<>0 AND IN(12)<>0 AND IN(13)<>0 THEN DIGIT$="C"
    IF IN(10)=0 AND IN(11)=0 AND IN(12)=0 AND IN(13)=0 THEN DIGIT$="D"

    WHILE (IN(9) AND 1) 'wait for data valid release
    LOOP

    START = TIMER                  ' start timer
    WHILE (TIMER-START < 3000000)  ' wait for 3 seconds
        IF IN(9) AND 1 THEN EXIT   ' if new valid data then exit loop
    LOOP

    IF TIMER-START < 3000000 THEN  ' if valid data before 3 seconds, process...
        WORD$ = WORD$ + DIGIT$     ' add digit to word and...
        GOTO DTMFDetected          ' go back to label "DTMFDetected:" above and get new digit
    ENDIF

    WORD$ = WORD$ + DIGIT$         ' add digit to word after timeout...
    SEND$ = WORD$                  ' copy word to send string...
    WORD$ = ""                     ' clear word string...

    'Send "SEND$" word data to PC...

    '...(put code here)...

ENDIF

LOOP ' end of program, loop back to top



How would you write this in Control BASIC ???

I have another 5-bit RF remote 4-ch. button input to the controller.
So there are 10-bits in a row I want to examine for processing.
Thats 5-bits for the DTMF board and 5-bits for the 4-ch. remote keys.
The 5th bit on each is VT(data valid).
The other 4-bits are a nibble for the DTMF board.

Your help on this is greatly appreciated Daniel.

Robert
.
Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.

Clifford Stoll
User avatar
RBSe
 
Posts: 33
Joined: Wed Mar 06, 2013 7:42 pm
Location: Eureka, California

Re: No AND/OR command! How-To decode DTMF board ???

Postby Daniel » Thu Mar 14, 2013 10:25 am

Hi Robert

I just noticed that there is no AND or OR command in Control BASIC.


See page 32, page 45, page 44 in the UNTIL section and a few other places.

In Control-BASIC the IF statement must end with ENDIF and the rest of the line after THEN can not contain anything other than comments. It is a feature, not a bug.
The code shown below needs small changes to work

Code: Select all
IF IN(9) AND 1 THEN ' wait for DTMF valid "1" to decode digits Q4 Q3 Q2 Q1

    IF IN(10)=0 AND IN(11)=0 AND IN(12)=0 AND IN(13)<>0 THEN DIGIT$="1"
WHILE (IN(9) AND 1) 'wait for data valid release
LOOP


Code: Select all
IF IND(9) = 1 THEN
    ' wait for DTMF valid "1" to decode digits Q4 Q3 Q2 Q1
    IF IND(10)=0 AND IND(11)=0 AND IND(12)=0 AND IND(13)=1 THEN
       DIGIT$="1"
    ENDIF
ENDIF
WHILE (IND(9) = 1)
    'wait for data valid release
WEND


In Control-BASIC pin I/O must specify what you are trying to accomplish by using IND for reading the digital value of the pin or INADC for reading the analog to digital converter associated with the pin. This is a feature to make programs self-documenting.

I hope this helps.

Daniel
Daniel
 
Posts: 91
Joined: Tue Nov 13, 2012 2:10 pm

Re: No AND/OR command! How-To decode DTMF board ???

Postby RBSe » Thu Mar 14, 2013 12:36 pm

Thanks Daniel,

That helps a great deal. :D
I was thrown off by AND/OR not being in the command list.
The sample code explains IF/THEN very well.

Robert
.
Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.

Clifford Stoll
User avatar
RBSe
 
Posts: 33
Joined: Wed Mar 06, 2013 7:42 pm
Location: Eureka, California


Return to EzSBC1

Who is online

Users browsing this forum: No registered users and 0 guests

cron