Skip to content

Commit 5d6b2f8

Browse files
committed
First Commit
Add Libary
1 parent c479f72 commit 5d6b2f8

File tree

5 files changed

+309
-0
lines changed

5 files changed

+309
-0
lines changed

glob_def.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* glob_def.h
3+
*
4+
* Created: 11.06.2021 12:14:11
5+
* Author: LD
6+
*/
7+
8+
9+
#ifndef GLOB_DEF_H_
10+
#define GLOB_DEF_H_
11+
12+
#include <stdbool.h>
13+
14+
#ifndef F_CPU
15+
#define F_CPU 16000000UL
16+
#endif /* F_CPU */
17+
18+
#define BIT(x) (1 << (x))
19+
20+
#define _ON(x, y) (x |= BIT(y))
21+
#define _OFF(x, y) (x &= ~BIT(y))
22+
#define _TOGGLE(x, y) (x ^= BIT(y))
23+
24+
#define _GET(x,y) (!(x & BIT(y)))
25+
#define _SET(x,y,z) if(x) _ON(y,z); else _OFF(y ,z)
26+
27+
#define OUTPUT(x) _ON(_ ## x ## _ ,x)
28+
#define INPUT(x) _OFF(_ ## x ## _ ,x)
29+
30+
#define ON(x) _ON(_ ## x ,x)
31+
#define OFF(x) _OFF(_ ## x,x)
32+
#define TOGGLE(x) _TOGGLE(_ ## x ,x)
33+
34+
#define GET(x) _GET(__ ## x, x)
35+
#define SET(x,y) if(x) _ON(_ ## y,y); else _OFF(_ ## y ,y)
36+
#define GETBIT(x,y) (((x)>>(y))%2)
37+
38+
typedef unsigned char byte;
39+
40+
#endif /* GLOB_DEF_H_ */

main.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Zufallszahl.c
3+
*
4+
* Created: 05.10.2021 13:52:05
5+
* Author : LD
6+
*/
7+
8+
#include "shield_def.h"
9+
10+
#include <avr/io.h>
11+
#include <util/delay.h>
12+
13+
int main()
14+
{
15+
while(1)
16+
{
17+
}
18+
}

shield_def.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* shield_def.c
3+
*
4+
* Created: 12.10.2021 15:25:03
5+
* Author: LD
6+
*/
7+
#include "shield_def.h"
8+
#include "glob_def.h"
9+
10+
#include <avr/io.h>
11+
12+
// 7 Seg. def
13+
/* Segment byte maps for numbers 0 to F */
14+
const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90,0x88,0x83,0xC6,0xA1,0x86, 0x8E};
15+
/* Byte maps to select digit 1 to 4 */
16+
const byte SEGMENT_SELECT[] = {0xF8,0xF4,0xF2,0xF1};
17+
18+
void seg_show(byte select, byte data){
19+
_seg_show(SEGMENT_SELECT[select], SEGMENT_MAP[data]);
20+
}
21+
22+
void seg_show_dot(byte select, byte data, bool dot){
23+
byte map = SEGMENT_MAP[data];
24+
_SET(!dot, map, 7);
25+
_seg_show(SEGMENT_SELECT[select], map);
26+
}
27+
28+
void _seg_show(byte sel, byte map){
29+
OFF(LATCH_DIO);
30+
31+
for(int i = 0; i < 8; i++)
32+
{
33+
SET((map & (1 << (7 - i))),DATA_DIO);
34+
35+
ON(CLK_DIO);
36+
OFF(CLK_DIO);
37+
}
38+
39+
for(int i = 0; i < 8; i++)
40+
{
41+
SET((sel & (1 << (7 - i))),DATA_DIO);
42+
43+
ON(CLK_DIO);
44+
OFF(CLK_DIO);
45+
}
46+
47+
ON(LATCH_DIO);
48+
}

