Subversion Repositories group.electronics

Rev

Rev 123 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 123 Rev 126
Line 1... Line 1...
1
#include <avr/io.h>
1
#include <avr/io.h>
2
 
-
 
3
#include "avrutil.h"
2
#include <avr/wdt.h>
-
 
3
#include <avr/interrupt.h>
-
 
4
#include <string.h>
4
#include <util/delay.h>
5
#include <util/delay.h>
5
 
-
 
6
#include <stdlib.h>
6
#include <stdlib.h>
7
 
7
 
-
 
8
#include "avrutil.h"
-
 
9
 
8
inline uint8_t map_8(uint8_t x, uint8_t in_min, uint8_t in_max, uint8_t out_min, uint8_t out_max) {
10
inline uint8_t map_8(uint8_t x, uint8_t in_min, uint8_t in_max, uint8_t out_min, uint8_t out_max) {
9
	return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
11
	return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
10
}
12
}
11
 
13
 
12
inline void delay_ms(uint16_t count) {
14
inline void delay_ms(uint16_t count) {
Line 18... Line 20...
18
  sbi(port, pin);
20
  sbi(port, pin);
19
  delay_ms(count);
21
  delay_ms(count);
20
  cbi(port, pin);
22
  cbi(port, pin);
21
}
23
}
22
 
24
 
-
 
25
void statusLed(uint8_t state) {
-
 
26
	if (state)
-
 
27
		sbi(PORTD, PD6);
-
 
28
	else
-
 
29
		cbi(PORTD, PD6);
-
 
30
}
-
 
31
 
23
uint8_t analogRead(uint8_t channel) {
32
uint8_t analogRead(uint8_t channel) {
24
        ADMUX = (1<<ADLAR) | (1<<REFS0) | (0<<REFS1) | (channel & 0x0f);
33
        ADMUX = (1<<ADLAR) | (1<<REFS0) | (0<<REFS1) | (channel & 0x0f);
25
        ADCSRA |= (1<<ADSC);            // Start converting
34
        ADCSRA |= (1<<ADSC);            // Start converting
26
 
35
 
27
        while (((ADCSRA >> ADSC) & 1)) {}       //Wait until conversion finished
36
        while (((ADCSRA >> ADSC) & 1)) {}       //Wait until conversion finished
Line 53... Line 62...
53
	TCCR0B = (1<< CS00) ;		// /1 prescaler
62
	TCCR0B = (1<< CS00) ;		// /1 prescaler
54
	
63
	
55
	//tick_addr = func;
64
	//tick_addr = func;
56
}
65
}
57
 
66
 
-
 
67
void swap_u8(uint8_t* a, uint8_t* b) {
-
 
68
	uint8_t t = *b;
-
 
69
	*b = *a;
-
 
70
	*a = t;
-
 
71
}
-
 
72
 
-
 
73
void swap_u16(uint16_t* a, uint16_t* b) {
-
 
74
	uint16_t t = *b;
-
 
75
	*b = *a;
-
 
76
	*a = t;
-
 
77
}
-
 
78