20131110-181004
This commit is contained in:
parent
63e462ea63
commit
b275a520fa
Binary file not shown.
@ -6,19 +6,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <avr/io.h>
|
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
#include "mcp2515_defs.h"
|
#include "mcp2515_defs.h"
|
||||||
#include "Led.h"
|
|
||||||
#include "Spi.h"
|
#include "Spi.h"
|
||||||
|
|
||||||
#ifndef CAN_H_
|
#ifndef CAN_H_
|
||||||
#define CAN_H_
|
#define CAN_H_
|
||||||
|
|
||||||
//#define DDR_CS DDRB
|
|
||||||
//#define PORT_CS PORTB
|
|
||||||
//#define P_CS 2
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
|
@ -1,27 +1,26 @@
|
|||||||
Can.d Can.o: .././Can.cpp .././Can.h .././config.h \
|
Can.d Can.o: .././Can.cpp .././Can.h .././config.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/io.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/util/delay.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/sfr_defs.h \
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/inttypes.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/inttypes.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/include/stdint.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/include/stdint.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/stdint.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/stdint.h \
|
||||||
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/util/delay_basic.h \
|
||||||
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/math.h \
|
||||||
|
.././mcp2515_defs.h .././Spi.h \
|
||||||
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/io.h \
|
||||||
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/sfr_defs.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/iom32u2.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/iom32u2.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/portpins.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/portpins.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/common.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/common.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/version.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/version.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/fuse.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/fuse.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/lock.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/lock.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/util/delay.h \
|
.././pin.hpp .././portb.hpp
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/util/delay_basic.h \
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/math.h \
|
|
||||||
.././mcp2515_defs.h .././Led.h .././Spi.h
|
|
||||||
|
|
||||||
.././Can.h:
|
.././Can.h:
|
||||||
|
|
||||||
.././config.h:
|
.././config.h:
|
||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/io.h:
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/util/delay.h:
|
||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/sfr_defs.h:
|
|
||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/inttypes.h:
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/inttypes.h:
|
||||||
|
|
||||||
@ -29,6 +28,18 @@ c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-
|
|||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/stdint.h:
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/stdint.h:
|
||||||
|
|
||||||
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/util/delay_basic.h:
|
||||||
|
|
||||||
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/math.h:
|
||||||
|
|
||||||
|
.././mcp2515_defs.h:
|
||||||
|
|
||||||
|
.././Spi.h:
|
||||||
|
|
||||||
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/io.h:
|
||||||
|
|
||||||
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/sfr_defs.h:
|
||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/iom32u2.h:
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/iom32u2.h:
|
||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/portpins.h:
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/portpins.h:
|
||||||
@ -41,14 +52,6 @@ c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-
|
|||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/lock.h:
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/lock.h:
|
||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/util/delay.h:
|
.././pin.hpp:
|
||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/util/delay_basic.h:
|
.././portb.hpp:
|
||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/math.h:
|
|
||||||
|
|
||||||
.././mcp2515_defs.h:
|
|
||||||
|
|
||||||
.././Led.h:
|
|
||||||
|
|
||||||
.././Spi.h:
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Led.d Led.o: .././Led.cpp .././Led.h \
|
Led.d Led.o: .././Led.cpp .././Led.h .././portc.hpp \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/io.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/io.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/sfr_defs.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/sfr_defs.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/inttypes.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/inttypes.h \
|
||||||
@ -9,10 +9,13 @@ Led.d Led.o: .././Led.cpp .././Led.h \
|
|||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/common.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/common.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/version.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/version.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/fuse.h \
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/fuse.h \
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/lock.h
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/lock.h \
|
||||||
|
.././pin.hpp
|
||||||
|
|
||||||
.././Led.h:
|
.././Led.h:
|
||||||
|
|
||||||
|
.././portc.hpp:
|
||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/io.h:
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/io.h:
|
||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/sfr_defs.h:
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/sfr_defs.h:
|
||||||
@ -34,3 +37,5 @@ c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-
|
|||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/fuse.h:
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/fuse.h:
|
||||||
|
|
||||||
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/lock.h:
|
c:\program\ files\ (x86)\atmel\atmel\ toolchain\avr8\ gcc\native\3.4.2.876\avr8-gnu-toolchain\bin\../lib/gcc/avr/4.7.2/../../../../avr/include/avr/lock.h:
|
||||||
|
|
||||||
|
.././pin.hpp:
|
||||||
|
@ -1,49 +1,41 @@
|
|||||||
/*
|
/*
|
||||||
* CPPFile1.cpp
|
* Led.cpp
|
||||||
*
|
*
|
||||||
* Created: 03.11.2013 17:24:58
|
* Created: 03.11.2013 17:24:58
|
||||||
* Author: netz
|
* Author: netz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Led.h"
|
#include "Led.h"
|
||||||
#define LEDPORT PORTB
|
|
||||||
#define LEDDDR DDRB
|
|
||||||
#define LEDPINR PINC5
|
|
||||||
#define LEDPING PINC6
|
|
||||||
#define LEDPINB PINC7
|
|
||||||
#define LEDPINM PINC5
|
|
||||||
|
|
||||||
Led::Led() {
|
/*Led::Led() {
|
||||||
init();
|
init();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void Led::init() {
|
/*void Led::init() {
|
||||||
LEDDDR |= (1<<LEDPINR) | (1<<LEDPING) | (1<<LEDPINB);
|
red::make_output();
|
||||||
}
|
green::make_output();
|
||||||
|
blue::make_output();
|
||||||
|
}*/
|
||||||
|
|
||||||
void Led::uninit() {
|
/*void Led::uninit() {
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void Led::color(uint8_t mask) {
|
/*void Led::color(uint8_t mask) {
|
||||||
int rgb = 0;
|
(mask & (1<<0)) ? blue::make_high() : blue::make_low();
|
||||||
rgb |= (mask & (1<<0)) ? (1<<0) : (0<<0);
|
(mask & (1<<1)) ? green::make_high() : green::make_low();
|
||||||
rgb |= (mask & (1<<1)) ? (1<<1) : (0<<1);
|
(mask & (1<<2)) ? red::make_high() : red::make_low();
|
||||||
rgb |= (mask & (1<<2)) ? (1<<2) : (0<<2);
|
}*/
|
||||||
|
|
||||||
LEDPORT &= ~((1<<LEDPINR) | (1<<LEDPING) | (1<<LEDPINB));
|
|
||||||
LEDPORT |= (rgb<<LEDPINM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Led::rainbow(uint8_t time) {
|
/*void Led::rainbow(uint8_t time) {
|
||||||
fade(RED, YELLOW, time);
|
fade(RED, YELLOW, time);
|
||||||
fade(YELLOW, GREEN, time);
|
fade(YELLOW, GREEN, time);
|
||||||
fade(GREEN, CYAN, time);
|
fade(GREEN, CYAN, time);
|
||||||
fade(CYAN, BLUE, time);
|
fade(CYAN, BLUE, time);
|
||||||
fade(BLUE, MAGENTA, time);
|
fade(BLUE, MAGENTA, time);
|
||||||
fade(MAGENTA, RED, time);
|
fade(MAGENTA, RED, time);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void Led::fade(int from, int to, int dur) {
|
/*void Led::fade(int from, int to, int dur) {
|
||||||
for (int i=0;i<0xFF;i++) {
|
for (int i=0;i<0xFF;i++) {
|
||||||
for(int k=0;k<dur;k++) {
|
for(int k=0;k<dur;k++) {
|
||||||
for (int j=i;j<0xFF;j++) {
|
for (int j=i;j<0xFF;j++) {
|
||||||
@ -54,4 +46,4 @@ void Led::fade(int from, int to, int dur) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
@ -5,19 +5,43 @@
|
|||||||
* Author: BlubbFish
|
* Author: BlubbFish
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include "portc.hpp"
|
||||||
|
#include "pin.hpp"
|
||||||
|
|
||||||
#ifndef LED_H_
|
#ifndef LED_H_
|
||||||
#define LED_H_
|
#define LED_H_
|
||||||
|
template <typename Port, int pin_red, int pin_green, int pin_blue>
|
||||||
class Led {
|
class Led {
|
||||||
public:
|
public:
|
||||||
Led();
|
Led() {
|
||||||
|
init();
|
||||||
|
}
|
||||||
inline Led(int) {}
|
inline Led(int) {}
|
||||||
//virtual ~Led();
|
void color(uint8_t mask) {
|
||||||
void color(uint8_t mask);
|
(mask & (1<<0)) ? blue::make_high() : blue::make_low();
|
||||||
void rainbow(uint8_t time);
|
(mask & (1<<1)) ? green::make_high() : green::make_low();
|
||||||
void fade(int from, int to, int dur);
|
(mask & (1<<2)) ? red::make_high() : red::make_low();
|
||||||
|
}
|
||||||
|
void rainbow(uint8_t time) {
|
||||||
|
fade(RED, YELLOW, time);
|
||||||
|
fade(YELLOW, GREEN, time);
|
||||||
|
fade(GREEN, CYAN, time);
|
||||||
|
fade(CYAN, BLUE, time);
|
||||||
|
fade(BLUE, MAGENTA, time);
|
||||||
|
fade(MAGENTA, RED, time);
|
||||||
|
}
|
||||||
|
void fade(uint8_t from, uint8_t to, uint8_t dur) {
|
||||||
|
for (uint8_t i=0;i<0xFF;i++) {
|
||||||
|
for(uint8_t k=0;k<dur;k++) {
|
||||||
|
for (uint8_t j=i;j<0xFF;j++) {
|
||||||
|
color(from);
|
||||||
|
}
|
||||||
|
for (int j=0;j<i;j++) {
|
||||||
|
color(to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
static const uint8_t BLACK = 0;
|
static const uint8_t BLACK = 0;
|
||||||
static const uint8_t BLUE = 1;
|
static const uint8_t BLUE = 1;
|
||||||
static const uint8_t GREEN = 2;
|
static const uint8_t GREEN = 2;
|
||||||
@ -27,8 +51,15 @@ class Led {
|
|||||||
static const uint8_t YELLOW = 6;
|
static const uint8_t YELLOW = 6;
|
||||||
static const uint8_t WHITE = 7;
|
static const uint8_t WHITE = 7;
|
||||||
private:
|
private:
|
||||||
void init();
|
void init() {
|
||||||
|
red::make_output();
|
||||||
|
green::make_output();
|
||||||
|
blue::make_output();
|
||||||
|
}
|
||||||
void uninit();
|
void uninit();
|
||||||
|
const typedef avrlib::pin<Port, pin_red> red;
|
||||||
|
const typedef avrlib::pin<Port, pin_green> green;
|
||||||
|
const typedef avrlib::pin<Port, pin_blue> blue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,15 +10,18 @@
|
|||||||
#include "Rs232.h"
|
#include "Rs232.h"
|
||||||
#include "Can.h"
|
#include "Can.h"
|
||||||
#include "Spi.h"
|
#include "Spi.h"
|
||||||
|
#include "portc.hpp"
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
|
||||||
Led l;
|
//Led l;
|
||||||
|
typedef Led<avrlib::portc, PINC5, PINC6, PINC7> l;
|
||||||
Rs232 r;
|
Rs232 r;
|
||||||
Can c(Spi(0));
|
Can c(Spi(0));
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
l.color(Led::YELLOW);
|
//l.color(Led::YELLOW);
|
||||||
|
l::color(l::YELLOW);
|
||||||
r.send("bla\n");
|
r.send("bla\n");
|
||||||
CANMessage m;
|
CANMessage m;
|
||||||
m.id = 0x0123;
|
m.id = 0x0123;
|
||||||
@ -28,7 +31,7 @@ int main(void)
|
|||||||
m.data[1] = 0xFE;
|
m.data[1] = 0xFE;
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
l.color(Led::GREEN);
|
//l.color(Led::GREEN);
|
||||||
_delay_ms(100);
|
_delay_ms(100);
|
||||||
//r.send("Text\n");
|
//r.send("Text\n");
|
||||||
//_delay_ms(500);
|
//_delay_ms(500);
|
||||||
@ -39,10 +42,10 @@ int main(void)
|
|||||||
//c.can_send_message(&m);
|
//c.can_send_message(&m);
|
||||||
uint8_t r = c.can_get_message(&m);
|
uint8_t r = c.can_get_message(&m);
|
||||||
if(r == 0xFF) {
|
if(r == 0xFF) {
|
||||||
l.color(Led::RED);
|
//l.color(Led::RED);
|
||||||
_delay_ms(100);
|
_delay_ms(100);
|
||||||
} else {
|
} else {
|
||||||
l.color(Led::BLUE);
|
//l.color(Led::BLUE);
|
||||||
_delay_ms(1000);
|
_delay_ms(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,6 +165,15 @@
|
|||||||
<Compile Include="mcp2515_defs.h">
|
<Compile Include="mcp2515_defs.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="pin.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="portb.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="portc.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Rs232.cpp">
|
<Compile Include="Rs232.cpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -18,20 +18,23 @@ void Spi::init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CANDDR_SPI DDRB
|
/*#define CANDDR_SPI DDRB
|
||||||
#define CANPORT_SPI PORTB
|
#define CANPORT_SPI PORTB
|
||||||
#define CANPIN_SPI PINB
|
#define CANPIN_SPI PINB
|
||||||
#define CANP_MISO PINB3
|
#define CANP_MISO PINB3
|
||||||
#define CANP_MOSI PINB2
|
#define CANP_MOSI PINB2
|
||||||
#define CANP_SCK PINB1
|
#define CANP_SCK PINB1
|
||||||
#define CANP_CS PINB4
|
#define CANP_CS PINB4*/
|
||||||
|
|
||||||
void Spi::init_port() {
|
void Spi::init_port() {
|
||||||
CANDDR_SPI |= (1<<CANP_SCK) | (1<<CANP_MOSI) | (1<<CANP_CS);
|
mosi::make_output();
|
||||||
CANDDR_SPI &= ~(1<<CANP_MISO);
|
mosi::make_low();
|
||||||
CANPORT_SPI &= ~((1<<CANP_MOSI) | (1<<CANP_MISO) | (1<<CANP_SCK));
|
sck::make_output();
|
||||||
*canport &= ~((1<<CANP_MOSI) | (1<<CANP_MISO) | (1<<CANP_SCK));
|
sck::make_low();
|
||||||
CANPORT_SPI |= (1<<CANP_CS);
|
cs::make_output();
|
||||||
|
cs::make_high();
|
||||||
|
miso::make_input();
|
||||||
|
miso::make_low();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spi::init_spi() {
|
void Spi::init_spi() {
|
||||||
@ -40,11 +43,11 @@ void Spi::init_spi() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Spi::CSOff() {
|
void Spi::CSOff() {
|
||||||
CANPORT_SPI |= (1<<CANP_CS);
|
cs::make_high();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spi::CSOn() {
|
void Spi::CSOn() {
|
||||||
CANPORT_SPI &= ~(1<<CANP_CS);
|
cs::make_low();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Spi::send(uint8_t data) {
|
uint8_t Spi::send(uint8_t data) {
|
||||||
@ -65,7 +68,28 @@ uint8_t Spi::send_hard( uint8_t data ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Spi::send_soft(uint8_t data) {
|
uint8_t Spi::send_soft(uint8_t data) {
|
||||||
uint8_t werti = 0;
|
uint8_t datain=0;
|
||||||
|
for (uint8_t a=8; a>0; a--){ //das Byte wird Bitweise nacheinander Gesendet MSB zuerst
|
||||||
|
datain<<=1; //Schieben um das Richtige Bit zusetzen
|
||||||
|
sck::make_low(); // Clock auf LOW
|
||||||
|
if (data & 0x80) { //Ist Bit a in Byte gesetzt
|
||||||
|
mosi::make_high(); //Set Output High
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
mosi::make_low(); //Set Output Low
|
||||||
|
}
|
||||||
|
_delay_us(1);
|
||||||
|
if(miso::read()) //Lesen des Pegels
|
||||||
|
{
|
||||||
|
datain |= 1;
|
||||||
|
}
|
||||||
|
_delay_us(1);
|
||||||
|
sck::make_high(); // Clock auf High
|
||||||
|
_delay_us(2);
|
||||||
|
data<<=1; //Schiebe um nächstes Bit zusenden
|
||||||
|
}
|
||||||
|
return datain;
|
||||||
|
/*uint8_t werti = 0;
|
||||||
|
|
||||||
for (uint8_t i = 8; i != 0; i--) {
|
for (uint8_t i = 8; i != 0; i--) {
|
||||||
CANPORT_SPI = (CANPORT_SPI & (~(1 << CANP_MOSI))) | ((data & 1) << CANP_MOSI);
|
CANPORT_SPI = (CANPORT_SPI & (~(1 << CANP_MOSI))) | ((data & 1) << CANP_MOSI);
|
||||||
@ -79,26 +103,5 @@ uint8_t Spi::send_soft(uint8_t data) {
|
|||||||
asm volatile ("nop");
|
asm volatile ("nop");
|
||||||
werti = (werti << 1) | ((CANPIN_SPI >> CANP_MISO) & 1);
|
werti = (werti << 1) | ((CANPIN_SPI >> CANP_MISO) & 1);
|
||||||
}
|
}
|
||||||
//RF_PORT &= ~(1<<CS);
|
return werti; */
|
||||||
/*for (i=0; i<8; i++)
|
|
||||||
{
|
|
||||||
if (wert & (1<<i)) {
|
|
||||||
|
|
||||||
|
|
||||||
CANPORT_SPI |= (1<<CANP_MOSI);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
CANPORT_SPI &= ~(1<<CANP_MOSI);
|
|
||||||
}
|
|
||||||
werti<<=1;
|
|
||||||
if (CANPIN_SPI & (1<<CANP_MISO)) {
|
|
||||||
werti|=1;
|
|
||||||
}
|
|
||||||
CANPORT_SPI |= (1<<CANP_SCK);
|
|
||||||
wert<<=1;
|
|
||||||
_delay_us(0.3);
|
|
||||||
CANPORT_SPI &= ~(1<<CANP_SCK);
|
|
||||||
}*/
|
|
||||||
//RF_PORT |= (1<<CS);
|
|
||||||
return werti;
|
|
||||||
}
|
}
|
@ -9,7 +9,12 @@
|
|||||||
#ifndef SPI_H_
|
#ifndef SPI_H_
|
||||||
#define SPI_H_
|
#define SPI_H_
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#include "pin.hpp"
|
||||||
|
#include "portb.hpp"
|
||||||
|
|
||||||
|
|
||||||
class Spi {
|
class Spi {
|
||||||
public:
|
public:
|
||||||
@ -19,8 +24,10 @@ class Spi {
|
|||||||
uint8_t send(uint8_t data);
|
uint8_t send(uint8_t data);
|
||||||
private:
|
private:
|
||||||
const uint8_t mode; //0 Hardware, 1 Software
|
const uint8_t mode; //0 Hardware, 1 Software
|
||||||
volatile uint8_t *canport;
|
const typedef avrlib::pin<avrlib::portb, PINB4> cs;
|
||||||
//static uint8_t spiport = PORTB;
|
const typedef avrlib::pin<avrlib::portb, PINB3> miso;
|
||||||
|
const typedef avrlib::pin<avrlib::portb, PINB2> mosi;
|
||||||
|
const typedef avrlib::pin<avrlib::portb, PINB1> sck;
|
||||||
void init();
|
void init();
|
||||||
void init_port();
|
void init_port();
|
||||||
void init_spi();
|
void init_spi();
|
||||||
|
48
Mainboard/Mainboard/pin.hpp
Normal file
48
Mainboard/Mainboard/pin.hpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#ifndef AVRLIB_PIN_HPP
|
||||||
|
#define AVRLIB_PIN_HPP
|
||||||
|
|
||||||
|
namespace avrlib {
|
||||||
|
|
||||||
|
template <typename Port, uint8_t Pin>
|
||||||
|
struct pin
|
||||||
|
{
|
||||||
|
static void set(bool value = true)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
Port::port(Port::port() | (1<<Pin));
|
||||||
|
else
|
||||||
|
Port::port(Port::port() & ~(1<<Pin));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clear() { set(false); }
|
||||||
|
|
||||||
|
static void toggle() { Port::port(Port::port() ^ (1<<Pin)); }
|
||||||
|
|
||||||
|
static bool get() { return (Port::port() & (1<<Pin)) != 0; }
|
||||||
|
|
||||||
|
static bool value() { return (Port::pin() & (1<<Pin)) != 0; }
|
||||||
|
|
||||||
|
static void output(bool value)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
Port::dir(Port::dir() | (1<<Pin));
|
||||||
|
else
|
||||||
|
Port::dir(Port::dir() & ~(1<<Pin));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool output() { return (Port::dir() & (1<<Pin)) != 0; }
|
||||||
|
|
||||||
|
static void make_output() { output(true); }
|
||||||
|
static void make_input() { output(false); clear(); }
|
||||||
|
static void make_low() { clear(); output(true); }
|
||||||
|
static void make_high() { set(); output(true); }
|
||||||
|
static void set_value(bool value) { set(value); }
|
||||||
|
static void set_high() { set(true); }
|
||||||
|
static void set_low() { set(false); }
|
||||||
|
static bool read() { return value(); }
|
||||||
|
static void pullup() { set_high(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
22
Mainboard/Mainboard/portb.hpp
Normal file
22
Mainboard/Mainboard/portb.hpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef AVRLIB_PORTB_HPP
|
||||||
|
#define AVRLIB_PORTB_HPP
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
namespace avrlib {
|
||||||
|
|
||||||
|
struct portb
|
||||||
|
{
|
||||||
|
static uint8_t port() { return PORTB; }
|
||||||
|
static void port(uint8_t v) { PORTB = v; }
|
||||||
|
|
||||||
|
static uint8_t pin() { return PINB; }
|
||||||
|
static void pin(uint8_t v) { PINB = v; }
|
||||||
|
|
||||||
|
static uint8_t dir() { return DDRB; }
|
||||||
|
static void dir(uint8_t v) { DDRB = v; }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
22
Mainboard/Mainboard/portc.hpp
Normal file
22
Mainboard/Mainboard/portc.hpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef AVRLIB_PORTC_HPP
|
||||||
|
#define AVRLIB_PORTC_HPP
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
namespace avrlib {
|
||||||
|
|
||||||
|
struct portc
|
||||||
|
{
|
||||||
|
static uint8_t port() { return PORTC; }
|
||||||
|
static void port(uint8_t v) { PORTC = v; }
|
||||||
|
|
||||||
|
static uint8_t pin() { return PINC; }
|
||||||
|
static void pin(uint8_t v) { PINC = v; }
|
||||||
|
|
||||||
|
static uint8_t dir() { return DDRC; }
|
||||||
|
static void dir(uint8_t v) { DDRC = v; }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user