NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » printf problems
December 15, 2012 by jmuthe |
I notice that anytime I write a program that uses printf it doesn't work. When I say that it doesn't work, I mean that the program compiles correctly and the other parts of the program work fine. However, I just don't see anything on the screen when I use the Nerdkit. Here is a program with the printf statement:
The program compiles but nothing appears on the screen. I then created another program where I included the same printf statement but I added a part to make a LED blink at PC0. Here it is:
|
---|---|
December 15, 2012 by Noter |
Do you have the lib's included in LINKFLAGS in the makefile?
|
December 16, 2012 by Ralphxyz |
Hi jmuthe, when you say "screen" do you mean the LCD? If LCD where is your
? Can you run initialload? Ralph |
December 16, 2012 by Rick_S |
Might need the
as well... Rick |
December 16, 2012 by jmuthe |
No, when I say screen, I don't mean the LCD. I am able to print things out on the LCD just fine. I mean my computer screen. Whenever you execute a printf statement in C or a cout statement in C++, a window with a black screen and white letters should pop up. It looks a lot like the command prompt window and it should display what you wrote in your program. Here is an example of this: http://www.youtube.com/watch?v=b00HsZvg-V0. In this video, a man writes a simple program in C that would display the message "Hello World." At the 8 minute mark he executes the program and we see a window with a black screen that displays the message "Hello World". You could just skip to the 8 minute mark if you don't want to watch the whole video. My question is why doesn't that window show up when I execute the program? When I wrote my Makefile, I just copied and pasted it from the sample files. Here it is: GCCFLAGS=-g -Os -Wall -mmcu=atmega168 LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm AVRDUDEFLAGS=-c avr109 -p m168 -b 115200 -P COM8 LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o all: led_blink-upload led_blink.hex: led_blink.c make -C ../libnerdkits avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o led_blink.o led_blink.c ${LINKOBJECTS} avr-objcopy -j .text -O ihex led_blink.o led_blink.hex led_blink.ass: led_blink.hex avr-objdump -S -d led_blink.o > led_blink.ass led_blink-upload: led_blink.hex avrdude ${AVRDUDEFLAGS} -U flash:w:led_blink.hex:a |
December 16, 2012 by Noter |
A program on the atmega microsontroller cannot pop open a window on the PC. The PC and the atmega are different and separate machines. |
December 16, 2012 by pcbolt |
jmuthe - If you look at the third to the last line in you makefile post, the command "avr-gcc" tells the computer to compile using the "avr-gcc" compiler NOT "gcc" which is used to compile programs for the PC. The "gcc" compiler is great for learning C and testing code syntax etc, but it won't work when you want to directly test programs written for the microchip. You could simulate the MCU for test purposes, but built-in functions like "printf()" need to be written differently in each case. |
December 16, 2012 by jmuthe |
Okay, I was a little confused by pcbolt's last comment. It seems that you are saying that if I change the makefile or program slightly by making it work off of gcc instead of avr-gcc then the printf function may work. If so then what do I have to change in my program and what do I have to change in my makefile? |
December 16, 2012 by pcbolt |
jmuthe - The first program of your first post in this thread (13 lines in total) should compile with "gcc" and display on your PC screen. If you put these lines in a text file called "test.c", and at the command line type...
you should get a program "test.exe" (or sometimes "a.exe") that will display on the command line when you type the name of the .exe file. That is assuming you have the gcc compiler and have all the PATH settings set up for you computer. BTW, I used a different compiler similar to "gcc" and got no errors, but when I ran it, the "while(1)" loop kept executing over and over and I had to kill the program. I'd take that out for testing purposes. |
Please log in to post a reply.
Did you know that a thermometer can be made "faster" by using a bit of math? Learn more...
|