Home > Article Index > X10 Speech Recognition Interface Article - Page 6

X10 Speech Recognition Interface

Download Hex Code for X10 PICBasic Pro Program (7K)


PICBASIC PRO PROGRAM

' 07/06/2009
' Copyright Images Scientific Instruments and J.Iovine
' PICBasic Pro X-10 program

ADCON1 = 7 'Make port a & port e lines digital
TRISA = 9 'set port a to output except pins RA0 and RA3 comparator inputs
TRISB = 255 'set port b to input
TRISC = 2 'set port c to output except PortC.1
TRISD = 15 'set port d (d.0 to d.3 input all other lines to output)
CMCON = 1 'Setup register to use just C1 comparator

include "modedefs.bas"

'Variables
hc var byte 'Housecode
num VAR BYTE
wd VAR BYTE
ld VAR BYTE
flg0 VAR BIT 'Word Spoken/ Recognize ?
' flags to hold on-off status
cfg1 var bit :cfg2 var bit
cfg3 var bit :cfg4 var bit
cfg5 var bit :cfg6 var bit
cfg7 var bit :cfg8 var bit
cfg9 var bit :cfg10 var bit
cfg11 var bit :cfg12 var bit
cfg13 var bit :cfg14 var bit
cfg15 var bit :cfg16 var bit

PORTE = 0
PORTC = 0
PORTD = 0

'Define comparator C1 output
C1OUT VAR CMCON.6


'read option register Housecodes A - P
hc = PORTD & %00001111
'test mode
'hc = 0

'See if a word has been spoken
start:
IF C1OUT Then out2 'Word Spoken?
PORTC.3 = 1
GoTo start
out2:
PORTC.3 = 0
GoSub rdnum 'Read number from SR-07
IF flg0 = 0 Then start 'Word Recognized?
GoSub latchout
GoTo start


'Read number from SR-07
rdnum:
Pause 350 'Pause .35 sec for word number to propagate through circuit
num = PORTB 'read word number
ld = num & %00001111 'low BCD nybble
wd = num >>4 'shift high nybble right 4 put reseults in wd
wd = wd & %00000111 'isolate lower 3 bits
IF wd > 4 Then error 'Error code 55,66 or 77
IF wd = 1 Then high_num 'Is it a high number (above 10?)
if wd > 1 then error 'Recognized word number is above 16
num = num & %00001111 'isolate BCD lower nybble
flg0 = 1 'Set flg word recognized
Return

'Check high number is 10 - 16
high_num:
IF ld = 0 Then num = 10
IF ld = 1 Then num = 11
IF ld = 2 Then num = 12
IF ld = 3 Then num = 13
IF ld = 4 Then num = 14
IF ld = 5 Then num = 15
IF ld = 6 Then num = 16
flg0 = 1 'Set flg word recognized
Return


'Latched Outputs
latchout:
hc = PORTD & %00001111
IF num = 1 Then checkcode1
IF num = 2 Then checkcode2
IF num = 3 Then checkcode3
IF num = 4 Then checkcode4
IF num = 5 Then checkcode5
IF num = 6 Then checkcode6
IF num = 7 Then checkcode7
IF num = 8 Then checkcode8
IF num = 9 Then checkcode9
IF num = 10 Then checkcode10
IF num = 11 Then checkcode11
IF num = 12 Then checkcode12
IF num = 13 Then checkcode13
IF num = 14 Then checkcode14
IF num = 15 Then checkcode15
IF num = 16 Then checkcode16

GoTo error

checkcode1:
IF cfg1 = 1 Then
cfg1 = 0
xout portc.2, portc.1,[hc\0,hc\unitOff]
Else
cfg1 = 1
xout portc.2, portc.1,[hc\0,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode2:
IF cfg2 = 1 Then
cfg2 = 0
xout portc.2, portc.1,[hc\1,hc\unitOff]
Else
cfg2 = 1
xout portc.2, portc.1,[hc\1,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode3:
IF cfg3 = 1 Then
cfg3 = 0
xout portc.2, portc.1,[hc\2,hc\unitOff]
Else
cfg3 = 1
xout portc.2, portc.1,[hc\2,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode4:
IF cfg4 = 1 Then
cfg4 = 0
xout portc.2, portc.1,[hc\3,hc\unitOff]
Else
cfg4 = 1
xout portc.2, portc.1,[hc\3,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode5:
IF cfg5 = 1 Then
cfg5 = 0
xout portc.2, portc.1,[hc\4,hc\unitOff]
Else
cfg5 = 1
xout portc.2, portc.1,[hc\4,hc\unitOn]
EndIF
flg0 = 0
return

checkcode6:
IF cfg6 = 1 Then
cfg6 = 0
xout portc.2, portc.1,[hc\5,hc\unitOff]
Else
cfg6 = 1
xout portc.2, portc.1,[hc\5,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode7:
IF cfg7 = 1 Then
cfg7 = 0
xout portc.2, portc.1,[hc\6,hc\unitOff]
Else
cfg7 = 1
xout portc.2, portc.1,[hc\6,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode8:
IF cfg8 = 1 Then
cfg8 = 0
xout portc.2, portc.1,[hc\7,hc\unitOff]
Else
cfg8 = 1
xout portc.2, portc.1,[hc\7,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode9:
IF cfg9 = 1 Then
cfg9 = 0
xout portc.2, portc.1,[hc\8,hc\unitOff]
Else
cfg9 = 1
xout portc.2, portc.1,[hc\8,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode10:
IF cfg10 = 1 Then
cfg10 = 0
xout portc.2, portc.1,[hc\9,hc\unitOff]
Else
cfg10 = 1
xout portc.2, portc.1,[hc\9,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode11:
IF cfg11 = 1 Then
cfg11 = 0
xout portc.2, portc.1,[hc\10,hc\unitOff]
Else
cfg11 = 1
xout portc.2, portc.1,[hc\10,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode12:
IF cfg12 = 1 Then
cfg12 = 0
xout portc.2, portc.1,[hc\11,hc\unitOff]
Else
cfg12 = 1
xout portc.2, portc.1,[hc\11,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode13:
IF cfg13 = 1 Then
cfg13 = 0
xout portc.2, portc.1,[hc\12,hc\unitOff]
Else
cfg13 = 1
xout portc.2, portc.1,[hc\12,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode14:
IF cfg14 = 1 Then
cfg14 = 0
xout portc.2, portc.1,[hc\13,hc\unitOff]
Else
cfg14 = 1
xout portc.2, portc.1,[hc\13,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode15:
IF cfg15 = 1 Then
cfg15 = 0
xout portc.2, portc.1,[hc\14,hc\unitOff]
Else
cfg14 = 1
xout portc.2, portc.1,[hc\14,hc\unitOn]
EndIF
flg0 = 0
Return

checkcode16:
IF cfg16 = 1 Then
cfg16 = 0
xout portc.2, portc.1,[hc\15,hc\unitOff]
Else
cfg16 = 1
xout portc.2, portc.1,[hc\15,hc\unitOn]
EndIF
flg0 = 0
Return


error:
flg0 = 0
Return

 

 

 

Previous Page    Article Index