aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Christian Pohle2017-05-20 19:08:44 +0200
committerMax Christian Pohle2017-05-20 19:08:44 +0200
commite22453c44e0b88f47cd16f6dd1a769bd4ff90203 (patch)
treebdbb67cfe1d607ac0ff3d7e42a5879bf3bfec3fd
downloadbinwatch-mini-e22453c44e0b88f47cd16f6dd1a769bd4ff90203.tar.bz2
binwatch-mini-e22453c44e0b88f47cd16f6dd1a769bd4ff90203.zip
First prototype version: Just shift register usage.
-rw-r--r--Makefile6
-rw-r--r--main.c164
2 files changed, 170 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e8d2720
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,6 @@
1all:
2 avr-gcc -Wall -mmcu=attiny85 -O3 -o main.elf main.c
3 avr-objcopy -j .text -j .data -O ihex main.elf main.hex
4
5program: all
6 avrdude -B100 -p t85 -c avrisp2 -P usb -U flash:w:main.hex
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..7906126
--- /dev/null
+++ b/main.c
@@ -0,0 +1,164 @@
1#include <avr/io.h> // (1)
2#include <avr/interrupt.h>
3
4#ifndef F_CPU
5#warning "F_CPU war noch nicht definiert, wird nun mit 3686400 definiert"
6// #define F_CPU 3686400UL /* Quarz mit 3.6864 Mhz */
7#define F_CPU 1000000UL /* Quarz mit 3.6864 Mhz */
8#endif
9
10#include <util/delay.h>
11#include <stdint.h>
12
13
14// set bit
15static inline void BIT_SET(volatile uint8_t *target, uint8_t bit) __attribute__((always_inline));
16static inline void BIT_SET(volatile uint8_t *target, uint8_t bit){
17 *target |= (1<<bit);
18};
19
20// set clear
21static inline void BIT_CLEAR(volatile uint8_t *target, uint8_t bit) __attribute__((always_inline));
22static inline void BIT_CLEAR(volatile uint8_t *target, uint8_t bit){
23 *target &= ~(1<<bit);
24};
25
26///* -----------------------------------------------------------------------------------------------------------*/
27///*! Eine schnelle MEM->SPI Blocksende Routine mit optimierungen auf Speed.
28// * \param buffer Zeiger auf den Puffer der gesendet werden soll.
29// * \param Datalenght Anzahl der Bytes die gesedet werden soll.
30// */
31///* -----------------------------------------------------------------------------------------------------------*/
32//void SPI_FastMem2Write( unsigned char * buffer, unsigned int Datalenght )
33//{
34// unsigned int Counter = 0;
35// unsigned char data;
36//
37// // erten Wert senden
38// SPDR = buffer[ Counter++ ];
39// while( Counter < Datalenght )
40// {
41// // Wert schon mal in Register holen, schneller da der Wert jetzt in einem Register steht und nicht mehr aus dem RAM geholt werden muss
42// // nachdem das senden des vorherigen Wertes fertig ist,
43// data = buffer[ Counter ];
44// // warten auf fertig
45// while(!(SPSR & (1<<SPIF)));
46// // Wert aus Register senden
47// SPDR = data;
48// Counter++;
49// }
50// while(!(SPSR & (1<<SPIF)));
51// return;
52//}
53uint8_t spi_transfer(uint8_t data) {
54 USIDR = data;
55 USISR = _BV(USIOIF); // clear flag
56
57 while ( (USISR & _BV(USIOIF)) == 0 ) {
58 USICR = (1<<USIWM0)|(1<<USICS1)|(1<<USICLK)|(1<<USITC);
59 }
60 return USIDR;
61}
62
63void pulse_sck()
64{
65 PORTB |= ( 1 << PB2 );
66 _delay_ms(10); // Eine Sekunde +/-1/10000 Sekunde warten...
67 PORTB ^= ( 1 << PB2 );
68}
69
70void print_data(uint16_t data)
71{
72 BIT_CLEAR(&PORTB, PB4);
73 _delay_ms(100);
74 BIT_SET(&PORTB, PB4);
75
76 for(int i=0; i<16; i++)
77 {
78 if(data<<i & 0b1000000000000000)
79 BIT_SET(&PORTB, PB4);
80 pulse_sck();
81 BIT_CLEAR(&PORTB, PB4);
82 //PORTB &= (1 << PB4);
83 }
84 //pulse_sck();
85
86
87 BIT_CLEAR(&PORTB, PB3);
88 _delay_ms(50);
89 BIT_SET(&PORTB, PB3);
90}
91
92
93int main (void) {
94
95 //DDRB |= _BV(PB4); // as output (latch)
96 //DDRB |= _BV(PB6); // as output (DO) - data out
97 //DDRB |= _BV(PB7); // as output (USISCK) - clock
98 _delay_ms(1000);
99 // DDRB = (1<<PB0) | (1<<PB2) | (1<<PB3) | (1<<PB4) | (1<<PB5); // PB0 an PORTB als Ausgang setzen
100 DDRB = 0xFF;
101
102
103 BIT_CLEAR(&PORTB, PB5);
104 _delay_ms(500);
105 BIT_SET(&PORTB, PB5);
106 BIT_CLEAR(&PORTB, PB5);
107 _delay_ms(500);
108 BIT_SET(&PORTB, PB5);
109 //DDRB &= ~_BV(PB5); // as input (DI) - data in
110 //PORTB |= _BV(PB5); // pullup on (DI)
111
112 while( 1 )
113 { // Endlosschleife
114
115 _delay_ms(1000); // Eine Sekunde +/-1/10000 Sekunde warten...
116
117
118 // char data = 0b10101010;
119 // char data = 0b11001101;
120 // char data = 0b10101100;
121 //
122 //
123 //
124 //
125 //
126 //
127 //
128 //
129
130 print_data(0x0001);
131 print_data(0x0002);
132 print_data(0x0004);
133 print_data(0x0008);
134 print_data(0x000F);
135 print_data(0xFF00);
136 print_data(0x00FF);
137 print_data(0xFF00);
138 print_data(0x00FF);
139 print_data(0xFF00);
140
141 uint16_t data;
142 for(int i=0; i<16; i++)
143 print_data(1<<i);
144 for(int i=0; i<16; i++)
145 print_data(0X8000>>i);
146
147 /*
148
149 char data = 1;
150 for(; data<128; data++)
151 {
152 // clear register (reset)
153 print_data(data);
154 _delay_ms(1000);
155 }
156
157 */
158
159 // spi_transfer(0x10101010b);
160
161
162 }
163 return 0;
164}
..