Pages: [1]   Go Down
Author Topic: Rolling my own software serial variant  (Read 366 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First off, I'm pretty much entirely a newbie at the Arduino, microcontrollers in general, and C in general. But I'm quite good at messing around and figuring things out.

Anyway, I've posted before on this topic, but since then I have been first very busy, then Windowsless, then computerless, then busy... and so on. Finally getting around to working a bit with it. Basically I want to get my TI83+ calculator to talk to my Arduino, and vice versa. I have managed to get it to work, but I want to package it into an interrupt-driven library so I can (for example) run bitlash over the link. What's the easiest way to do this, do you think?

Code:
void sendByte(byte toSend){
  byte b1 = 0;
  int pin0 = 6;
  int pin1 = 7;
  for ( b1 =0;b1<=7;b1++){
    if(toSend & 1){
      pinMode(pin0,OUTPUT);
      digitalWrite(pin0,LOW);
      while(digitalRead(pin1)==1) {}
      pinMode(pin1,INPUT);
      pinMode(pin0,INPUT);
      while(digitalRead(pin1)==0) {}
    }else{
      pinMode(pin1,OUTPUT);
      digitalWrite(pin1,LOW);
      while(digitalRead(pin0)==1) {}
      pinMode(pin1,INPUT);
      pinMode(pin0,INPUT);
      while(digitalRead(pin0)==0) {}
    }
    toSend = toSend>>1;
//    delayMicroseconds(188);
  }
}
byte getByte(void){
  byte out = 0;
  int bit;
  int pin0 = 6;
  int pin1 = 7;
  for(bit=0; bit<8; bit++) {
    while((digitalRead(pin0) == 1) && (digitalRead(pin1) == 1)){}
    if( digitalRead(pin0) == LOW ){
       pinMode(pin1,OUTPUT);
       digitalWrite(pin1,LOW);
       while( digitalRead(pin0) == LOW ) {}
       pinMode(pin1,INPUT);
       pinMode(pin0,INPUT);
       out = (out >> 1) | 0x80;
    }else{
      pinMode(pin0,OUTPUT);
      digitalWrite(pin0,LOW);
      while( digitalRead(pin1) == LOW ) {}
      pinMode(pin1,INPUT);
      pinMode(pin0,INPUT);
      out = out >> 1;
     }
  }
  return out;
}

Logged

Pages: [1]   Go Up
Jump to: