반응형
printf 처럼 uart로 출력하는 방법입니다.
프로그램시 디버깅을 하려면 UART로 로그를 많이 보내게 되는데
문자열로 만들어서 UART를 전송하는 방법입니다.
간단하게 아래와 같이 코딩하시면 디버깅이 편하겠죠?
#ifndef F_CPU
#define F_CPU 16000000UL // 16 MHz clock speed
#endif
#define F_CPU 16000000UL // 16 MHz clock speed
#endif
#include <stdio.h>
#include <stdarg.h>
#include <avr/io.h>
#include <avr/iom128.h>
#include <util/delay.h>
#include <stdarg.h>
#include <avr/io.h>
#include <avr/iom128.h>
#include <util/delay.h>
void uart_send_byte(unsigned char byte)
{
while(!(UCSR0A & (1 << UDRE)));
UDR0 = byte;
}
unsigned char usart_receive(void)
{
while(!(UCSR0A & (1 << RXC)));
return UDR0;
}
{
while(!(UCSR0A & (1 << UDRE)));
UDR0 = byte;
}
unsigned char usart_receive(void)
{
while(!(UCSR0A & (1 << RXC)));
return UDR0;
}
static int uart0_debug_putChar(char c, FILE *stream);
static FILE uart0_debug_out = FDEV_SETUP_STREAM(uart0_debug_putChar, NULL,_FDEV_SETUP_WRITE);
static int uart0_debug_putChar(char c, FILE *stream)
{
uart_send_byte(c);
return 0;
}
static FILE uart0_debug_out = FDEV_SETUP_STREAM(uart0_debug_putChar, NULL,_FDEV_SETUP_WRITE);
static int uart0_debug_putChar(char c, FILE *stream)
{
uart_send_byte(c);
return 0;
}
int debug_printf( const char *fmt, ...)
{
va_list al;
va_start(al, fmt);
return vfprintf(&uart0_debug_out, fmt, al);
}
{
va_list al;
va_start(al, fmt);
return vfprintf(&uart0_debug_out, fmt, al);
}
int main(void)
{
{
//19200 bps
UBRR0L = 0x33;//(unsigned char)BAUD_RATE_L; // baud rate 설정
UBRR0H = 0x00;
UCSR0A = 0x00;
UCSR0B = 0x18;
UCSR0C = 0x06;
UBRR0L = 0x33;//(unsigned char)BAUD_RATE_L; // baud rate 설정
UBRR0H = 0x00;
UCSR0A = 0x00;
UCSR0B = 0x18;
UCSR0C = 0x06;
int count = 0;
while(1)
{
debug_printf("\r\n count %d",count++);
_delay_ms(1000);
}
}
반응형
'프로그래밍 언어' 카테고리의 다른 글
[MFC] C++ 엔터치면 종료 (0) | 2023.10.13 |
---|---|
Atmel Micro processor Flash Programming (0) | 2023.09.14 |
AVR EEPROM 읽고 쓰기 (0) | 2023.09.14 |
입력 출력 간단하게 구현하기(AVR input output) (0) | 2023.09.14 |
[C#] 파일다이얼로그 , OpenFileDialog, SaveFileDialog (0) | 2023.08.14 |