-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtcd1703c.ino
64 lines (47 loc) · 1.2 KB
/
tcd1703c.ino
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
// Clock generator to drive a Toshiba TCD1703C CCD sensor.
// Default clock speed is 16MHz on Arduino Uno.
#define CLK 16000000UL
#define SH PORTB0 // Digital pin 8.
#define PHI1 PORTB1 // Digital pin 9 (PWM).
#define PHI2 PORTB2 // Digital pin 10 (PWM).
#define RS PORTB3 // Digital pin 11 (PWM).
#define CP PORTB4 // Digital pin 12.
#define TOTAL_STEPS (3825)
#define NOP __asm__ __volatile__ ("nop\n\t")
#define DELAY1 NOP;
#define DELAY2 NOP; NOP;
#define DELAY4 DELAY2; DELAY2;
#define DELAY8 DELAY4; DELAY4;
void setup() {
DDRB = B00011111;
PORTB = B00000000;
noInterrupts();
}
// Generates RS and a delayed CP pulse.
void RS_CP() {
PORTB |= (1 << RS);
DELAY1;
PORTB &= ~(1 << RS);
DELAY1;
PORTB |= (1 << CP);
DELAY1;
PORTB &= ~(1 << CP);
DELAY1;
}
void loop() {
PORTB = (0 << RS) | (0 << CP) | (1 << PHI1) | (0 << PHI2) | (0 << SH);
DELAY1;
RS_CP();
PORTB |= (1 << SH);
DELAY1;
PORTB &= ~(1 << SH);
DELAY1;
RS_CP();
for (int cnt = 0; cnt < TOTAL_STEPS; cnt++) {
PORTB = (0 << RS) | (0 << CP) | (0 << PHI1) | (1 << PHI2) | (0 << SH);
DELAY2;
RS_CP();
PORTB = (0 << RS) | (0 << CP) | (1 << PHI1) | (0 << PHI2) | (0 << SH);
DELAY8;
}
}