OK! I think I have my permanent solution. Since I had no problems with the first setup I did with this project where I was using physically attached buttons instead of serial commands to control the unit, I am adding a second PIC, whose only job in life is to sit at a serin command pause and await commands. Upon receiving a command, it will simply set a pin high for about 100ms, simulating a button press. Proof of concept already works... Just have two small snags... (and a large one too, but one step at a time lol)
1. I am trying to send via serial just one character. Capital A-F, depending on what combo of buttons is pressed by the user. It's not going thru. The BT is linked. The link seems good. When I hold a button down, it causes the serin pause to release, causing my debugging LED to flash. However, no command is processed. I'm sure it's a format problem or something, but I have tried 9 ways to sunday and I just can't seem to spot what I'm doing wrong. Also, if I shut down the master BT and log my laptop terminal into the dish PIC, sending A-F from the terminal works perfectly and it responds as expected.
2. Only buttons 3 and 4 work. Buttons 1 and 2 do not cause the LED to flash on the receiving end. I assume I'm missing something again about analog/digital, but this pic is very basic and has no ADC, and for the life of me I cannot figure out what I am missing. I have read thru every register in the datasheet, and I'm just not snapping to what it is...
Here is the code for the handheld device:
Code:
'****************************************************************
'* Name : Wireless Handheld Device
'* Author : John Moore
'* CHIP : PIC16F628A
'* Date : May 28, 2014
'* Version : 1.0
'* Notes : This pic will eventually have 4 physical buttons and an LCD
'* : as well as a BT device. Right now I just need it to send the
'* ; serial commands, as I am monitoring the feedback with a terminal.
'****************************************************************
#CONFIG
__config 10000111110000
#ENDCONFIG
button1 var PORTA.2
button2 var PORTA.3
button3 var PORTA.4
button4 var PORTB.3
TRISA.2 = 1
TRISA.3 = 1
TRISA.4 = 1
TRISB.3 = 1
cereal var byte
TX var PORTB.2
TRISB.2 = 0
START:
if button1 = 1 then cereal = "A"
if button2 = 1 then cereal = "B"
if button3 = 1 then cereal = "C"
if button4 = 1 then cereal = "D"
if (button2 = 1) and (button3 = 1) then cereal = "E"
if (button1 = 1) and (button4 = 1) then cereal = "F"
if cereal <> "X" then serout TX, 2, [cereal]
pause 100
cereal = "X"
GOTO START
Here is the code for the PIC16F628A that is receiving the commands and "pressing buttons":
Code:
'****************************************************************
'* Name : On-Board Communication PIC
'* Author : John Moore
'* CHIP : PIC16F628A
'* Date : May 28, 2014
'* Version : 1.0
'* Notes : This pic will never be more complicated than this. It's only
'* : purpose in life is to get characters and push buttons.
'****************************************************************
#CONFIG
__config 10000111110000
#ENDCONFIG
button1 var PORTB.7
button2 var PORTB.6
button3 var PORTB.5
button4 var PORTB.4
TRISB.7 = 0
TRISB.6 = 0
TRISB.5 = 0
TRISB.4 = 0
button1 = 0
button2 = 0
button3 = 0
button4 = 0
RX var PORTB.3
TRISB.3 = 1
LED var PORTA.1
TRISA.1 = 0
cereal var byte
START:
serin RX, 2, cereal
if cereal = "A" then
high button1
pause 140
low button1
endif
if cereal = "B" then
high button2
pause 140
low button2
endif
if cereal = "C" then
high button3
pause 140
low button3
endif
if cereal = "D" then
high button4
pause 140
low button4
endif
if cereal = "E" then
button2 = 1
button3 = 1
pause 140
button2 = 0
button3 = 0
endif
if cereal = "F" then
button1 = 1
button4 = 1
pause 140
button1 = 0
button4 = 0
endif
LED = 1
pause 250
LED = 0
pause 250
GOTO START
Bookmarks