-
Notifications
You must be signed in to change notification settings - Fork 0
/
blink.nim
81 lines (70 loc) · 1.73 KB
/
blink.nim
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
import msp430
import msp430usb
import unsigned
# Trivial blink demo for now.
# Button on P2_0, LED on PJ_3
type
States = enum
Blinking
On
Off
var state {.volatile.} : States
ISR:
proc PORT2() =
case P2IV
of 2:
case state
of Blinking: state = On
of On: state = Off
of Off: state = Blinking
else: return
template toggleLED() =
PJ.OUT = PJ.OUT xor 8u16
proc main =
PJ.DIR[3] = 1
PA.DIR[8] = 0
PA.OUT[8] = 1
PA.REN[8] = 1
PA.IES[8] = 1
PA.IE[8] = 1
PA.IFG = 0
usbinit()
enable_interrupts()
while true:
case state
of Blinking:
toggleLED()
#if ((PJ.OUT and 8)==0) != ((PA.IN and 256)==0):
# toggleLED()
var i {.volatile.} = 0x7350 # volatile to keep delay loop
while i!=0:
i = i - 1
of On:
PJ.OUT[3] = 1
of Off:
PJ.OUT[3] = 0
#proc testvol =
# PA.OUT = 5
# PA.OUT = 5
main()
#testvol()
# My first project is a PC joystick to USB adapter based on an
# Olimexino-5510 board (a MSP430 board resembling an Arduino Pro).
# Judging by the SW/HW I2C solder jumpers on the board, the
# designer was unaware that this chip can remap those functions.
# I intend to measure the analog resistances by timing a capacitor
# charge, similar to the original card. Luckily the f5510 has
# more than four timer capture pins for this.
# I also intend to add a Gravis Grip decoder, for which the
# pin change interrupts will come in handy.
# Pins connected on adapter board so far:
# 1,8,9,15 5v
# 4,5,12 gnd
# 7 b2 d3 ta0_0
# 6 y1 d4 ta0_1 has capacitor
# 14 b3 d2 p1_0
# 13 y2 d5 ta0_2 has capacitor
# 11 x2 d6 ta0_3 has capacitor
# 3 x1 d7 ta0_4 has capacitor
# 2 b1 d8 p1_6
# 10 b4 d9 p1_7