Hacker-Jeopardy/Mainboard_/Mainboard/Mainboard.c

126 lines
2.0 KiB
C
Raw Permalink Normal View History

2013-11-04 18:45:46 +01:00
/*
* Mainboard.c
*
* Created: 06.10.2013 19:12:35
* Author: netz
*/
#define F_CPU 16000000
//#define F_CPU 8000000
//#define F_CPU 2000000
#include <avr/io.h>
#include <util/delay.h>
//#include "config.h"
//#include <avr/io.h>
//#include "led.h"
//#include "rs232.h"
//#include "usb.h"
/*void wait_for_usb() {
while(true) {
if(usb_getstatus() == USB_STATUS_DISCONNECTED) {
led(YELLOW);
if(!(PINC & (1<<PINC7))) {
return;
}
}
if(usb_getstatus() == USB_STATUS_ENUMERATED) {
led(CYAN);
}
if(usb_getstatus() == USB_STATUS_CONFIGURED) {
led(GREEN);
return;
}
}
}
void init()
{
led(YELLOW);
sei();
init_led();
init_rs232();
//init_usb();
DDRC &= ~(1<<PINC7);
PORTC |= (1<<PINC7);
//wait_for_usb();
}
void send(char * text) {
uint8_t l = strlen(text);
if(l >= 29) {
text[29] = 13;
text[30] = 10;
text[31] = 0;
} else {
text[l] = 13;
text[l+1] = 10;
text[l+2] = 0;
}
led(MAGENTA);
rs232_send(text);
if(usb_getstatus() == USB_STATUS_CONFIGURED && usb_ready()) {
usb_send(text);
}
led(GREEN);
}
void resi(char * text) {
_delay_ms(10);
send("Nachricht bekommen!");
//send(text);
led(RED);
_delay_ms(2000);
}*/
uint8_t spi_putc( uint8_t data ) {
SPDR = data;
while(!(SPSR & (1<<SPIF))) {
PORTB ^= (1<<PINB6);
_delay_ms(100);
}
return SPDR;
}
int main(void)
{
DDRB = (1<<PINB1) | (1<<PINB2) | (0<<PINB3) | (1<<PINB4) | (1<<PINB7) | (1<<PINB6);
PORTB = 0 | (1<<PINB4);
SPSR = 0;//(1<<SPI2X);
SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<<SPR0);
_delay_ms(10);
PORTB &= ~(1<<PINB4);
spi_putc( 0xC0 );
_delay_ms(1);
PORTB |= (1<<PINB4);
PORTB &= ~(1<<PINB4);
spi_putc( 0xC0 );
_delay_ms(1);
PORTB |= (1<<PINB4);
PORTB |= (1<<PINB7);
/*init();
led(GREEN);
char text[32];
uint16_t i=0;
while(1)
{
snprintf(text, 32, "blafoo %d ich bin ein lager doofer text",i++);
send(text);
_delay_ms(100);
led_rainbow(5);
}*/
while(1) {
}
}