shield_def.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* shield_def.h
3+
*
4+
* Created: 11.06.2021 12:09:39
5+
* Author: LD
6+
*/
7+
8+
#include "uno_def.h"
9+
#include "glob_def.h"
10+
11+
#ifndef SHIELD_DEF_H_
12+
#define SHIELD_DEF_H_
13+
14+
// LEDs
15+
#define D1 P13
16+
#define D2 P12
17+
#define D3 P11
18+
#define D4 P10
19+
20+
#define __D1 __P13
21+
#define __D2 __P12
22+
#define __D3 __P11
23+
#define __D4 __P10
24+
25+
#define _D1 _P13
26+
#define _D2 _P12
27+
#define _D3 _P11
28+
#define _D4 _P10
29+
30+
#define _D1_ _P13_
31+
#define _D2_ _P12_
32+
#define _D3_ _P11_
33+
#define _D4_ _P10_
34+
35+
// Sensor, Buzzer
36+
#define TEMP A4
37+
#define IR P2
38+
#define VR A0
39+
#define LSI P3
40+
41+
#define __TEMP __A4
42+
#define __IR __P2
43+
#define __VR __A0
44+
#define __LSI __P3
45+
46+
#define _TEMP _A4
47+
#define _IR _P2
48+
#define _VR _A0
49+
#define _LSI _P3
50+
51+
#define _TEMP_ _A4_
52+
#define _IR_ _P2_
53+
#define _VR_ _A0_
54+
#define _LSI_ _P3_
55+
56+
// 7 Seg. Pins
57+
#define LATCH_DIO P4
58+
#define CLK_DIO P7
59+
#define DATA_DIO P8
60+
61+
#define __LATCH_DIO __P4
62+
#define __CLK_DIO __P7
63+
#define __DATA_DIO __P8
64+
65+
#define _LATCH_DIO _P4
66+
#define _CLK_DIO _P7
67+
#define _DATA_DIO _P8
68+
69+
#define _LATCH_DIO_ _P4_
70+
#define _CLK_DIO_ _P7_
71+
#define _DATA_DIO_ _P8_
72+
73+
// Buttons
74+
#define S1 A1
75+
#define S2 A2
76+
#define S3 A3
77+
78+
#define __S1 __A1
79+
#define __S2 __A2
80+
#define __S3 __A3
81+
82+
#define _S1 _A1
83+
#define _S2 _A2
84+
#define _S3 _A3
85+
86+
#define _S1_ _A1_
87+
#define _S2_ _A2_
88+
#define _S3_ _A3_
89+
90+
extern const byte SEGMENT_MAP[];
91+
extern const byte SEGMENT_SELECT[];
92+
93+
void _seg_show(byte sel, byte map);
94+
95+
void seg_show(byte select, byte data);
96+
97+
void seg_show_dot(byte select, byte data, bool dot);
98+
99+
#endif /* SHIELD_DEF_H_ */

uno_def.h

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* uno_def.h
3+
*
4+
* Created: 11.06.2021 12:04:54
5+
* Author: LD
6+
*/
7+
8+
9+
#ifndef UNO_DEF_H_
10+
#define UNO_DEF_H_
11+
12+
// Pins
13+
#define A0 PORTC0
14+
#define A1 PORTC1
15+
#define A2 PORTC2
16+
#define A3 PORTC3
17+
#define A4 PORTC4
18+
#define A5 PORTC5
19+
20+
#define P13 PORTB5
21+
#define P12 PORTB4
22+
#define P11 PORTB3
23+
#define P10 PORTB2
24+
#define P9 PORTB1
25+
#define P8 PORTB0
26+
#define P7 PORTD7
27+
#define P6 PORTD6
28+
#define P5 PORTD5
29+
#define P4 PORTD4
30+
#define P3 PORTD3
31+
#define P2 PORTD2
32+
#define P1 PORTD1
33+
#define P0 PORTD0
34+
35+
// Port
36+
#define _A0 PORTC
37+
#define _A1 PORTC
38+
#define _A2 PORTC
39+
#define _A3 PORTC
40+
#define _A4 PORTC
41+
#define _A5 PORTC
42+
43+
#define _P13 PORTB
44+
#define _P12 PORTB
45+
#define _P11 PORTB
46+
#define _P10 PORTB
47+
#define _P9 PORTB
48+
#define _P8 PORTB
49+
#define _P7 PORTD
50+
#define _P6 PORTD
51+
#define _P5 PORTD
52+
#define _P4 PORTD
53+
#define _P3 PORTD
54+
#define _P2 PORTD
55+
#define _P1 PORTD
56+
#define _P0 PORTD
57+
58+
// Pin
59+
#define __A0 PINC
60+
#define __A1 PINC
61+
#define __A2 PINC
62+
#define __A3 PINC
63+
#define __A4 PINC
64+
#define __A5 PINC
65+
66+
#define __P13 PINB
67+
#define __P12 PINB
68+
#define __P11 PINB
69+
#define __P10 PINB
70+
#define __P9 PINB
71+
#define __P8 PINB
72+
#define __P7 PIND
73+
#define __P6 PIND
74+
#define __P5 PIND
75+
#define __P4 PIND
76+
#define __P3 PIND
77+
#define __P2 PIND
78+
#define __P1 PIND
79+
#define __P0 PIND
80+
81+
// DDR
82+
#define _A0_ DDRC
83+
#define _A1_ DDRC
84+
#define _A2_ DDRC
85+
#define _A3_ DDRC
86+
#define _A4_ DDRC
87+
#define _A5_ DDRC
88+
89+
#define _P13_ DDRB
90+
#define _P12_ DDRB
91+
#define _P11_ DDRB
92+
#define _P10_ DDRB
93+
#define _P9_ DDRB
94+
#define _P8_ DDRB
95+
#define _P7_ DDRD
96+
#define _P6_ DDRD
97+
#define _P5_ DDRD
98+
#define _P4_ DDRD
99+
#define _P3_ DDRD
100+
#define _P2_ DDRD
101+
#define _P1_ DDRD
102+
#define _P0_ DDRD
103+
104+
#endif /* UNO_DEF_H_ */

0 commit comments

Comments
 (0)