[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-chat] AVR Test
From: |
swm |
Subject: |
Re: [avr-chat] AVR Test |
Date: |
Mon, 29 May 2006 18:50:55 -0700 |
User-agent: |
KMail/1.9.1 |
You might also want to use _delay_us() and _delay_ms() from the libraries. Be
aware that these have a maximum delay that is speed dependent (you'll have to
look in delay.h to see what it is).
Change your code like so to enable these delays:
#define F_CPU 8000000UL
#include <avr/io.h>
#include <avr/delay.h>
And as just mentioned, use "~" for bit inversions and "!" for logical not.
This part looks ok to me so I'm not sure why the LED is staying off (is it
wired up correctly and the pin is not blown?):
int main(void) {
DDRD |= 1<<PD1; /* set PD1 to output */
while(1) {
PORTD |= 1<<PD1; /* LED on */
delayms(1000);
PORTD &= ~(1<<PD1); /* LED off */
delayms(1000);
}
return 0;
}
-Steve
On Monday 29 May 2006 18:22, Chris Spencer wrote:
> I was able to get my dev environment setup (thanks Galen) and
> successfully write a hex file to my atmega48. However, my test program
> doesn't make the led blink. Below is my c code and makefile. Does anyone
> see any glaring problems? Is my makefile setting (or not setting) the
> appropriate fuse bits? I'm testing on two Pololu Baby Orangutan boards
> (http://www.pololu.com/products/pololu/0215/), so I'm pretty confident
> it's not a hardware issue. All lights are green on the programmer.
>
> #include <avr/io.h>
>
> /* at 8 MHz we get 1us per 8 instructions */
> inline void delayus() { asm volatile("nop\nnop\nnop\nnop\n"
> "nop\nnop\nnop\nnop"); }
>
> void delayms(uint16_t millis) {
> uint16_t loop;
> while ( millis ) {
> loop = 100;
> while (loop) {
> /* 20us of delays */
> delayus(); delayus(); delayus(); delayus(); delayus();
> delayus(); delayus(); delayus(); delayus(); delayus();
> loop--;
> }
> millis--;
> }
> }
>
> int main(void) {
> DDRD |= 1<<PD1; /* set PD1 to output */
> while(1) {
> PORTD |= 1<<PD1; /* LED on */
> delayms(1000);
> PORTD &= !(1<<PD1); /* LED off */
> delayms(1000);
> }
> return 0;
> }
>
> CC=avr-gcc
> CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=atmega48
> OBJ2HEX=avr-objcopy
> TARGET=blink
> PART=m48
> PROGRAMMER=avrisp2
>
> program: $(TARGET).hex
> avrdude -p $(PART) -c $(PROGRAMMER) -P usb -e flash:w:$(TARGET).hex
>
> %.obj: %.o
> $(CC) $(CFLAGS) $< -o $@
>
> %.hex: %.obj
> $(OBJ2HEX) -R .eeprom -O ihex $< $@
>
> clean:
> rm -f *.hex *.obj *.o
>
>
>
> _______________________________________________
> AVR-chat mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-chat