Output contents of OCR1A and OCR1B to terminal using USART

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I would like to know if it is possible to display the contents of OCR1A to a terminal using serial communication once I have the functions usart_putstring(OCR1A) as shown below:


void usart_putstring(char *s)
{
    while(*s)
    {
       usart_putch(*s);
       s++;
    }
}

void usart_putch(char data)
{
    // Wait for empty transmit buffer
    while ( !(UCSRA & (_BV(UDRE))) );
    // Start transmission
    UDR = data; 
}

I want to do this so that I can see what are the min. and max. values of OCR1A while driving a servo.

Thanks,
Sumair

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if your terminal program can display hex values received you should be fine already.
if you use a ASCII terminal program, then first convert the hex value into 4 ASCII characters and send those through the UART.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

usart_putstring(OCR1A)

Try something like:

char buff[10];
itoa(OCR1A, buff, 10);
usart_putstring(buf);

Note that itoa() is not a standard C function so your compiler may have a different interface or may not even supply itoa() at all.