Hello all:

I'm a long time computer programmer, so so electronics background and new to pics.

My immediate goals:
1. control my laptop through the pic using pulsin generated by infrared.
2. control my pic from my laptop.

My longer term goals:
1. continuous pic to laptop communication with no human intervention
2. accomplish the above on a severe shoestring

I have had proof-of-concept success in my immediate goals but with inconsistencies and anomalies.

A little hardware and software background:
1. My pic setup is breadboarded
2. I am using picbasic demo
3. I am using a straight through 9 pin d type female serial cable with 20 gauge wires stuck in the appropriate holes secured with a rubber band and alligator leads going to the breadboard.
4. I was using hyperterminal to send and receive data through the serial port but it isn't gui capable. I am now using PHP since I know it quite well and have apache/php already set up on my laptop.
5. Serial input and output electronics and software are configured as per the pbp manual.

Once I secured the wires to the d connector and became more aware of not stepping on cables, not letting things fall on the floor and not stressing temporary connections, the hardware setup became stable.

Now for the inconsistencies and anomalies.
1. As I stated above I was using hyperterminal to communicate with the serial port. In my PHP input program, whether at the command line or on the browser, the program will hang unless I log into hyperterminal and log out with the correct settings. That action seems to set something in the background beyond what diagnostics I can display, but I can't tell what.

Using PHP as output to the serial port requires no hyperterminal intervention.

2.In the output mode, characters sent to the serial port and the pic through either hyperterminal or PHP result in a successful completion about 8 out of 10 times. I wasn't sure if it was a sticky keyboard problem with hyperterminal because the characters don't appear on the screen. With PHP the characters do appear on the screen and still the successful receive rate is 8 out of 10 times. Is there a timing thing going on here? Would "define char_spacing" help?

***

One more question, unrelated to the above: Somehow I got all zereos on a 16f628 and it appears useless. I am using a pic programmer. Is there any recovery procedure available? What causes this?

I have included the pic programs and the PHP programs below.

Sorry for the length of this message. Thanks in advance to whoever takes the time to read it and reply.

- K -

*****************************************
php code - to the pic ...
- - - - - - - - - - - - -

<?php
$submit='';
$word='';
if (isset($_POST) && !empty($_POST)) {
if (isset($_POST['word'])) {
$word=$_POST['word'];
echo "word=$word";
}
}
if ($word) {
`mode com1: baud=2400 parity=n data=8 stop=1 to=on xon=off octs=off odsr=off dtr=on rts=on

idsr=off`;
$fp = fopen ("com1:", "w+");
if (!$fp) {
echo "can't open port: com1";
}
else {
if (fwrite($fp, $word) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

fclose($fp);
}

}


?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php
echo "<input type=text size=2 maxlength=2 name=word><br>";
echo "<input type=submit value=submit name=submit></form>";

?>

************************************************** **
php code - from the pic ...
- - - - - - - - - - - - - - -

<?php

`mode com1: baud=9600 parity=n data=8 stop=1 to=on xon=off octs=off odsr=off dtr=on rts=on idsr=off`;
$char='';
$fp = fopen ("com1:", "r");
if (!$fp) {
echo "can't open port: com1";
}
else {
//while (!feof($fp)) {
// $buffer = fgets($fp);
// echo ord($buffer);
//}
// while (false !== ($char = fgetc($fp))) {
for ($i=0;$i<=34;$i++) {
$char = $char.fgetc($fp);
}
echo substr($char,19,16);
//}
echo "<br>finish 1<br>";
fclose($fp);
}

?>

************************************************** **
serin pic code (16f628)
- - - - - - - - - - - - - -
SI var portb.1 ' Define serial in pin
N2400 con 4 ' Set serial mode
byteIn var byte
low portb.4
low portb.5
low portb.7
loop:
Serin SI,N2400,["x"],Bytein
if bytein = "6" then
low portb.4
low portb.5
low portb.7
goto loop
endif
if (bytein = "4") or (bytein = "5") then
goto show4or5
else
high portb.7
low portb.4
low portb.5
endif
show4or5:
If bytein = "4" Then ' 4 = input character
low portb.5
low portb.7
high portb.4
endif
If bytein = "5" Then ' 5 = input character
low portb.4
low portb.7
high portb.5
endif
goto loop

*********************************************
serout code ...
- - - - - - - - - - -
w0 var word
so var portb.0
N9600 con 6
j var byte
k var word
pulseLoop:
PULSIN PORTb.2,1,w0
if w0 < 1 then
goto pulseLoop
else
Serout SO,N9600,[" ",10]
Serout SO,N9600,[#w0]
Serout SO,N9600,["-w0 value"]
endif
;low portb.0
Serout SO,N9600,[" "]
Serout SO,N9600,[#w0]
Serout SO,N9600,["-"]
k = w0
for j = 0 to 15
;low j
if k.15 then
Serout SO,N9600,["1"]
else
Serout SO,N9600,["0"]
endif
k = w0 << (j + 1)
next j
pause 1500
goto pulseloop
************