|
|||||||
![]() |
Forum Index > Projects > Other projects | ||
New guy trying to blink a led |
|||
| | | Printable Version |
|
Anonymous: Joe | ||||||||
|
I'm trying to learn this embedded stuff, using a 2313 target board, and I'm having a hard time figuring out what I'm doing wrong. I've been a software developer for 20+ years now, mostly with some kind of Unix/linux, so this is a new world for me. Sorry if I'm doing something dumb. PHP Formatted Code 00003 #include <avr/io.h> 00004 00005 // define what pins the LEDs are connected to. 00006 // in reality, PD6 is really just '6' 00007 #define LED PD6 00008 00009 // Some macros that make the code more readable 00010 #define output_low(port,pin) port &= ~(1<<pin) 00011 #define output_high(port,pin) port |= (1<<pin) 00012 #define set_input(portdir,pin) portdir &= ~(1<<pin) 00013 #define set_output(portdir,pin) portdir |= (1<<pin) 00014 00015 // this is just a program that 'kills time' in a calibrated method 00016 void delay_ms(uint8_t ms) { 00017 uint16_t delay_count = F_CPU / 17500; 00018 volatile uint16_t i; 00019 00020 while (ms != 0) { 00021 for (i=0; i != delay_count; i++); 00022 ms--; 00023 } 00024 } 00025 00026 int main(void) { 00027 // initialize the direction of PORTD #6 to be an output 00028 set_output(DDRD, LED); 00029 00030 while (1) { 00031 // turn on the LED for 200ms 00032 output_high(PORTD, LED); 00033 delay_ms(200); 00034 // now turn off the LED for another 200ms 00035 output_low(PORTD, LED); 00036 delay_ms(200); 00037 // now start over 00038 } 00039 }
|
|
||||||||
|
|||||||||
|
Windell | ||||||||
|
I presume that you're using an ISP programmer like the USBtinyISP, or some such; no bootloader is needed. PHP Formatted Code #include <avr/io.h>int main(void) { DDRD = 255; PORTD = 255; }
Windell H. Oskay drwho(at)evilmadscientist.com http://www.evilmadscientist.com/ |
![]() Evil Scientist ![]() Status: offline
Registered: 06/15/06 |
||||||||
|
|||||||||
|
Anonymous: Joe | ||||||||
Quote by: WindellI presume that you're using an ISP programmer like the USBtinyISP, or some such; no bootloader is needed. PHP Formatted Code #include <avr/io.h>int main(void) { DDRD = 255; PORTD = 255; }
|
|
||||||||
|
|||||||||
|
Windell | ||||||||
|
You shouldn't need anything besides the chip, header, and a power source for this to work. Not even the cap. Windell H. Oskay drwho(at)evilmadscientist.com http://www.evilmadscientist.com/ |
![]() Evil Scientist ![]() Status: offline
Registered: 06/15/06 |
||||||||
|
|||||||||
|
Anonymous: Joe | ||||||||
Quote by: WindellYou shouldn't need anything besides the chip, header, and a power source for this to work. Not even the cap.
|
|
||||||||
|
|||||||||
|
Windell | ||||||||
|
I'm glad to hear that you've got it working. Windell H. Oskay drwho(at)evilmadscientist.com http://www.evilmadscientist.com/ |
![]() Evil Scientist ![]() Status: offline
Registered: 06/15/06 |
||||||||
|
|||||||||
|
|
| All times are PDT. The time is now 07:12 AM. |
|
|
Octolively
Interactive LED kits
Meggy Jr RGB
LED matrix game
development kit.
Business-card sized
AVR target boards
Peggy 2
LED Pegboard kits