-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample-send.c
86 lines (69 loc) · 1.61 KB
/
example-send.c
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
/*
** Demonstration of fd-serial module
** (C) 2010, Nick Andrew <[email protected]>
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include "fd-serial.h"
/* Set highest frequency CPU operation
** Startup frequency is assumed to be 1 MHz
** 8 MHz for the internal clock
*/
void set_cpu_8mhz(void) {
// Let's wind this sucker up to 8 MHz
CLKPR = 1<<CLKPCE;
CLKPR = 0<<CLKPS3 | 0<<CLKPS2 | 0<<CLKPS1 | 0<<CLKPS0;
// System clock is now 8 MHz
}
void writeString(char const *cp) {
while (*cp) {
fdserial_send(*cp++);
}
}
void write8(unsigned char c) {
unsigned char b = (c >> 4) + 0x30;
fdserial_send(b > 0x39 ? b + 7 : b);
b = (c & 0x0f) + 0x30;
fdserial_send(b > 0x39 ? b + 7 : b);
}
void write16(uint16_t i) {
write8(i >> 8);
write8(i & 0xff);
}
void write32(uint32_t i) {
write16(i >> 16);
write16(i & 0xffff);
}
volatile uint8_t count_int0 = 0;
volatile uint8_t start_cycles = 0;
volatile uint8_t start_counter = 0;
volatile uint8_t stop_cycles = 0;
volatile uint8_t stop_counter = 0;
volatile uint8_t cycle_count = 0;
#define NR_MARKERS 14
volatile uint8_t a_state[NR_MARKERS];
volatile uint8_t a_cycle[NR_MARKERS];
volatile uint8_t a_counter[NR_MARKERS];
volatile uint8_t a_index = 0;
volatile uint8_t a_max = NR_MARKERS;
int main(void)
{
// Disable interrupts
cli();
//Setup the clock
set_cpu_8mhz();
fdserial_init();
// Enable interrupts
sei();
uint32_t loops = 0;
// Configure PORTB4 as an output
DDRB |= 1<<PORTB4;
while (1) {
loops ++;
if (loops % 50000 == 0) {
PORTB |= 1<<PORTB4;
writeString("ATtiny85 Serial Port Test 9600BPS UUUUU UUUUU\n");
PORTB &= ~(1<<PORTB4);
}
}
}