File: port.c

package info (click to toggle)
simulavr 1.0.0%2Bgit20160221.e53413b-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 5,748 kB
  • sloc: cpp: 35,491; python: 6,991; ansic: 3,567; makefile: 1,072; sh: 653; asm: 414; tcl: 320
file content (76 lines) | stat: -rw-r--r-- 1,809 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* this code is taken from examples/anacomp */
#include <avr/interrupt.h>

#include <avr/io.h>

volatile unsigned char in_loop = 0;
volatile unsigned char loop_count = 0;

// PORT A
#define init_a() { DDRA = 0x02; }
#define update_a() { PORTA = (PINA & 0x1) << 1; }
// PORT B
#define init_b() { DDRB = 0x02; }
#define update_b() { PORTB = (PINB & 0x1) << 1; }
// PORT C
#define init_c() { DDRC = 0x02; }
#define update_c() { PORTC = (PINC & 0x1) << 1; }
// PORT D
#define init_d() { DDRD = 0x02; }
#define update_d() { PORTD = (PIND & 0x1) << 1; }
// PORT E
#define init_e() { DDRE = 0x02; }
#define update_e() { PORTE = (PINE & 0x1) << 1; }
// PORT F
#define init_f() { DDRF = 0x02; }
#define update_f() { PORTF = (PINF & 0x1) << 1; }
// PORT G
#define init_g() { DDRG = 0x02; }
#define update_g() { PORTG = (PING & 0x1) << 1; }

void init(void) {
#if !defined(PROC_at90s4433) && !defined(PROC_atmega8) && !defined(PROC_atmega48) && !defined(PROC_attiny25)
  init_a();
#endif
  init_b();
#if !defined(PROC_attiny2313) && !defined(PROC_attiny25)
  init_c();
#endif
#if !defined(PROC_attiny25)
  init_d();
#endif
#if defined(PROC_atmega64) || defined(PROC_atmega128) || defined(PROC_at90can32) 
  init_e();
  init_f();
  init_g();
#endif
}

int main(void) {

    init();

    do {
        in_loop = 1;

#if !defined(PROC_at90s4433) && !defined(PROC_atmega8) && !defined(PROC_atmega48) && !defined(PROC_attiny25)
        update_a();
#endif
        update_b();
#if !defined(PROC_attiny2313) && !defined(PROC_attiny25)
        update_c();
#endif
#if !defined(PROC_attiny25)
        update_d();
#endif
#if defined(PROC_atmega64) || defined(PROC_atmega128) || defined(PROC_at90can32) 
        update_e();
        update_f();
        update_g();
#endif

        loop_count++;
    } while(1); // do forever
}

// EOF