2

Author Topic: Axon LED code  (Read 636 times)

0 Members and 1 Guest are viewing this topic.

Offline wecool44Topic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
Axon LED code
« on: December 13, 2011, 08:39:52 PM »
I just made an attachment for my Axon that allows it to be connected to a breadboard. I wanted to program it in AVR-GCC(No additional libraries) and the program built correctly. I uploaded it to the Axon, and nothing happens. This code is meant to flash an LED connected to C0. And yes, I did put a resistor before the LED. Here is the code:
Code: [Select]
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>

main() {
DDRC = 0b10000000;
while(1) {
PORTC = 0b10000000;
_delay_ms(50);
PORTC = 0b00000000;
_delay_ms(50);
}
}

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,660
  • Helpful? 169
    • Society of Robots
Re: Axon LED code
« Reply #1 on: December 13, 2011, 08:51:19 PM »
Just in case, do you have the LED pointing the right direction?

Also, increase the delay to 500. You have it faster than the eye can see :P

Offline wecool44Topic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
Re: Axon LED code
« Reply #2 on: December 13, 2011, 09:00:39 PM »
I tried that, and still nothing happened. I also tried switching the LED's direction, and that didn't do anything. Attached is a picture of the board

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,660
  • Helpful? 169
    • Society of Robots
Re: Axon LED code
« Reply #3 on: December 13, 2011, 09:36:03 PM »
Quote
This code is meant to flash an LED connected to C0.
I noticed your code is changing the bit for C7, not C0 :P
Bits are ordered as DDRC = 0b76543210;

Try this code below. It'll make keeping track of bits easier.

Code: [Select]
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>

//define port functions; example: PORT_ON( PORTD, 6);
#define PORT_ON( port_letter, number ) port_letter |= (1<<number)
#define PORT_OFF( port_letter, number ) port_letter &= ~(1<<number)

DDRC = 0b11111111;  //configure ports for output


main()
  {
  while(1)
    {
    PORT_ON(PORTC,7);
    _delay_ms(500);
    PORT_OFF(PORTC,7);
    _delay_ms(500);
    }
  }

In the end, you're going to find yourself writing your own libraries as your code gets more complicated. It's best to just give in and use WebbotLib :P

 


Get Your Ad Here

data_list