-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathmain.c
91 lines (39 loc) · 1.15 KB
/
main.c
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
////////////////////////////////////////////////////////////////////////
// I2C Master
////////////////////////////////////////////////////////////////////////
/*
I2C Master MCU implementaiton:
(1) Master Transmitting to Slave:
A- Specify the Slave Address (Target_Slave)
use the function I2C_Writer(SlaveAddress, Location, Data)
- SlaveAddress: The slave you want to write to, e.g. "Target_Slave"
- Location: The location on the slave receving buffer you want to write to, range is 0-254
- Data: The data you wish to transmit
(2) Master Reading from slave
A- Specify the Slave Address (Target_Slave)
use the function I2C_Reader(SlaveAddress, Location)
which will return the data retreived from the slave
*/
#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include <avr/io.h>
#include <util/delay.h>
#include "I2C_master.h"
#define Target_Slave 0x02
int main(void)
{
uint8_t x=0;
uint8_t LEDs=0;
I2C_init();
DDRB=0xFF;
for(;;)
{
I2C_Writer(Target_Slave,0x00,x);
I2C_Writer(Target_Slave,0x01,255-x);
x+=1;
PORTB = I2C_Reader(Target_Slave, 0x01);
_delay_ms(100);
}
return 0;
}