-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuttonOnOffInterrupt.txt
93 lines (77 loc) · 1.89 KB
/
buttonOnOffInterrupt.txt
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
\ *********************************************************************
\ Manage button by interrupt for On/Off - work in progress
\ Filename: buttonOnOffInterrupt.txt
\ Date: 23/05/2020
\ Updated: 29/05/2020
\ File Version: 1.0
\ MCU: ARDUINO all models
\ Copyright: Marc PETREMANN
\ Author: Marc PETREMANN
\ GNU General Public License
\ *********************************************************************
\ require pinsDefinition.txt
\ PORT B
37 constant PORTB \ Port B Data Register
\ PORT D
43 constant PORTD \ Port D Data Register
eeprom
\ PB5 on Arduino NANO
PORTB %00100000 defPIN: LED
\ PB7 on Arduino MEGA
\ PORTB %10000000 defPIN: LED
\ PD2 on Arduino NANO
PORTD %00000100 defPIN: BUTTON
\ PD0 on Arduino MEGA
\ PORTD %00000001 defPIN: BUTTON
flash
: init.ports ( ---)
LED output \ set PB5 for output
;
: LED.on ( ---)
LED high ;
: LED.off ( ---)
LED low ;
: LED.toggle ( ---)
LED pin@
if LED.off
else LED.on
then ;
: button? ( --- fl)
BUTTON pin@ \ test if button is pressed
\ true = button pressed
\ false = button released
;
\ only for test
\ : button.action ( ---)
\ BUTTON?
\ if
\ LED.toggle
\ then
\ ;
\ EXTERNAL_INTERRUPT
$69 constant EICRA \ External Interrupt Control Register A
\ $3c constant EIFR \ External Interrupt Flag Register
$3d constant EIMSK \ External Interrupt Mask Register
eeprom
$0002 constant INT0Addr \ interrupt addr for INT0
flash
: init.interrupt ( ---)
%00000011 EICRA mset \ interrupt on rising edge
%00000001 EIMSK mset \ activate INT0
;
: tempo ( ---)
6000 for next ;
: int-action ( ---)
di \ disable interrupt
tempo
LED.toggle
tempo
ei
;i
: int-enable ( ---)
['] int-action INT0Addr int!
ei \ ei = Enable Interrupt
;
init.ports
init.interrupt
int-enable