-
Notifications
You must be signed in to change notification settings - Fork 0
/
iic_dumb.asm
45 lines (39 loc) · 1.43 KB
/
iic_dumb.asm
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
;--------------------------------------------------------
; I2C Code
;--------------------------------------------------------
; Äàåì ñòàðò íà ëèíèþ I2C
IIC_START: OUTI TWCR,1<<TWINT|1<<TWSTA|1<<TWEN|0<<TWIE
IIC_S: IN r16,TWCR
ANDI r16,1<<TWINT
BREQ IIC_S ; Æäåì ïîêà ïåðåäàò÷èê IIC âûïîëíèò ñòàðò
RET
;-----------------------------------------------------------------------------
;Ïîñûëàåì áàéò ïî IIC
IIC_BYTE: OUT TWDR,r16
OUTI TWCR,1<<TWINT|1<<TWEN|0<<TWIE
IIC_B: IN r16,TWCR
ANDI r16,1<<TWINT ; Æäåì ïîêà ïåðåäàò÷èê ïîøëåò áàéò
BREQ IIC_B
RET
;-----------------------------------------------------------------------------
; Ïðèíÿòü áàéò.
IIC_RCV: OUTI TWCR,1<<TWINT|1<<TWEN|1<<TWEA|0<<TWIE
IIC_R: IN r16,TWCR
ANDI r16,1<<TWINT
BREQ IIC_R ; Æäåì ïîêà áàéò áóäåò ïðèíÿò
RET
;-----------------------------------------------------------------------------
; Ïðèíÿòü ïîñëåäíèé áàéò. Ïîìíèòå ÿ ïèñàë î ðàçíèöå ìåæäó ïðîñòî áàéòîì è ïîñëåäíèì
; áàéòîì? Â ïîñëåäíåì áàéòå íå ãåíåðèðóåòñÿ ACK!!!
IIC_RCV2: OUTI TWCR,1<<TWINT|1<<TWEN|0<<TWEA|0<<TWIE
IIC_R2: IN r16,TWCR
ANDI r16,1<<TWINT ; Æäåì ïîêà áàéò áóäåò ïðèíÿò
BREQ IIC_R2
RET
;-----------------------------------------------------------------------------
; Ñãåíåðèðîâàòü STOP
IIC_STOP: OUTI TWCR,1<<TWINT|1<<TWSTO|1<<TWEN|0<<TWIE
;IIC_ST: IN r16,TWCR
; ANDI r16,1<<TWSTO
; BREQ IIC_ST ; Æäåì ïîêà íå áóäåò ãîòîâ ñòîï.
RET