Cannot control LED on Teensy 2.0

Status
Not open for further replies.
Hello,

I'm trying to make my LED on my teensy 2.0 blink on demand. If I compile the code here - https://www.pjrc.com/teensy/hid_listen.html - the LED blinks with the morse code and I can see everything as expected on my hid listen desktop code.

With the following code, all I want to do is turn the LED on for 1 second, turn it off, then repeat that infinitely. However, when I compile & flash this code, the LED turns on and does not turn off. I'm compiling it with the makefile that's included in the project dir, avr-gcc.

If anyone knows what my problem is I'd be very appreciative of your help. Thanks a lot.

Code:
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "usb_debug_only.h"
#include "print.h"


// Teensy 2.0: LED is active high
#if defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB1286__)
#define LED_ON		(PORTD |= (1<<6))
#define LED_OFF		(PORTD &= ~(1<<6))

// Teensy 1.0: LED is active low
#else
#define LED_ON	(PORTD &= ~(1<<6))
#define LED_OFF	(PORTD |= (1<<6))
#endif

#define LED_CONFIG	(DDRD |= (1<<6))
#define CPU_PRESCALE(n)	(CLKPR = 0x80, CLKPR = (n))
#define DIT 80		/* unit time for morse code */

void morse_character(char c);
void morse_P(const char *s);
const unsigned char morse_code_table[];


int main(void)
{
	unsigned char i;

	// set for 16 MHz clock, and make sure the LED is off
	CPU_PRESCALE(0);
	LED_CONFIG;
	LED_OFF;

	// initialize the USB, but don't want for the host to
	// configure.  The first several messages sent will be
	// lost because the PC hasn't configured the USB yet,
	// but we care more about blinking than debug messages!
	usb_init();

	while (1)
	{

		LED_ON;

		_delay_ms(1000);

		LED_OFF;
	}


}
 
You are turning the LED off and immediately after that back on. You are missing a delay.
 
Status
Not open for further replies.
Back
Top