-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtm1638cc_input.asm
116 lines (97 loc) · 3.1 KB
/
tm1638cc_input.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
; --------------------------------------------------------------------------
; s'AVR - Precompiler for Structured AVR Assembler by Eberhard Haug (C) 2017
; Version 2.23 (BETA), compiled 08-AUG-2017.
; This is the LITE version supporting short and medium range options.
; The selected default range is Short (.s).
; s'AVR File compiled: 11.08.2017 23:17:12
; Please report any bugs by email to [email protected]
; No liability accepted for any code generated by s'AVR!
; --------------------------------------------------------------------------
;=======================================================================
; TM1638cc_input.asm
; Library to drive the special circuit for LED control TM1638
; from Titan Micro Electronics (TM)
;
; written by Ralf Jardon (cosmicos at gmx dot net), May-July 2017
;
; Comments related to the datasheet refer to version 1.3 (en)
;
; License: GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007
;
; Version: 1.0beta-1
;=======================================================================
TM1638_POLL_KEYPAD:
push COUNT
push AKKU
push AKKU2
push AKKU3
TM1638_STB_LOW ; set strobe low to start action
ldi TM1638_DATA_BYTE, DATA_CMD + READ_KEYS ; send DATA_READ COMMAND
rcall TM1638_SEND
rcall Delay1us ; Twait = 2us
rcall Delay1us
ldi AKKU, (1<<STB_PIN) | (1<<CLK_PIN) | (0<<DATA_PIN) ; configure DATA_PIN as INPUT
out DDR_TM1638, AKKU ; to receive DATA from Slave
TM1638_DATA_HIGH ; activate internal pullup
clr AKKU
;01// FOR AKKU3 := #4 ; 4 Bytes to read
LDI AKKU3,4
_A1:
clr AKKU2
;02// FOR COUNT := #8 ; 8 Bits each Byte
LDI COUNT,8
_A4:
TM1638_CLK_LOW ; send CLK from Master to Slave
rcall Delay1us ; Twait
;03// IF %PIN_TM1638, DATA_PIN ; if slave sends high
SBIS PIN_TM1638,DATA_PIN
RJMP _A7
_A8:
sbr AKKU2, 0b10000000 ; -> set bit
;03// ENDI
_A9:
_A7:
;03// IF COUNT <> #1
CPI COUNT,1
BREQ _A11
lsr AKKU2 ; shift bit
;03// ENDI
_A13:
_A11:
TM1638_CLK_HIGH ; CLOCK pin HIGH
rcall Delay1us
;02// ENDF ; next bit
DEC COUNT
BRNE _A4
andi AKKU2,0b00010001 ; keep buttons 1 through 8 only
; works with 8-Button "LED&KEY" Board
mov COUNT,AKKU3 ; from outer FOR counter
dec COUNT ; shift by 3, 2, 1, 0
;02// WHILE COUNT > #0 ; dynamically shift button bits
_A14:
CPI COUNT,0
BRLO _A16
BREQ _A16
lsl AKKU2
dec COUNT
;02// ENDW
RJMP _A14
_A16:
or BUTTONS,AKKU2 ; mark buttons 1 through 8 only
;01// ENDF ; next byte
DEC AKKU3
BRNE _A1
swap BUTTONS ; finally all 8 Buttons (if pressed)
; are marked in following order: 12345678
TM1638_STB_HIGH ; set strobe high to terminate action
ldi AKKU, (1<<STB_PIN) | (1<<CLK_PIN) | (1<<DATA_PIN) ; reconfigure DATA_PIN as OUTPUT
out DDR_TM1638, AKKU
pop AKKU3
pop AKKU2
pop AKKU
pop COUNT
ret
; s'AVR lines read: 76
; Lines generated: 116
; Errors detected: 0
; Warnings/Hints noted: 0