#include <inttypes.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include <string.h>
#include <config.h> // All configuration parameters
#include <bios.h> // BIOS interface declarations, including CAN structure and ID defines.
#include <drivers/timer/timer.h>
#include <drivers/lcd/glcd/ks0108.h>
#include <drivers/lcd/glcd/font.h>
#include <avr/pgmspace.h>
#define APP_TYPE 0xf001
#define APP_VERSION 0x0002
/* Left half of the LCD */
static unsigned char Splash_left[] PROGMEM = {
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,
0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0xFF,0xFF,
0xFF,0xFF,0x7F,0x7F,0x3F,0xBF,0x3F,0x1F,
0x3F,0x3F,0x3F,0x7F,0xFF,0xBF,0x1F,0x47,
0x87,0x07,0x07,0x07,0x27,0x77,0x77,0x67,
0xE7,0xE7,0xE7,0xC7,0x87,0x07,0x07,0x07,
0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x87,
0xC7,0xF7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0xEF,0x7F,
0x7F,0x7F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xBF,0xFF,0xFF,0xFF,0xFF,
0x3F,0x7F,0x7F,0x7F,0x3F,0x3F,0x3F,0x1F,
0x1F,0x1F,0x1F,0x1F,0x0F,0x1F,0x1F,0x1F,
0x3F,0x3F,0x3F,0x3F,0x3F,0x7F,0x7F,0x7F,
0x7F,0x3F,0x3F,0x7F,0x7F,0x7F,0x7F,0x7F,
0x7F,0xFF,0xFF,0xFF,0x7F,0x7F,0xFF,0xFF,
0xFE,0xFE,0xFE,0xFF,0xFF,0xFF,0xF8,0xF8,
0xF0,0xF0,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,
0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,
0x0C,0x0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xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0xF8,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x7F,0x7F,0x7F,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,
0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,
0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,
0x7F,0x7F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
0x07,0x07,0x07,0x07,0x07,0x07,0x03,0x03,
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0x03,0x01,0x03,0x03,
0x03,0x03,0x03,0x03,0x03,0x01,0x01,0x00,
0x00,0x00,0x07,0x07,0x07,0x07,0x07,0x07,
0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
0x07,0x03,0x03,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x05,0x05,0x07,0x07,0x07,0x07
};
uint16_t ixa = 0;
uint8_t jxa = 0;
// A simple message "queue", with space for one message only.
// These are declared volatile to tell the compiler not to optimize away accesses.
volatile Can_Message_t rxMsg; // Message storage
volatile uint8_t rxMsgFull; // Synchronization flag
// CAN message reception callback.
// This function runs with interrupts disabled, keep it as short as possible.
void can_receive(Can_Message_t *msg) {
if (!rxMsgFull) {
memcpy((void*)&rxMsg
, msg
, sizeof(rxMsg
));
rxMsgFull = 1;
}
}
// Timer callback function used for some timer tests
void timer_callback(uint8_t timer) {
Can_Message_t msg;
msg.ExtendedFlag = 1;
msg.Id = (CAN_TST << CAN_SHIFT_CLASS) | NODE_ID;
msg.RemoteFlag = 0;
msg.DataLength = 1;
msg.Data.bytes[0] = timer;
BIOS_CanSend(&msg);
}
int main(void)
{
//Initiera utgngar
DDRB |= (1<<7)|(1<<2)|(1<<1)|(1<<0);
DDRC |= (1<<5)|(1<<4);
DDRD |= (1<<7)|(1<<6)|(1<<5)|(1<<4)|(1<<2)|(1<<1)|(1<<0);
// Enable interrupts as early as possible
sei();
Can_Message_t txMsg;
txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID);
txMsg.DataLength = 4;
txMsg.RemoteFlag = 0;
txMsg.ExtendedFlag = 1;
txMsg.Data.words[0] = APP_TYPE;
txMsg.Data.words[1] = APP_VERSION;
// Set up callback for CAN reception, this is optional if only sending is required.
BIOS_CanCallback = &can_receive;
// Send CAN_NMT_APP_START
BIOS_CanSend(&txMsg);
/* Kukgrejer frn apetech-libbet
// Wait a little while the display starts up
for(volatile uint16_t i=0; i<15000; i++);
// Initialize the LCD
ks0108Init(0);
// Select a font
ks0108SelectFont(Arial_Bold_14, ks0108ReadFontData, BLACK);
// Set a position
ks0108GotoXY(15,10);
// Print some text
ks0108Puts_P(PSTR("KS0108-Treiber"));
// a nice little round rect
ks0108DrawRoundRect(5, 5, 117, 20, 8, BLACK);
// Once again :)
// Select a font
ks0108SelectFont(Corsiva_12, ks0108ReadFontData, BLACK);
// Set a position
ks0108GotoXY(5,0);
// Print some text
ks0108Puts_P(PSTR("http://www.apetech.de\nmailto:me@apetech.de"));
*/
glcdPowerOn();
glcdSetXY(0,0);
//glcdPutStr("This is a test....... Let us try another row.. And another.. And some more..");
for (jxa = 0; jxa< 8; jxa++){
glcdSetXY(0,jxa);
for (ixa = 0; ixa < 128; ixa++){
glcdWriteData(pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128));
}
}
glcdSetXY(0,0);
glcdPutStr("I can write text. This is cool. Yeah baby! Pixelina!");
/*glcdSetXY(5,5);
glcdPutStr("I can write text.");
glcdSetXY(8,10);
glcdPutStr("Everywhere!");
*/
while (1) {
//glcdSetXY(0,0);
//glcdPutStr("This is a test.... Let us try another row.. And another.. And some more..");
if (Timer_Expired(0)) {
// Send a CAN message
txMsg.
Data.
dwords[1] = time;
BIOS_CanSend(&txMsg);
//printf("Two seconds passed, time is now %ld.\n", time);
}
if (rxMsgFull) {
// Print the received message
/* printf("RX: ID=%08lx, DLC=%u, EXT=%u, RTR=%u, data={ ",
rxMsg.Id,
(uint16_t)rxMsg.DataLength,
(uint16_t)rxMsg.ExtendedFlag,
(uint16_t)rxMsg.RemoteFlag);
for (uint8_t i=0; i<rxMsg.DataLength; i++) {
printf("%02x ", rxMsg.Data.bytes[i]);
}
printf("}\n");*/
rxMsgFull = 0; //
}
}
return 0;
}