Atmega 2560 programmieren

Gast #1353781
Lesenswert?

Hi

Ich versuche gerade einen Atmega zu programmieren. Um zu testen, ob der 
ganze Aufbau samt Programmer funktioniert, habe ich eine LED an PB0 
angeschlossen und folgendes Programm gebrannt. Leider funktioniert es 
nicht (Led bleibt dunkel), deshalb mal die Frage, ob mit dem Programm an 
sich alles in Ordnung ist...

  #include <avr/io.h>

  #define LED PB0
  #define output_low(port,pin) port &= ~(1<<pin)
  #define output_high(port,pin) port |= (1<<pin)
  #define set_input(portdir,pin) portdir &= ~(1<<pin)
  #define set_output(portdir,pin) portdir |= (1<<pin)


void delay_ms(uint8_t ms) {
  uint16_t delay_count = 16000000 / 17500;
  volatile uint16_t i;
  while (ms != 0) {
  for (i=0; i != delay_count; i++);
  ms--;
  }
}


int main(void) {
  set_output(DDRB, LED);
  while (1) {
  output_high(PORTB, LED);
  delay_ms(200);
  output_low(PORTB, LED);
  delay_ms(200);
  }
}
#1355237
Lesenswert?

Hallo,
Deine Berechnung von delay_count ist seltsam...
Ist Dein Programm tatsächlich auf dem Controller glandet?

Probier mal als Delay das:
1
#define F_CPU 16000000UL  // 16 MHz
2
#include <util/delay.h>
3
#include <avr/io.h>
4

5
#define LED PB0
6
#define output_low(port,pin) port &= ~(1<<pin)
7
#define output_high(port,pin) port |= (1<<pin)
8
#define set_input(portdir,pin) portdir &= ~(1<<pin)
9
#define set_output(portdir,pin) portdir |= (1<<pin)
10

11

12

13

14
int main(void) {
15
  set_output(DDRB, LED);
16
  while (1) {
17
  output_high(PORTB, LED);
18
  _delay_ms(200);
19
  output_low(PORTB, LED);
20
  _delay_ms(200);
21
  }
22
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren