PIO hinzugefügt
This commit is contained in:
parent
99c282566f
commit
419e37eeae
62
B15F.hex
62
B15F.hex
|
@ -7,62 +7,8 @@
|
|||
:100060000C9450000C9450000C9450000C945000D0
|
||||
:100070000C9450000C9450000C9450000C945000C0
|
||||
:100080000C9450000C9450000C94500011241FBE8E
|
||||
:10009000CFEFD0E4DEBFCDBF0E9452000C940F0220
|
||||
:1000A0000C940000CF93DF9300D0CDB7DEB7CE0124
|
||||
:1000B00001960E94620080E090E00F900F90DF9127
|
||||
:1000C000CF910895CF93DF93CDB7DEB760970FB68A
|
||||
:1000D000F894DEBF0FBECDBF988B8F8784E290E08F
|
||||
:1000E00024E230E0F90120812160FC01208385E2D7
|
||||
:1000F00090E025E230E0F901308121E02327FC0186
|
||||
:10010000208380E090E0A0E8BFE389839A83AB83FB
|
||||
:10011000BC8320E030E44CE955E469817A818B812D
|
||||
:100120009C810E947A01DC01CB018D839E83AF8389
|
||||
:10013000B88720E030E040E85FE36D817E818F8109
|
||||
:1001400098850E94F40088232CF481E090E09A873F
|
||||
:1001500089873FC020E03FEF4FE757E46D817E8104
|
||||
:100160008F8198850E94750118164CF520E030E0CB
|
||||
:1001700040E251E469817A818B819C810E947A01FD
|
||||
:10018000DC01CB01BC01CD010E94F900DC01CB01F7
|
||||
:100190009A87898789859A85892B09F4A8CF84EF66
|
||||
:1001A00091E09C878B878B859C850197F1F79C87D5
|
||||
:1001B0008B8789859A8501979A878987EBCF6D818F
|
||||
:1001C0007E818F8198850E94F900DC01CB019A879E
|
||||
:1001D000898789859A859E878D878D859E850197DC
|
||||
:1001E000F1F79E878D8783CF0E94280108F481E074
|
||||
:1001F00008950E94540188F09F5798F0B92F9927CD
|
||||
:10020000B751B0F0E1F0660F771F881F991F1AF001
|
||||
:10021000BA95C9F714C0B13091F00E946E01B1E0F7
|
||||
:1002200008950C946E01672F782F8827B85F39F0F6
|
||||
:10023000B93FCCF3869577956795B395D9F73EF49A
|
||||
:1002400090958095709561957F4F8F4F9F4F089542
|
||||
:10025000990F0008550FAA0BE0E8FEEF16161706D7
|
||||
:10026000E807F907C0F012161306E407F50798F03F
|
||||
:10027000621B730B840B950B39F40A2661F0232B58
|
||||
:10028000242B252B21F408950A2609F4A140A695D4
|
||||
:100290008FEF811D811D089557FD9058440F551F04
|
||||
:1002A00059F05F3F71F04795880F97FB991F61F0F8
|
||||
:1002B0009F3F79F087950895121613061406551F6F
|
||||
:1002C000F2CF4695F1DF08C0161617061806991FDB
|
||||
:1002D000F1CF86957105610508940895E894BB27D0
|
||||
:1002E00066277727CB0197F908950E94280108F423
|
||||
:1002F0008FEF08950E948D010C94FE010E94F00181
|
||||
:1003000038F00E94F70120F0952311F00C94E701DA
|
||||
:100310000C94ED0111240C946F010E944C0170F3B8
|
||||
:10032000959FC1F3950F50E0551F629FF001729F9A
|
||||
:10033000BB27F00DB11D639FAA27F00DB11DAA1FA9
|
||||
:10034000649F6627B00DA11D661F829F2227B00DF6
|
||||
:10035000A11D621F739FB00DA11D621F839FA00D81
|
||||
:10036000611D221F749F3327A00D611D231F849FD1
|
||||
:10037000600D211D822F762F6A2F11249F57504028
|
||||
:100380009AF0F1F088234AF0EE0FFF1FBB1F661FA3
|
||||
:10039000771F881F91505040A9F79E3F510580F06C
|
||||
:1003A0000C94E7010C946F015F3FE4F3983ED4F3A3
|
||||
:1003B000869577956795B795F795E7959F5FC1F710
|
||||
:1003C000FE2B880F911D9695879597F9089597F9BB
|
||||
:1003D0009F6780E870E060E008959FEF80EC0895EB
|
||||
:1003E00000240A9416161706180609060895002414
|
||||
:1003F0000A9412161306140605060895092E03948E
|
||||
:10040000000C11F4882352F0BB0F40F4BF2B11F401
|
||||
:1004100060FF04C06F5F7F4F8F4F9F4F0895F89428
|
||||
:02042000FFCF0C
|
||||
:10009000CFEFD0E4DEBFCDBF0E9457000C946600C6
|
||||
:1000A0000C9400000895259A2698279A0895CF93D6
|
||||
:1000B000DF931F92CDB7DEB7CE0101960E945200AA
|
||||
:1000C00080E090E00F90DF91CF910895F894FFCFFA
|
||||
:00000001FF
|
||||
|
|
12
Makefile
12
Makefile
|
@ -8,11 +8,11 @@ COMPILER_PATH = C:\avr8-gnu-toolchain-win32_x86\bin\avr-g++.exe
|
|||
OBJCOPY_PATH = C:\avr8-gnu-toolchain-win32_x86\bin\avr-objcopy.exe
|
||||
|
||||
|
||||
OUTPUT = B15F.elf
|
||||
OUTPUT = B15F.elf
|
||||
HEX = B15F.hex
|
||||
CFLAGS = -std=c++14 -mmcu=atmega1284 -DF_CPU=20000000
|
||||
CFLAGS = -std=c++14 -O3 -mmcu=atmega1284 -DF_CPU=20000000 -DPIO_DISABLE_I2C
|
||||
LDFLAGS =
|
||||
OBJECTS = main.o spi.o
|
||||
OBJECTS = main.o spi.o
|
||||
|
||||
|
||||
COMPILE = $(COMPILER_PATH) $(CFLAGS)
|
||||
|
@ -24,13 +24,13 @@ B15F: $(OBJECTS)
|
|||
$(OBJCOPY_PATH) -O ihex -R .eeprom -R .fuse -R .lock -R .signature $(OUTPUT) $(HEX)
|
||||
|
||||
help:
|
||||
@echo "This Makefile has the following rules. Use one of the following:"
|
||||
@echo "This Makefile has the following rules:"
|
||||
@echo "make B15F .... to compile (default)"
|
||||
@echo "make clean ... to delete objects and hex file"
|
||||
@echo "make clean ... to delete objects, elf and hex file"
|
||||
|
||||
clean:
|
||||
@echo "Cleaning..."
|
||||
rm -f $(OBJECTS) $(OUTPUT)
|
||||
rm -f $(OBJECTS) $(OUTPUT) $(HEX)
|
||||
|
||||
.cpp.o:
|
||||
$(COMPILE) -c $< -o $@
|
||||
|
|
95
pio.h
Normal file
95
pio.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
/***
|
||||
* _______ _____ ___
|
||||
* |_ __ \|_ _|.' `.
|
||||
* | |__) | | | / .-. \
|
||||
* | ___/ | | | | | |
|
||||
* _| |_ _| |_\ `-' /
|
||||
* |_____| |_____|`.___.'
|
||||
*
|
||||
* Preprocessor I/O Library
|
||||
*
|
||||
* ~ version 1.0.0
|
||||
* ~ written by Tristan Krause
|
||||
* ~ visit www.devfix.net
|
||||
*
|
||||
* You should have received a copy of the MIT License.
|
||||
* If not, see <https://opensource.org/licenses/MIT>.
|
||||
*
|
||||
* How does it work?
|
||||
* ----------------------------------------------
|
||||
* Instead of the classical way
|
||||
* (1a) DDRA |= (1<<PA0);
|
||||
* you can now write
|
||||
* (1b) dMode(A0, OUT);
|
||||
*
|
||||
* It gets directly replaced by the fast
|
||||
* PORT manipulation command (1a) using
|
||||
* preprocessor macros. This way, PIO
|
||||
* does not increase the overall memory
|
||||
* consumption or slow down the execution
|
||||
* like Arduino does.
|
||||
*
|
||||
* Why using PIO? The Port commands are enough...
|
||||
* ----------------------------------------------
|
||||
* First, the code gets a bit more readable,
|
||||
* especially for beginners.
|
||||
* Second, you can define pins regardless
|
||||
* their corresponding port, resulting in
|
||||
* a more flexible code. For instance:
|
||||
* (2a) #define LED A0
|
||||
* dMode(LED, OUT);
|
||||
* dWrite(LED, HIGH);
|
||||
* If you now choose another pin, the rest
|
||||
* of the code can stay the same and PIO
|
||||
* will take care of the right PORT commands.
|
||||
* (2b) #define LED D6 // this changed
|
||||
* dMode(LED, OUT); // same command
|
||||
* dWrite(LED, HIGH); // same command
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PIO_H
|
||||
#define PIO_H
|
||||
|
||||
// current version
|
||||
#define PIOLIB 100
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
#ifdef HIGH
|
||||
#undef HIGH
|
||||
#endif
|
||||
#define HIGH 1
|
||||
|
||||
#ifndef LOW
|
||||
#undef LOW
|
||||
#endif
|
||||
#define LOW 0
|
||||
|
||||
#ifndef OUT
|
||||
#undef OUT
|
||||
#endif
|
||||
#define OUT 1
|
||||
|
||||
#ifndef OUTPUT
|
||||
#undef OUTPUT
|
||||
#endif
|
||||
#define OUTPUT 1
|
||||
|
||||
#ifndef IN
|
||||
#undef IN
|
||||
#endif
|
||||
#define IN 0
|
||||
|
||||
#ifndef INPUT
|
||||
#undef INPUT
|
||||
#endif
|
||||
#define INPUT 0
|
||||
|
||||
#include "pio/dmode.h"
|
||||
#include "pio/dwrite.h"
|
||||
#include "pio/dread.h"
|
||||
|
||||
#include "pio/mcus.h"
|
||||
|
||||
#endif // PIO_H
|
248
pio/dmode.h
Normal file
248
pio/dmode.h
Normal file
|
@ -0,0 +1,248 @@
|
|||
/***
|
||||
* dmode.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifndef PIO_DMODE_H
|
||||
#define PIO_DMODE_H
|
||||
|
||||
#define dMode(A, B) dMode_(A, B)
|
||||
#define dMode_(A, B) DMODE ## _ ## A ## _ ## B
|
||||
|
||||
#ifdef PA0
|
||||
#define DMODE_A0_1 DDRA |= 0x01
|
||||
#define DMODE_A0_0 DDRA &= 0xFE
|
||||
#else
|
||||
#define DMODE_A0_1 # Pin A0 not supported on this MCU!
|
||||
#define DMODE_A0_0 DMODE_A0_1
|
||||
#endif
|
||||
#ifdef PA1
|
||||
#define DMODE_A1_1 DDRA |= 0x02
|
||||
#define DMODE_A1_0 DDRA &= 0xFD
|
||||
#else
|
||||
#define DMODE_A1_1 # Pin A1 not supported on this MCU!
|
||||
#define DMODE_A1_0 DMODE_A1_1
|
||||
#endif
|
||||
#ifdef PA2
|
||||
#define DMODE_A2_1 DDRA |= 0x04
|
||||
#define DMODE_A2_0 DDRA &= 0xFB
|
||||
#else
|
||||
#define DMODE_A2_1 # Pin A2 not supported on this MCU!
|
||||
#define DMODE_A2_0 DMODE_A2_1
|
||||
#endif
|
||||
#ifdef PA3
|
||||
#define DMODE_A3_1 DDRA |= 0x08
|
||||
#define DMODE_A3_0 DDRA &= 0xF7
|
||||
#else
|
||||
#define DMODE_A3_1 # Pin A3 not supported on this MCU!
|
||||
#define DMODE_A3_0 DMODE_A3_1
|
||||
#endif
|
||||
#ifdef PA4
|
||||
#define DMODE_A4_1 DDRA |= 0x10
|
||||
#define DMODE_A4_0 DDRA &= 0xEF
|
||||
#else
|
||||
#define DMODE_A4_1 # Pin A4 not supported on this MCU!
|
||||
#define DMODE_A4_0 DMODE_A4_1
|
||||
#endif
|
||||
#ifdef PA5
|
||||
#define DMODE_A5_1 DDRA |= 0x20
|
||||
#define DMODE_A5_0 DDRA &= 0xDF
|
||||
#else
|
||||
#define DMODE_A5_1 # Pin A5 not supported on this MCU!
|
||||
#define DMODE_A5_0 DMODE_A5_1
|
||||
#endif
|
||||
#ifdef PA6
|
||||
#define DMODE_A6_1 DDRA |= 0x40
|
||||
#define DMODE_A6_0 DDRA &= 0xBF
|
||||
#else
|
||||
#define DMODE_A6_1 # Pin A6 not supported on this MCU!
|
||||
#define DMODE_A6_0 DMODE_A6_1
|
||||
#endif
|
||||
#ifdef PA7
|
||||
#define DMODE_A7_1 DDRA |= 0x80
|
||||
#define DMODE_A7_0 DDRA &= 0x7F
|
||||
#else
|
||||
#define DMODE_A7_1 # Pin A7 not supported on this MCU!
|
||||
#define DMODE_A7_0 DMODE_A7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PB0
|
||||
#define DMODE_B0_1 DDRB |= 0x01
|
||||
#define DMODE_B0_0 DDRB &= 0xFE
|
||||
#else
|
||||
#define DMODE_B0_1 # Pin B0 not supported on this MCU!
|
||||
#define DMODE_B0_0 DMODE_B0_1
|
||||
#endif
|
||||
#ifdef PB1
|
||||
#define DMODE_B1_1 DDRB |= 0x02
|
||||
#define DMODE_B1_0 DDRB &= 0xFD
|
||||
#else
|
||||
#define DMODE_B1_1 # Pin B1 not supported on this MCU!
|
||||
#define DMODE_B1_0 DMODE_B1_1
|
||||
#endif
|
||||
#ifdef PB2
|
||||
#define DMODE_B2_1 DDRB |= 0x04
|
||||
#define DMODE_B2_0 DDRB &= 0xFB
|
||||
#else
|
||||
#define DMODE_B2_1 # Pin B2 not supported on this MCU!
|
||||
#define DMODE_B2_0 DMODE_B2_1
|
||||
#endif
|
||||
#ifdef PB3
|
||||
#define DMODE_B3_1 DDRB |= 0x08
|
||||
#define DMODE_B3_0 DDRB &= 0xF7
|
||||
#else
|
||||
#define DMODE_B3_1 # Pin B3 not supported on this MCU!
|
||||
#define DMODE_B3_0 DMODE_B3_1
|
||||
#endif
|
||||
#ifdef PB4
|
||||
#define DMODE_B4_1 DDRB |= 0x10
|
||||
#define DMODE_B4_0 DDRB &= 0xEF
|
||||
#else
|
||||
#define DMODE_B4_1 # Pin B4 not supported on this MCU!
|
||||
#define DMODE_B4_0 DMODE_B4_1
|
||||
#endif
|
||||
#ifdef PB5
|
||||
#define DMODE_B5_1 DDRB |= 0x20
|
||||
#define DMODE_B5_0 DDRB &= 0xDF
|
||||
#else
|
||||
#define DMODE_B5_1 # Pin B5 not supported on this MCU!
|
||||
#define DMODE_B5_0 DMODE_B5_1
|
||||
#endif
|
||||
#ifdef PB6
|
||||
#define DMODE_B6_1 DDRB |= 0x40
|
||||
#define DMODE_B6_0 DDRB &= 0xBF
|
||||
#else
|
||||
#define DMODE_B6_1 # Pin B6 not supported on this MCU!
|
||||
#define DMODE_B6_0 DMODE_B6_1
|
||||
#endif
|
||||
#ifdef PB7
|
||||
#define DMODE_B7_1 DDRB |= 0x80
|
||||
#define DMODE_B7_0 DDRB &= 0x7F
|
||||
#else
|
||||
#define DMODE_B7_1 # Pin B7 not supported on this MCU!
|
||||
#define DMODE_B7_0 DMODE_B7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PC0
|
||||
#define DMODE_C0_1 DDRC |= 0x01
|
||||
#define DMODE_C0_0 DDRC &= 0xFE
|
||||
#else
|
||||
#define DMODE_C0_1 # Pin C0 not supported on this MCU!
|
||||
#define DMODE_C0_0 DMODE_C0_1
|
||||
#endif
|
||||
#ifdef PC1
|
||||
#define DMODE_C1_1 DDRC |= 0x02
|
||||
#define DMODE_C1_0 DDRC &= 0xFD
|
||||
#else
|
||||
#define DMODE_C1_1 # Pin C1 not supported on this MCU!
|
||||
#define DMODE_C1_0 DMODE_C1_1
|
||||
#endif
|
||||
#ifdef PC2
|
||||
#define DMODE_C2_1 DDRC |= 0x04
|
||||
#define DMODE_C2_0 DDRC &= 0xFB
|
||||
#else
|
||||
#define DMODE_C2_1 # Pin C2 not supported on this MCU!
|
||||
#define DMODE_C2_0 DMODE_C2_1
|
||||
#endif
|
||||
#ifdef PC3
|
||||
#define DMODE_C3_1 DDRC |= 0x08
|
||||
#define DMODE_C3_0 DDRC &= 0xF7
|
||||
#else
|
||||
#define DMODE_C3_1 # Pin C3 not supported on this MCU!
|
||||
#define DMODE_C3_0 DMODE_C3_1
|
||||
#endif
|
||||
#ifdef PC4
|
||||
#define DMODE_C4_1 DDRC |= 0x10
|
||||
#define DMODE_C4_0 DDRC &= 0xEF
|
||||
#else
|
||||
#define DMODE_C4_1 # Pin C4 not supported on this MCU!
|
||||
#define DMODE_C4_0 DMODE_C4_1
|
||||
#endif
|
||||
#ifdef PC5
|
||||
#define DMODE_C5_1 DDRC |= 0x20
|
||||
#define DMODE_C5_0 DDRC &= 0xDF
|
||||
#else
|
||||
#define DMODE_C5_1 # Pin C5 not supported on this MCU!
|
||||
#define DMODE_C5_0 DMODE_C5_1
|
||||
#endif
|
||||
#ifdef PC6
|
||||
#define DMODE_C6_1 DDRC |= 0x40
|
||||
#define DMODE_C6_0 DDRC &= 0xBF
|
||||
#else
|
||||
#define DMODE_C6_1 # Pin C6 not supported on this MCU!
|
||||
#define DMODE_C6_0 DMODE_C6_1
|
||||
#endif
|
||||
#ifdef PC7
|
||||
#define DMODE_C7_1 DDRC |= 0x80
|
||||
#define DMODE_C7_0 DDRC &= 0x7F
|
||||
#else
|
||||
#define DMODE_C7_1 # Pin C7 not supported on this MCU!
|
||||
#define DMODE_C7_0 DMODE_C7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PD0
|
||||
#define DMODE_D0_1 DDRD |= 0x01
|
||||
#define DMODE_D0_0 DDRD &= 0xFE
|
||||
#else
|
||||
#define DMODE_D0_1 # Pin D0 not supported on this MCU!
|
||||
#define DMODE_D0_0 DMODE_D0_1
|
||||
#endif
|
||||
#ifdef PD1
|
||||
#define DMODE_D1_1 DDRD |= 0x02
|
||||
#define DMODE_D1_0 DDRD &= 0xFD
|
||||
#else
|
||||
#define DMODE_D1_1 # Pin D1 not supported on this MCU!
|
||||
#define DMODE_D1_0 DMODE_D1_1
|
||||
#endif
|
||||
#ifdef PD2
|
||||
#define DMODE_D2_1 DDRD |= 0x04
|
||||
#define DMODE_D2_0 DDRD &= 0xFB
|
||||
#else
|
||||
#define DMODE_D2_1 # Pin D2 not supported on this MCU!
|
||||
#define DMODE_D2_0 DMODE_D2_1
|
||||
#endif
|
||||
#ifdef PD3
|
||||
#define DMODE_D3_1 DDRD |= 0x08
|
||||
#define DMODE_D3_0 DDRD &= 0xF7
|
||||
#else
|
||||
#define DMODE_D3_1 # Pin D3 not supported on this MCU!
|
||||
#define DMODE_D3_0 DMODE_D3_1
|
||||
#endif
|
||||
#ifdef PD4
|
||||
#define DMODE_D4_1 DDRD |= 0x10
|
||||
#define DMODE_D4_0 DDRD &= 0xEF
|
||||
#else
|
||||
#define DMODE_D4_1 # Pin D4 not supported on this MCU!
|
||||
#define DMODE_D4_0 DMODE_D4_1
|
||||
#endif
|
||||
#ifdef PD5
|
||||
#define DMODE_D5_1 DDRD |= 0x20
|
||||
#define DMODE_D5_0 DDRD &= 0xDF
|
||||
#else
|
||||
#define DMODE_D5_1 # Pin D5 not supported on this MCU!
|
||||
#define DMODE_D5_0 DMODE_D5_1
|
||||
#endif
|
||||
#ifdef PD6
|
||||
#define DMODE_D6_1 DDRD |= 0x40
|
||||
#define DMODE_D6_0 DDRD &= 0xBF
|
||||
#else
|
||||
#define DMODE_D6_1 # Pin D6 not supported on this MCU!
|
||||
#define DMODE_D6_0 DMODE_D6_1
|
||||
#endif
|
||||
#ifdef PD7
|
||||
#define DMODE_D7_1 DDRD |= 0x80
|
||||
#define DMODE_D7_0 DDRD &= 0x7F
|
||||
#else
|
||||
#define DMODE_D7_1 # Pin D7 not supported on this MCU!
|
||||
#define DMODE_D7_0 DMODE_D7_1
|
||||
#endif
|
||||
|
||||
#endif // PIO_DMODE_H
|
183
pio/dread.h
Normal file
183
pio/dread.h
Normal file
|
@ -0,0 +1,183 @@
|
|||
/***
|
||||
* dread.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifndef PIO_DREAD_H
|
||||
#define PIO_DREAD_H
|
||||
|
||||
#define dRead(A) dRead_(A)
|
||||
#define dRead_(A) DREAD ## _ ## A
|
||||
|
||||
#ifdef PA0
|
||||
#define DREAD_A0 (PINA & 0x01)
|
||||
#else
|
||||
#define DREAD_A0 # Pin A0 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA1
|
||||
#define DREAD_A1 (PINA & 0x02)
|
||||
#else
|
||||
#define DREAD_A1 # Pin A1 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA2
|
||||
#define DREAD_A2 (PINA & 0x04)
|
||||
#else
|
||||
#define DREAD_A2 # Pin A2 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA3
|
||||
#define DREAD_A3 (PINA & 0x08)
|
||||
#else
|
||||
#define DREAD_A3 # Pin A3 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA4
|
||||
#define DREAD_A4 (PINA & 0x10)
|
||||
#else
|
||||
#define DREAD_A4 # Pin A4 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA5
|
||||
#define DREAD_A5 (PINA & 0x20)
|
||||
#else
|
||||
#define DREAD_A5 # Pin A5 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA6
|
||||
#define DREAD_A6 (PINA & 0x40)
|
||||
#else
|
||||
#define DREAD_A6 # Pin A6 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PA7
|
||||
#define DREAD_A7 (PINA & 0x80)
|
||||
#else
|
||||
#define DREAD_A7 # Pin A7 not supported on this MCU!
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PB0
|
||||
#define DREAD_B0 (PINB & 0x01)
|
||||
#else
|
||||
#define DREAD_B0 # Pin B0 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB1
|
||||
#define DREAD_B1 (PINB & 0x02)
|
||||
#else
|
||||
#define DREAD_B1 # Pin B1 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB2
|
||||
#define DREAD_B2 (PINB & 0x04)
|
||||
#else
|
||||
#define DREAD_B2 # Pin B2 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB3
|
||||
#define DREAD_B3 (PINB & 0x08)
|
||||
#else
|
||||
#define DREAD_B3 # Pin B3 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB4
|
||||
#define DREAD_B4 (PINB & 0x10)
|
||||
#else
|
||||
#define DREAD_B4 # Pin B4 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB5
|
||||
#define DREAD_B5 (PINB & 0x20)
|
||||
#else
|
||||
#define DREAD_B5 # Pin B5 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB6
|
||||
#define DREAD_B6 (PINB & 0x40)
|
||||
#else
|
||||
#define DREAD_B6 # Pin B6 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PB7
|
||||
#define DREAD_B7 (PINB & 0x80)
|
||||
#else
|
||||
#define DREAD_B7 # Pin B7 not supported on this MCU!
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PC0
|
||||
#define DREAD_C0 (PINC & 0x01)
|
||||
#else
|
||||
#define DREAD_C0 # Pin C0 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC1
|
||||
#define DREAD_C1 (PINC & 0x02)
|
||||
#else
|
||||
#define DREAD_C1 # Pin C1 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC2
|
||||
#define DREAD_C2 (PINC & 0x04)
|
||||
#else
|
||||
#define DREAD_C2 # Pin C2 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC3
|
||||
#define DREAD_C3 (PINC & 0x08)
|
||||
#else
|
||||
#define DREAD_C3 # Pin C3 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC4
|
||||
#define DREAD_C4 (PINC & 0x10)
|
||||
#else
|
||||
#define DREAD_C4 # Pin C4 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC5
|
||||
#define DREAD_C5 (PINC & 0x20)
|
||||
#else
|
||||
#define DREAD_C5 # Pin C5 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC6
|
||||
#define DREAD_C6 (PINC & 0x40)
|
||||
#else
|
||||
#define DREAD_C6 # Pin C6 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PC7
|
||||
#define DREAD_C7 (PINC & 0x80)
|
||||
#else
|
||||
#define DREAD_C7 # Pin C7 not supported on this MCU!
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PD0
|
||||
#define DREAD_D0 (PIND & 0x01)
|
||||
#else
|
||||
#define DREAD_D0 # Pin D0 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD1
|
||||
#define DREAD_D1 (PIND & 0x02)
|
||||
#else
|
||||
#define DREAD_D1 # Pin D1 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD2
|
||||
#define DREAD_D2 (PIND & 0x04)
|
||||
#else
|
||||
#define DREAD_D2 # Pin D2 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD3
|
||||
#define DREAD_D3 (PIND & 0x08)
|
||||
#else
|
||||
#define DREAD_D3 # Pin D3 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD4
|
||||
#define DREAD_D4 (PIND & 0x10)
|
||||
#else
|
||||
#define DREAD_D4 # Pin D4 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD5
|
||||
#define DREAD_D5 (PIND & 0x20)
|
||||
#else
|
||||
#define DREAD_D5 # Pin D5 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD6
|
||||
#define DREAD_D6 (PIND & 0x40)
|
||||
#else
|
||||
#define DREAD_D6 # Pin D6 not supported on this MCU!
|
||||
#endif
|
||||
#ifdef PD7
|
||||
#define DREAD_D7 (PIND & 0x80)
|
||||
#else
|
||||
#define DREAD_D7 # Pin D7 not supported on this MCU!
|
||||
#endif
|
||||
#endif // PIO_DREAD_H
|
249
pio/dwrite.h
Normal file
249
pio/dwrite.h
Normal file
|
@ -0,0 +1,249 @@
|
|||
/***
|
||||
* dwrite.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifndef PIO_DWRITE_H
|
||||
#define PIO_DWRITE_H
|
||||
|
||||
#define dWrite(A, B) dWrite_(A, B)
|
||||
#define dWrite_(A, B) DWRITE ## _ ## A ## _ ## B
|
||||
|
||||
#ifdef PA0
|
||||
#define DWRITE_A0_1 PORTA |= 0x01
|
||||
#define DWRITE_A0_0 PORTA &= 0xFE
|
||||
#else
|
||||
#define DWRITE_A0_1 # Pin A0 not supported on this MCU!
|
||||
#define DWRITE_A0_0 DWRITE_A0_1
|
||||
#endif
|
||||
#ifdef PA1
|
||||
#define DWRITE_A1_1 PORTA |= 0x02
|
||||
#define DWRITE_A1_0 PORTA &= 0xFD
|
||||
#else
|
||||
#define DWRITE_A1_1 # Pin A1 not supported on this MCU!
|
||||
#define DWRITE_A1_0 DWRITE_A1_1
|
||||
#endif
|
||||
#ifdef PA2
|
||||
#define DWRITE_A2_1 PORTA |= 0x04
|
||||
#define DWRITE_A2_0 PORTA &= 0xFB
|
||||
#else
|
||||
#define DWRITE_A2_1 # Pin A2 not supported on this MCU!
|
||||
#define DWRITE_A2_0 DWRITE_A2_1
|
||||
#endif
|
||||
#ifdef PA3
|
||||
#define DWRITE_A3_1 PORTA |= 0x08
|
||||
#define DWRITE_A3_0 PORTA &= 0xF7
|
||||
#else
|
||||
#define DWRITE_A3_1 # Pin A3 not supported on this MCU!
|
||||
#define DWRITE_A3_0 DWRITE_A3_1
|
||||
#endif
|
||||
#ifdef PA4
|
||||
#define DWRITE_A4_1 PORTA |= 0x10
|
||||
#define DWRITE_A4_0 PORTA &= 0xEF
|
||||
#else
|
||||
#define DWRITE_A4_1 # Pin A4 not supported on this MCU!
|
||||
#define DWRITE_A4_0 DWRITE_A4_1
|
||||
#endif
|
||||
#ifdef PA5
|
||||
#define DWRITE_A5_1 PORTA |= 0x20
|
||||
#define DWRITE_A5_0 PORTA &= 0xDF
|
||||
#else
|
||||
#define DWRITE_A5_1 # Pin A5 not supported on this MCU!
|
||||
#define DWRITE_A5_0 DWRITE_A5_1
|
||||
#endif
|
||||
#ifdef PA6
|
||||
#define DWRITE_A6_1 PORTA |= 0x40
|
||||
#define DWRITE_A6_0 PORTA &= 0xBF
|
||||
#else
|
||||
#define DWRITE_A6_1 # Pin A6 not supported on this MCU!
|
||||
#define DWRITE_A6_0 DWRITE_A6_1
|
||||
#endif
|
||||
#ifdef PA7
|
||||
#define DWRITE_A7_1 PORTA |= 0x80
|
||||
#define DWRITE_A7_0 PORTA &= 0x7F
|
||||
#else
|
||||
#define DWRITE_A7_1 # Pin A7 not supported on this MCU!
|
||||
#define DWRITE_A7_0 DWRITE_A7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PB0
|
||||
#define DWRITE_B0_1 PORTB |= 0x01
|
||||
#define DWRITE_B0_0 PORTB &= 0xFE
|
||||
#else
|
||||
#define DWRITE_B0_1 # Pin B0 not supported on this MCU!
|
||||
#define DWRITE_B0_0 DWRITE_B0_1
|
||||
#endif
|
||||
#ifdef PB1
|
||||
#define DWRITE_B1_1 PORTB |= 0x02
|
||||
#define DWRITE_B1_0 PORTB &= 0xFD
|
||||
#else
|
||||
#define DWRITE_B1_1 # Pin B1 not supported on this MCU!
|
||||
#define DWRITE_B1_0 DWRITE_B1_1
|
||||
#endif
|
||||
#ifdef PB2
|
||||
#define DWRITE_B2_1 PORTB |= 0x04
|
||||
#define DWRITE_B2_0 PORTB &= 0xFB
|
||||
#else
|
||||
#define DWRITE_B2_1 # Pin B2 not supported on this MCU!
|
||||
#define DWRITE_B2_0 DWRITE_B2_1
|
||||
#endif
|
||||
#ifdef PB3
|
||||
#define DWRITE_B3_1 PORTB |= 0x08
|
||||
#define DWRITE_B3_0 PORTB &= 0xF7
|
||||
#else
|
||||
#define DWRITE_B3_1 # Pin B3 not supported on this MCU!
|
||||
#define DWRITE_B3_0 DWRITE_B3_1
|
||||
#endif
|
||||
#ifdef PB4
|
||||
#define DWRITE_B4_1 PORTB |= 0x10
|
||||
#define DWRITE_B4_0 PORTB &= 0xEF
|
||||
#else
|
||||
#define DWRITE_B4_1 # Pin B4 not supported on this MCU!
|
||||
#define DWRITE_B4_0 DWRITE_B4_1
|
||||
#endif
|
||||
#ifdef PB5
|
||||
#define DWRITE_B5_1 PORTB |= 0x20
|
||||
#define DWRITE_B5_0 PORTB &= 0xDF
|
||||
#else
|
||||
#define DWRITE_B5_1 # Pin B5 not supported on this MCU!
|
||||
#define DWRITE_B5_0 DWRITE_B5_1
|
||||
#endif
|
||||
#ifdef PB6
|
||||
#define DWRITE_B6_1 PORTB |= 0x40
|
||||
#define DWRITE_B6_0 PORTB &= 0xBF
|
||||
#else
|
||||
#define DWRITE_B6_1 # Pin B6 not supported on this MCU!
|
||||
#define DWRITE_B6_0 DWRITE_B6_1
|
||||
#endif
|
||||
#ifdef PB7
|
||||
#define DWRITE_B7_1 PORTB |= 0x80
|
||||
#define DWRITE_B7_0 PORTB &= 0x7F
|
||||
#else
|
||||
#define DWRITE_B7_1 # Pin B7 not supported on this MCU!
|
||||
#define DWRITE_B7_0 DWRITE_B7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PC0
|
||||
#define DWRITE_C0_1 PORTC |= 0x01
|
||||
#define DWRITE_C0_0 PORTC &= 0xFE
|
||||
#else
|
||||
#define DWRITE_C0_1 # Pin C0 not supported on this MCU!
|
||||
#define DWRITE_C0_0 DWRITE_C0_1
|
||||
#endif
|
||||
#ifdef PC1
|
||||
#define DWRITE_C1_1 PORTC |= 0x02
|
||||
#define DWRITE_C1_0 PORTC &= 0xFD
|
||||
#else
|
||||
#define DWRITE_C1_1 # Pin C1 not supported on this MCU!
|
||||
#define DWRITE_C1_0 DWRITE_C1_1
|
||||
#endif
|
||||
#ifdef PC2
|
||||
#define DWRITE_C2_1 PORTC |= 0x04
|
||||
#define DWRITE_C2_0 PORTC &= 0xFB
|
||||
#else
|
||||
#define DWRITE_C2_1 # Pin C2 not supported on this MCU!
|
||||
#define DWRITE_C2_0 DWRITE_C2_1
|
||||
#endif
|
||||
#ifdef PC3
|
||||
#define DWRITE_C3_1 PORTC |= 0x08
|
||||
#define DWRITE_C3_0 PORTC &= 0xF7
|
||||
#else
|
||||
#define DWRITE_C3_1 # Pin C3 not supported on this MCU!
|
||||
#define DWRITE_C3_0 DWRITE_C3_1
|
||||
#endif
|
||||
#ifdef PC4
|
||||
#define DWRITE_C4_1 PORTC |= 0x10
|
||||
#define DWRITE_C4_0 PORTC &= 0xEF
|
||||
#else
|
||||
#define DWRITE_C4_1 # Pin C4 not supported on this MCU!
|
||||
#define DWRITE_C4_0 DWRITE_C4_1
|
||||
#endif
|
||||
#ifdef PC5
|
||||
#define DWRITE_C5_1 PORTC |= 0x20
|
||||
#define DWRITE_C5_0 PORTC &= 0xDF
|
||||
#else
|
||||
#define DWRITE_C5_1 # Pin C5 not supported on this MCU!
|
||||
#define DWRITE_C5_0 DWRITE_C5_1
|
||||
#endif
|
||||
#ifdef PC6
|
||||
#define DWRITE_C6_1 PORTC |= 0x40
|
||||
#define DWRITE_C6_0 PORTC &= 0xBF
|
||||
#else
|
||||
#define DWRITE_C6_1 # Pin C6 not supported on this MCU!
|
||||
#define DWRITE_C6_0 DWRITE_C6_1
|
||||
#endif
|
||||
#ifdef PC7
|
||||
#define DWRITE_C7_1 PORTC |= 0x80
|
||||
#define DWRITE_C7_0 PORTC &= 0x7F
|
||||
#else
|
||||
#define DWRITE_C7_1 # Pin C7 not supported on this MCU!
|
||||
#define DWRITE_C7_0 DWRITE_C7_1
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PD0
|
||||
#define DWRITE_D0_1 PORTD |= 0x01
|
||||
#define DWRITE_D0_0 PORTD &= 0xFE
|
||||
#else
|
||||
#define DWRITE_D0_1 # Pin D0 not supported on this MCU!
|
||||
#define DWRITE_D0_0 DWRITE_D0_1
|
||||
#endif
|
||||
#ifdef PD1
|
||||
#define DWRITE_D1_1 PORTD |= 0x02
|
||||
#define DWRITE_D1_0 PORTD &= 0xFD
|
||||
#else
|
||||
#define DWRITE_D1_1 # Pin D1 not supported on this MCU!
|
||||
#define DWRITE_D1_0 DWRITE_D1_1
|
||||
#endif
|
||||
#ifdef PD2
|
||||
#define DWRITE_D2_1 PORTD |= 0x04
|
||||
#define DWRITE_D2_0 PORTD &= 0xFB
|
||||
#else
|
||||
#define DWRITE_D2_1 # Pin D2 not supported on this MCU!
|
||||
#define DWRITE_D2_0 DWRITE_D2_1
|
||||
#endif
|
||||
#ifdef PD3
|
||||
#define DWRITE_D3_1 PORTD |= 0x08
|
||||
#define DWRITE_D3_0 PORTD &= 0xF7
|
||||
#else
|
||||
#define DWRITE_D3_1 # Pin D3 not supported on this MCU!
|
||||
#define DWRITE_D3_0 DWRITE_D3_1
|
||||
#endif
|
||||
#ifdef PD4
|
||||
#define DWRITE_D4_1 PORTD |= 0x10
|
||||
#define DWRITE_D4_0 PORTD &= 0xEF
|
||||
#else
|
||||
#define DWRITE_D4_1 # Pin D4 not supported on this MCU!
|
||||
#define DWRITE_D4_0 DWRITE_D4_1
|
||||
#endif
|
||||
#ifdef PD5
|
||||
#define DWRITE_D5_1 PORTD |= 0x20
|
||||
#define DWRITE_D5_0 PORTD &= 0xDF
|
||||
#else
|
||||
#define DWRITE_D5_1 # Pin D5 not supported on this MCU!
|
||||
#define DWRITE_D5_0 DWRITE_D5_1
|
||||
#endif
|
||||
#ifdef PD6
|
||||
#define DWRITE_D6_1 PORTD |= 0x40
|
||||
#define DWRITE_D6_0 PORTD &= 0xBF
|
||||
#else
|
||||
#define DWRITE_D6_1 # Pin D6 not supported on this MCU!
|
||||
#define DWRITE_D6_0 DWRITE_D6_1
|
||||
#endif
|
||||
#ifdef PD7
|
||||
#define DWRITE_D7_1 PORTD |= 0x80
|
||||
#define DWRITE_D7_0 PORTD &= 0x7F
|
||||
#else
|
||||
#define DWRITE_D7_1 # Pin D7 not supported on this MCU!
|
||||
#define DWRITE_D7_0 DWRITE_D7_1
|
||||
#endif
|
||||
|
||||
|
||||
#endif // PIO_DWRITE_H
|
78
pio/i2c/impl0.h
Normal file
78
pio/i2c/impl0.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/***
|
||||
* impl0.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the super parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifndef F_CPU
|
||||
#error F_CPU not defined!
|
||||
#endif
|
||||
|
||||
#ifndef F_I2C
|
||||
#ifndef PIO_DISABLE_I2C
|
||||
#warning F_I2C not defined, I2C disabled.
|
||||
#endif
|
||||
#else
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// AVR TWI master transmitter status codes
|
||||
#define TWS_START 0x08
|
||||
#define TWS_REPEATED_START 0x10
|
||||
#define TWS_ADDR_ACK 0x18
|
||||
#define TWS_ADDR_NOT_ACK 0x20
|
||||
#define TWS_DATA_ACK 0x28
|
||||
#define TWS_DATA_NOT_ACK 0x30
|
||||
#define TWS_ARB_LOST 0x38
|
||||
|
||||
// functions
|
||||
void i2cInit(void);
|
||||
void i2cBeginTransmission(uint8_t);
|
||||
void i2cSend(uint8_t);
|
||||
void i2cEndTransmission(void);
|
||||
|
||||
// error function pointer
|
||||
void (*i2cError)(void) = NULL;
|
||||
|
||||
void i2cInit() {
|
||||
// i2c clock speed, see SCL frequency formula in datasheet
|
||||
uint16_t sp = F_CPU / F_I2C - 16;
|
||||
uint16_t bp = sp;
|
||||
while(sp > 510) {
|
||||
TWSR++;
|
||||
sp /= 4;
|
||||
}
|
||||
TWBR = bp / (1<<(2*(TWSR & 0x03)+1));
|
||||
}
|
||||
|
||||
void i2cBeginTransmission(uint8_t addr) {
|
||||
TWCR = _BV(TWEN) | _BV(TWINT) | _BV(TWSTA);
|
||||
while (!(TWCR & _BV(TWINT)));
|
||||
if((TWSR & 0xF8) != TWS_START)
|
||||
i2cError();
|
||||
|
||||
TWDR = (addr & 0xFE) << 1;
|
||||
TWCR = _BV(TWEN) | _BV(TWINT);
|
||||
while (!(TWCR & _BV(TWINT)));
|
||||
if((TWSR & 0xF8) != TWS_ADDR_ACK)
|
||||
i2cError();
|
||||
}
|
||||
|
||||
void i2cSend(uint8_t b) {
|
||||
TWDR = b;
|
||||
TWCR = _BV(TWEN) | _BV(TWINT);
|
||||
while (!(TWCR & _BV(TWINT)));
|
||||
if((TWSR & 0xF8) != TWS_DATA_ACK)
|
||||
i2cError();
|
||||
}
|
||||
|
||||
void i2cEndTransmission() {
|
||||
TWCR = _BV(TWEN) | _BV(TWINT) | _BV(TWSTO);
|
||||
while (TWCR & _BV(TWSTO));
|
||||
}
|
||||
|
||||
#endif
|
22
pio/mcus.h
Normal file
22
pio/mcus.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
/***
|
||||
* mcus.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifndef PIO_MCUS_H
|
||||
#define PIO_MCUS_H
|
||||
|
||||
#include "mcus/atmega328p.h"
|
||||
#include "mcus/atmega16.h"
|
||||
#include "mcus/atmega1284.h"
|
||||
|
||||
#ifndef MCU
|
||||
#error No compatible MCU header file found.
|
||||
#endif
|
||||
|
||||
#endif // PIO_MCUS_H
|
17
pio/mcus/atmega1284.h
Normal file
17
pio/mcus/atmega1284.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
/***
|
||||
* atmega1284.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the super parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should not be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifdef __AVR_ATmega1284__
|
||||
|
||||
#define MCU ATmega1284
|
||||
|
||||
#include "../i2c/impl0.h"
|
||||
|
||||
#endif
|
17
pio/mcus/atmega16.h
Normal file
17
pio/mcus/atmega16.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
/***
|
||||
* atmega16.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the super parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should not be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
#ifdef __AVR_ATmega16__
|
||||
|
||||
#define MCU ATmega16
|
||||
|
||||
#include "../i2c/impl0.h"
|
||||
|
||||
#endif
|
14
pio/mcus/atmega328p.h
Normal file
14
pio/mcus/atmega328p.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
/***
|
||||
* atmega328p.h
|
||||
* This file is part of the PIO library.
|
||||
* For license information see "pio.h" in the super parent directory.
|
||||
*/
|
||||
|
||||
#if !defined(PIOLIB) || PIOLIB < 100
|
||||
#error This file should not be included directly. Use "pio.h" instead.
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __AVR_ATmega328P__
|
||||
#error Not implemented!
|
||||
#endif
|
12
spi.cpp
12
spi.cpp
|
@ -0,0 +1,12 @@
|
|||
#include "spi.h"
|
||||
|
||||
SPI::SPI(void)
|
||||
{
|
||||
}
|
||||
|
||||
void SPI::init(void) const
|
||||
{
|
||||
dMode(MOSI, OUT);
|
||||
dMode(MISO, IN);
|
||||
dMode(SCLK, OUT);
|
||||
}
|
20
spi.h
20
spi.h
|
@ -1,19 +1,17 @@
|
|||
#ifndef SPI_H
|
||||
#define SPI_H
|
||||
#ifndef SPI_MASTER_H
|
||||
#define SPI_MASTER_H
|
||||
|
||||
#include <util/delay.h>
|
||||
#include "pio.h"
|
||||
|
||||
#define MOSI B5
|
||||
#define MISO B6
|
||||
#define SCLK B7
|
||||
|
||||
class SPI {
|
||||
public:
|
||||
SPI(void) {
|
||||
DDRB |= _BV(PB0);
|
||||
while(1) {
|
||||
PORTB ^= _BV(PB0);
|
||||
_delay_ms(1);
|
||||
}
|
||||
}
|
||||
|
||||
private: int d;
|
||||
SPI(void);
|
||||
void init(void) const;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue