title: Trying to write character from Arduino pin to Putty
body: <p>So, i am writing a code to send a character (8 data-bits) and a stop bit to Putty using the Arduino timer 1 interrupt. When I try to send a character it shows something in Putty, so it does send, but not the character I am sending. I have searched for all sorts of documentation but i can't seem to find what i need, also I don't know what I'm doing wrong. Code:</p>
  
  <pre><code>#define Fosc 16000000
  
  int rxPin = 7;
  int txPin = 8;
  
  int dataBits = 0;
  
  uint8_t txBuffer;
  
  void setup() {
    Serial.begin(9600);
    pinMode(txPin, OUTPUT);
    pinMode(rxPin, INPUT);
    setupInterrupts(9600);
  }
  
  void loop() {
    ReadMessage();
  }
  
  void setupInterrupts(long baud)
  {
    long cmr = ((Fosc / (64 * baud)) - 1); //compare match register
    noInterrupts();
    TCCR1A = 0;
    TCCR1B = 0;
    TCNT1  = 0; //counter value to 0
    OCR1A = cmr;
    TCCR1B |= (1 &lt;&lt; WGM12);  // CTC mode
    TCCR1B |= (1 &lt;&lt; CS11) | (1 &lt;&lt; CS10);   // Set bits for 64 prescaler
    //TIMSK1 = _BV(OCIE1A);  //attach
    interrupts();
  }
  
  ISR(TIMER1_COMPA_vect)
  {
    transmit();
  }
  
  void transmit()
  {
    if (dataBits &lt; 8)
    {
      if (txBuffer &amp; 0b1) {
        digitalWrite(txPin, HIGH);
      }
      else {
        digitalWrite(txPin, LOW);
      }
      txBuffer &gt;&gt;= 1;
    }  
    dataBits++;
    if (dataBits == 9)
    {
      dataBits = 0;
      digitalWrite(txPin, HIGH);
      TIMSK1 &amp;= ~_BV(OCIE1A); //detach
    }
  }
  
  bool getParity(unsigned int n)
  {
    bool parity = 0;
    while (n)
    {
      parity = !parity;
      n = n &amp; (n - 1);
    }
    return parity;
  }
  
  int incomingByte;
  
  void ReadMessage() {
    if (Serial.available() &gt; 0) {
      incomingByte = Serial.read();
      char receivedCharacter = (char) incomingByte;
      txBuffer = receivedCharacter;
      Serial.println((char)txBuffer);
      TIMSK1 = _BV(OCIE1A);  //attach
    }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/pBcel.png" rel="nofollow noreferrer">Putty Output</a></p>