336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

http://www.gnu.org/savannah-checkouts/non-gnu/avr-libc/user-manual/group__avr__stdio.html

우선 #include<stdio.h> 가 선언되어있어야 한다.


http://www.avrfreaks.net/forum/how-use-printf-uart

timojaask의 링크를 주목


https://www.sparkfun.com/tutorials/105

SparkFun의 Tutorial

AVR GCC Compiling

Sorry for the confusion. 

When these tutorials were written and photographed, 

we used the ATmega8. 

We now carry the newer ATmega168. 

You will find all ATmega168 information in the following pages, 

but the pictures will show an ATmega8.

I know very little about the ins and outs of the AVR-GCC compiler. 

난 알고있다. 매우조금 about the 입력들 and 출력들을 of the AVR-GCC 컴파일러의.

I've learned a few basics that helped me along the way, 

but when you run up against a jam, google and AVRfreaks.net are your friend.

First, we did the blinky. 

Open this code in PN2 and make sure you can compile it. 

Click on Tools->Make All. The window in the bottom screen should say 'Process Exit Code: 0' meaning the compilation was successful. If not, there should be a line number listing of the problem line of code. Be sure to check above and below the indicated line for problems.

In the second example C file called basic-out-atmega168.c (basic-out.c for the ATmega8), 

I've inserted a handful of functions and lines of code. First of the black magic:


#define FOSC 16000000
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1    //MYUBRR을 선언하기위해 FOSC, BAUD를 선언


What is all this noise at the top of the file? 

This is a series of defines that calculates the MYUBRR variable with the correct number. 

Since serial communication depends on the fact that we will be transmitting and receiving at 9600 bits per second, it's crucial to tell the ATmega168 what bit rate to set. 

Because the ATmega168 is dictated by the oscillator that it is using, 

we must correctly calculate what value we need to load into the ATmega168 hardware so that the ATmega168 sends the serial pulses at the correct rate with a given oscillator type. 

In our case, 

we are using a 16MHz oscillator so we can setup the define statement as shown. MYUBRR is calculated at compile time and is loaded successfully into the hardware UART during run time.


The UBRR value calculation in Lecture 5 could be more accurate with the following macro:

#define MYUBRR (((((FOSC * 10) / (16L * BAUD)) + 5) / 10) - 1)

There is also pretty useful web form for UBRR calculation:

http://www.wormfood.net/avrbaudcalc.php

▲BaudRate 계산기

여기 맞춰서 Bit를 설정해주면 된다.


static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);


This line creates a buffer for the printf statement to post to.

이 라인은 만들어낸다. a buffer를 for the printf statement를 to 포스트하기위해

I'd rather not explain it, simply because I don't understand it. 

When I am working on a new coding project I never start from a blank page, 

I *always* start from a known working program and slowly bring in bits of other projects to get the code I need, writing bits along the way. 

Please start from this printf example and build away. 

The purpose here is to get your printing string to the terminal window.

여기 프로젝트는 to 얻기위함이다. 네 printing string을 to the 터미널 윈도우에.


Checkout the ioinit() function. You'll notice some new commands.

UCSR0B = (1<<RXEN0)|(1<<TXEN0);       //기본적으로 RX,TX가 Enable상태가 되야한다.


This is the really funky, but very practical, method of setting bits on the AVR series. RXEN0 is defined in some file as '5'. 1<<RXEN0 translates to 'shift a 1 to the left by 5 spaces'.  

This is handy because you don't need to remember specifically where the RX enable bit resides, 

you only need to know to set (or not set) the RXEN0 bit by using this bit command. Same goes for TX enable. Using the example code above, these two bits (RXEN0 and TXEN0) get set and loaded into UCSR0B register, enabling the TX and RX hardware on the ATmega168. 

Finally, we see the very comfortable line of code:


printf("Test it! x = %d", x);


What did you say? This is not a comfortable line of C code for you? Ok - printf is somewhat of a universal function to pass serial strings and variables to the outside world. The line of code above will pass the string "Test it! x =" to the serial port and it should display on the terminal window. After that, the %d gets converted to an actual decimal number so that whatever digital number is currently stored in the variable x gets printed to the terminal screen. So what? This simple printf statement allows you to print variable contents and see what's going on within your C program.

Time to load the basic-out-atmega168.c file onto your breadboard. Open up PN2, compile basic_out-atmega168.c. Power up your board, click on Tools->[WinAVR] Program from within Programmer's Notepad. The code should now be loaded onto your ATmega168. If WinAVR throws a verification error, try again. Open up the terminal window at 9600bps if you don't already have it open.

basic-out-atmega168.c


코드상에서 필수 추가해야할 것들

static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);

여기  파라미터에 대한 선언이 없으므로

static int uart_putchar(char c, FILE *stream);

함수 printf를 초기화시키기위해 ▼아래 작업이 필요하다.

stdout = &mystdout;    //Required for printf init

'졸업작품 > 우편함(bluetooth+Servo+LCD+SmartPhone)' 카테고리의 다른 글

2-1 관련코드  (3) 2016.10.27
4.회로도  (7) 2016.10.27
1.충격센서 (Piezo Disk Vibration Sensor)  (0) 2016.10.15
Posted by ElectricShock
:
BLOG main image
잡동사니들(지극히 개인취향인...) (다른글에도 댓글 부탁해요♥) You May Leave English Messages on GuestBook. by ElectricShock

공지사항

카테고리

분류 전체보기 (782)
Programming(=프로그래밍) (3)
MiDi (2)
Animation (4)
Blender (3D Graphic Program.. (10)
Blendtuts.com (Series) (1)
Blender 기초 팁들 (2)
Processing (디지털미디어과) (2)
Music (1)
Books in the world (0)
Communication(CAN, UART, et.. (12)
MCU Examples (PIC 기반) (7)
Transistor (1)
Mikro C Pro (11)
Mikro Pascal (1)
Proton IDE (0)
Robot (0)
Swift 3D (1)
Dummies Series (1)
All about Hacking (0)
제2 외국어 (1)
PIC 해외서적들 (3)
AVR (25)
PIC (MikroC) (MPLAB) (4)
Assembly (2)
ARM (3)
Arduino (26)
PSpice (1)
Proteus ISIS (14)
CodeVision (2)
FPGA (15)
MPLAB (24)
PCB (the Procedure) (15)
3D Printer (5)
PICKIT3 (6)
Matlab (11)
RaspBerry PI (15)
BeagleBone (1)
Android Studio (17)
졸업작품 (172)
Korea History (0)
Issue(사회) (73)
Multimeter 리뷰 (1)
Oscilloscope (1)
A (34)
B (19)
J (6)
C (32)
P (12)
T (37)
H (12)
I (12)
M (44)
R (5)
E (5)
F (2)
D (9)
O (2)
L (7)
S (9)
W (2)
V (6)
G (14)
Visual C++ or Visual Studio (2)
Android App Development (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백