#include "global.h"
#include "rs232.h"

inline void 
rs232_init() {
  UBRRL = UC_CLOCK /16 /BAUDRATE -1;          /* set baudrate *//*изменено*/
/*  UCR |= _BV(TXEN) | _BV(RXEN) | _BV(RXCIE); *//* activate sending and receiving */
  UCSRB = (1<<RXEN)|(1<<TXEN)|(1<<RXCIE);  /*изменено*/
}

void
rs232_sendbyte(uint8_t data) {
 /* while (! (USR & _BV(UDRE))) */ while (! (UCSRB & _BV(UDRE)))     /* wait till data port empty */
    ;
  UDR = data;
}

void
rs232_sendhex(uint8_t data) {
  while (!(UCSRB & _BV(UDRE))) /*изменено*/
    ;              
  if (data < 0xA0)              /* send highbyte */
    UDR = (data / 16) + '0';    /* "0" to "9" */
  else
    UDR = (data / 16) + 'A' - 10;  /* "A" to "F" */

  while (!(UCSRB & _BV(UDRE))) /*изменено*/
    ;

  data &= 0x0f;         /* send lowbyte */
  data += '0';          
  if (data > '9')       
    data += 'A' - '0'- 10;  
  UDR = data;
}

