-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTWI_Program.c
79 lines (61 loc) · 1.15 KB
/
TWI_Program.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
/*
* TWI_Program.c
*
* Created: 2/12/2024 8:16:43 PM
* Author: mosta
*/
#include "STBD_TYPES.h"
#include "BIT_MATH.h"
#include "TWI_interface.h"
#include "TWI_Privte.h"
void TWI_voidInit(void)
{
TWBR = 10 ;
SET_BIT(TWSR , TWPS0);
CLEAR_BIT(TWSR , TWPS1);
SET_BIT(TWCR,TWEN);
}
void TWI_voidSetMyAddress(u8 Copy_MyAdd)
{
TWAR = TWAR & 0x01 ;
TWAR = TWAR | (Copy_MyAdd << 1) ;
}
void TWI_voidSendStart(void)
{
TWCR = (1<<TWSTA) | (1<<TWEN) |(1<<TWINT);
while(GET_BIT(TWCR , TWINT) == 0);
}
void TWI_voidSendStop(void)
{
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
void TWI_voidSendByte(u8 Copy_Byte)
{
TWDR = Copy_Byte;
TWCR = (1<<TWINT)| (1<<TWEN);
while(GET_BIT(TWCR , TWINT) == 0);
}
u8 TWI_u8ReceiveByteWithNoAck(void)
{
TWCR = (1<<TWINT) | (1<<TWEN);
while(GET_BIT(TWCR , TWINT) == 0);
return TWDR ;
}
u8 TWI_u8ReceiveByteWithAck(void)
{
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
while(GET_BIT(TWCR , TWINT) == 0);
return TWDR ;
}
u8 TWI_u8CheckStatus(tenuI2C_Check Copy_Status)
{
u8 Local_u8TWSR_Temp = TWSR;
if( Copy_Status == (Local_u8TWSR_Temp & 0xF8 ) )
{
return True;
}
else
{
return False;
}
}