정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

UART(RS232)통신을 적용했는데 전송 데이터를 영어에서 한글로 나타내고 싶습니다.
이수인 | 2016-12-29
//Created August 23 2006
//Heather Dewey-Hagborg
//http://www.arduino.cc
#include <ctype.h>
#define bit9600Delay 100  
#define halfBit9600Delay 50
#define bit4800Delay 188 
#define halfBit4800Delay 94 
byte rx = 8;
byte tx = 9;
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));
}

 

이전글   |    Atmel Studio 7.0에서 오렌지보드가 인식을 못하네요?... 2016-12-28
다음글   |    아두이노의 비콘 송출 값 자동 수신이 가능한가요??... 2016-12-30