Forum: Mikrocontroller und Digitale Elektronik ATtiny2313 Eingangspins / kurzschluss / fehlbeschaltung


von Pinmaster (Gast)


Lesenswert?

Hallo alle zusammen,

ich möchte an 3 PINS meines ATtiny2313 einen Zustand simulieren. Ich 
habe einen 2. Controller (ATmega32) der jeweils auf ein PIN bzw. mehrere 
PINs ein Signal (Ausgangspin HIGH) auf die Eingänge des ATtiny2313 
schickt.

Leider ließt der ATtiny2313 den Zustand fehlerhaft aus bzw. reagiert 
nicht. Nun dachte ich, dass das Problem am ATmega32 liegt. Meine 
Vermutung: NEIN! Ich habe schließlich eine Kabelbrücke zwischen Vcc und 
einen Eingangspin des ATtiny2313 gehalten und der Controller startet 
neu.

Wahrscheinlich ein Hardwarefehler(!) oder ist der Controller defekt?

Um die Software auszuschließen hier nachfolgende Codestücke des 
ATtiny2313:

dip-schalter.h
1
void dip_init(void);
2
int dip_read(int dip);
3
4
////////////////////////////////////////////////////////////////////////////////
5
// Pinbelegung für 2 Dip-Schalter, an verwendete Pins anpassen
6
// Dip 1-2 <-->  PORTD Bit PD3-PD4
7
#define DIP1_PORT      PD5
8
#define DIP2_PORT      PD4
9
#define DIP3_PORT      PD3
10
#define DIP4_PORT      PD2
11
12
#define DIP_PIN     PIND

dip-schalter.c
1
#include <avr/io.h>
2
#include "dip-schalter.h"
3
#include "system.h"
4
5
void dip_init(void)
6
{
7
  DIP_PIN &= ~( 1 << DIP1_PORT ); // DIP 1 activ.
8
  DIP_PIN &= ~( 1 << DIP2_PORT ); // DIP 2 activ.
9
  DIP_PIN &= ~( 1 << DIP3_PORT ); // DIP 3 activ.
10
  DIP_PIN &= ~( 1 << DIP4_PORT ); // DIP 4 activ.
11
}
12
13
int dip_read(int dip)
14
{
15
    int x=5;
16
    
17
  switch (dip)
18
  {
19
  case 1:
20
      if (DIP_PIN & (1<< DIP1_PORT))
21
      x=1; //DIP 1
22
    break;
23
24
  case 2:
25
    if (DIP_PIN & (1<< DIP2_PORT))
26
      x=2; //DIP 2
27
    break;
28
29
  case 3:
30
    if (DIP_PIN & (1<< DIP3_PORT))
31
      x=2; //DIP 2
32
    break;
33
34
  case 4:
35
    if (DIP_PIN & (1<< DIP4_PORT))
36
      x=2; //DIP 2
37
    break;
38
  default:
39
    x = 5;
40
    break;
41
  }
42
43
  return x;
44
}

main.c
1
#include <avr/io.h>
2
#include <stdint.h>
3
#include "system.h"
4
#include <util/delay.h>
5
#include "relais.h"
6
#include "led.h"
7
#include "usart.h"
8
#include "dip-schalter.h"
9
10
void tast(int but);
11
void hightast(int buto, int nub);
12
13
void tast(int but)
14
{
15
  led_on(4);
16
  switch(but)
17
  {
18
    case 1: relais_on(2); //Aus
19
        break;
20
    case 2: relais_on(3); //runter
21
        break;
22
    case 3: relais_on(4); //hoch
23
        break;
24
  }
25
  long_delay(400);
26
  switch(but)
27
  {
28
    case 1: relais_off(2); //Aus
29
        break;
30
    case 2: relais_off(3); //runter
31
        break;
32
    case 3: relais_off(4); //hoch
33
        break;
34
  }
35
  led_off(4);
36
}
37
38
void hightast(int buto, int nub)
39
{
40
  int i;
41
  for(i=0; i <= (nub-1); i++)
42
  {
43
    tast(buto);
44
    long_delay(30);
45
  }
46
}
47
48
int main()
49
{
50
  uart_init();
51
  led_init();
52
  dip_init();
53
  int x, urt;
54
55
  led_on(4);
56
  sec_delay(2);
57
  led_off(4);
58
         hightast(3, 9);
59
  led_off(4);
60
  sec_delay(1);
61
  tast(2);
62
  sec_delay(1);
63
64
while(1)
65
{
66
  if ((dip_read(1)) == 1) tast(1);
67
  if ((dip_read(2)) == 2) tast(2);
68
  long_delay(5);
69
70
}
71
}

Die eigentliche Beschaltung ist:
 -----
/  A  \              ---
|  T  |-> --------->| A |
|  M  |-> --------->| T |
|  E  |-> --------->| T |
|  G  |             | I |
|  A  |             | N |
|  3  |             | y |
\  2  /              ---
 -----

Vielleicht hat jemand eine Idee was daran nicht funktioniert, wenn ich 
einen ganz normalen Highpegel an einen Eingang setzte. Vcc gegen PIN ist 
doch ein TTL Level. Müsste doch gehen.

von g457 (Gast)


Lesenswert?

..was sollen die Zuweisungen a la..

> #define DIP_PIN     PIND
[..]
> DIP_PIN &= ~( 1 << DIP1_PORT ); // DIP 1 activ.
[..]

bewirken?</gretchenfrage>

HTH

von Benjamin U. (utzus)


Lesenswert?

Du musst DDRD initialisieren, nicht PIND.

Und in deiner Casestruktur wird x öfters auf 2 gesetzt, vermutluch ein 
C&P-Fehler.

Grüße

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.