RS232 and Arduino

hi,

I am trying to establish a communication channel between my arduino board and computer via RS232.

I have managed to make the connections on the breadboard.
The problem i am facing is the coding.

I searched for a lot of example codes online but i am unable to write a code since i couldnt understand the ones online..

So any help for the above problem would be appreciated.
PLEASE HELP ME!!!

i found a code online but it is not working.
the code i found is::

#include <ctype.h>

#define bit9600Delay 100
#define halfBit9600Delay 500
#define bit4800Delay 188
#define halfBit4800Delay 94

byte rx = 6;
byte tx = 7;
byte SWval;

void setup() {
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
digitalWrite(tx,HIGH);
delay(2);
digitalWrite(13,HIGH); //turn on debugging LED
SWprint(‘h’); //debugging hello
SWprint(‘i’);
SWprint(10); //carriage return
}

void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit9600Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit9600Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit9600Delay);
}

int SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit9600Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit9600Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit9600Delay);
delayMicroseconds(bit9600Delay);
return val;
}
}

void loop()
{
SWval = SWread();
SWprint(toupper(SWval));
}

As per this code when i type ‘a’ I should get back 'A" in the hyper terminal…

Its not happening so for me…

PLEASE HELP!!!

it is not working.

Probably about the single most useless thing you could type here.

Have you got RS232 level shifters?

Please remember to use code tags when posting code here.

Why are you not using the SoftwareSerial library? It comes with the Arduino IDE by default. Your code can not do anything else except serial. The Arduino literally cannot do anything useful while it's running that code. In fact, it can't even transmit and receive at the same time. Not to mention changing baud rates means changing 7 lines of code.

If you really do want to write your own version of software serial you may find some ideas in my yet another software serial

Otherwise, as @MorganS has said, just use the SoftwareSerial library
AFAIK SoftwareSerial cannot transmit and receive at the same time

If you need "proper" serial comms you need a Mega (with 4 serial ports) or a Leonardo (with 1 free USART)

...R

Yes, I am using a MAX232 level shifter.

I can see this is going to take a while.

YEAH SO WELL ID APPRECIATE IT IF U GOT OF FROM UR HIGH ASS PEDESTAL AND EXPLAINED>>

not everyone is an expert..
If everyone were u wouldnt be a GLOBAL MODERATOR.

Since u are. perhaps u could help a beginner.

YEAH SO WELL ID APPRECIATE IT IF U GOT OF FROM UR HIGH ASS PEDESTAL AND EXPLAINED

sp. "Yeah, so well, I'd appreciate it if you got off from your high-ass pedestal and explained".

OK, explanation:
Your sketch does something.
You haven't told us what.
Presumably, what it does doesn't match what you expect.
You haven't told us that either.

That and code tags are all explained here

Note: Just because I happen to be a moderator doesn't mean I know all the answers or that I'm psychic, particularly when you're being so protective of the facts in the case.

#define bit9600Delay 100 
#define halfBit9600Delay 500

Arithmetic..

This is so simple as using the Serial.begin and Serial.print commands.

chit:
As per this code when i type 'a' I should get back 'A" in the hyper terminal...

Its not happening so for me..

I did mention what the code is supposed to do..
I knew u wouldnt be a psychic.
Well, if u dont wanna share the answers, dont share ur bullshit either..

AWOL:

#define bit9600Delay 100 

#define halfBit9600Delay 500



Arithmetic..

Heard of typos?? Or is your pedestal too damn high??

Well, if u dont wanna share the answers, dont share ur bullshit either..

sp. "Well, if you don't want to share the answers, don't share your bovine effluent either"

I did share the answer, but you dismissed it as a typo.
Mind your language.

You demand answers, but I note that it took you over 40 minutes to post the code (badly).

chit:
Well, if u dont wanna share the answers, dont share ur bullshit either..

Heard of typos?? Or is your pedestal too damn high??

Do you want help?
OR
Have you just come here to find something new to complain about.

If you copy and paste code there can't be a typo - and I think it is reasonable to assume that is what you did. There is not much point posting code that you have not tested.

Have you noticed that some people have given you some constructive advice?
Have you tried it?

...R