1 | #include <stdlib.h>
|
2 | #include <stdio.h>
|
3 | #include <avr/io.h>
|
4 | #include <avr/eeprom.h>
|
5 | #include <avr/interrupt.h>
|
6 | #include "dataflash.h"
|
7 |
|
8 | uint16_t Analogwert;
|
9 | uint8_t Array = 0;
|
10 | uint16_t Page;
|
11 | static uint16_t pBuffer[60];
|
12 |
|
13 |
|
14 | //***********UART Konfiguration**************
|
15 | void UART_init(void)
|
16 | {
|
17 | UBRR0 = 51;
|
18 | UCSR0A |= (1<<U2X0);
|
19 | UCSR0B |= (1<<TXEN0);
|
20 | UCSR0C |= (1<<UCSZ00)|(1<<UCSZ01);
|
21 | }
|
22 |
|
23 | int uart_putc(unsigned char c)
|
24 | {
|
25 | while (!(UCSR0A & (1<<UDRE0)))
|
26 | {
|
27 | }
|
28 |
|
29 | UDR0 = c;
|
30 | return 0;
|
31 | }
|
32 |
|
33 |
|
34 | /* puts ist unabhaengig vom Controllertyp */
|
35 | void uart_puts (char *s)
|
36 | {
|
37 | while (*s)
|
38 | {
|
39 | uart_putc(*s);
|
40 | s++;
|
41 | }
|
42 | }
|
43 | //***********UART Konfiguration**************
|
44 |
|
45 | //***********Timer Konfiguration*************
|
46 | void Timer1_init(void)
|
47 | {
|
48 | TCNT1 = 3036;
|
49 | }
|
50 |
|
51 | void Timer1_start(void)
|
52 | {
|
53 | TCCR1B |= (1<<CS12);
|
54 | }
|
55 |
|
56 | void Timer1_stop(void)
|
57 | {
|
58 | TCCR1B &= ~(1<<CS12);
|
59 | Buffer_To_Page(1, Page);
|
60 | }
|
61 |
|
62 | ISR(TIMER1_OVF_vect)
|
63 | {
|
64 | TCNT1 = 3036;
|
65 | }
|
66 | //***********Timer Konfiguration*************
|
67 |
|
68 | //************ADC Konfiguration**************
|
69 | void ADC_init(void)
|
70 | {
|
71 | ADCSRA |= (1<<ADEN)|(1<<ADIE)|(1<<ADSC);
|
72 | ADCSRB |= (1<<ADTS1)|(1<<ADTS2);
|
73 | }
|
74 |
|
75 | ISR(ADC_vect)
|
76 | {
|
77 | if(Array < 60)
|
78 | {
|
79 | Analogwert = ADC;
|
80 | *pBuffer = Array;
|
81 | pBuffer[Array] = Analogwert;
|
82 | Array++;
|
83 | }
|
84 | else
|
85 | {
|
86 | if(Page < 2048)
|
87 | {
|
88 | Buffer_Write_Str(1, 0, 120, pBuffer);
|
89 | Buffer_To_Page(1, Page);
|
90 | eeprom_write_byte(0x00, Page);
|
91 | Page++;
|
92 | }
|
93 | else
|
94 | {
|
95 | Timer1_stop();
|
96 | }
|
97 | }
|
98 | }
|
99 | //************ADC Konfiguration**************
|
100 |
|
101 |
|
102 | int main(void)
|
103 | {
|
104 | sei();
|
105 | UART_init();
|
106 | ADC_init();
|
107 | Timer1_init();
|
108 | DF_SPI_init();
|
109 | Page = eeprom_read_byte(0x00);
|
110 | while(1)
|
111 | {
|
112 | if(!(PIND & (1<<PD0)))
|
113 | {
|
114 | Timer1_start();
|
115 | }
|
116 | if(!(PIND & (1<<PD1)))
|
117 | {
|
118 | Timer1_stop();
|
119 | }
|
120 | if(!(PIND & (1<<PD2)))
|
121 | {
|
122 | int16_t i = -1;
|
123 | while(i < Page)
|
124 | {
|
125 | Page_To_Buffer(i, 1);
|
126 | Buffer_Read_Str(1, 0, 120, pBuffer);
|
127 | uart_puts(pBuffer);
|
128 | }
|
129 | }
|
130 | if(!(PIND & (1<<PD3)))
|
131 | {
|
132 | eeprom_write_byte(0x00, 0);
|
133 | }
|
134 | }
|
135 | return(0);
|
136 | }
|