5x7led/5x7test.c

130 lines
3.0 KiB
C

/***************************************************************************
* Copyright (C) 02/2010 by Olaf Rempel *
* razzor@kopf-tisch.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; version 2 of the License, *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#define F_CPU 3686400
#include <util/delay.h>
#include "6x8_vertikal_LSB_1.h"
/*
* at90s2313 pinout:
* PB0-4 => LED C1-5
* PB5-7 => free/ISP
* PD0-6 => LED R1-7 (with 100R resistors)
*/
/* for TC12-11 */
//#define COL_SEL(x) PORTB = ~(x)
//#define COL_DATA(x) PORTD = (x)
/* for TA12-11 */
#define COL_SEL(x) PORTB = (x)
#define COL_DATA(x) PORTD = ~(x)
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
static const char text[] = " <<<AT90S2313:Scrolltext-Demo>>>";
/* scrollbuffer */
static volatile uint8_t data[5 + 1 + 5];
static volatile uint8_t offset;
ISR(SIG_OVERFLOW0)
{
static uint8_t col;
/* ~2,8ms */
TCNT0 = 0xFF - 40;
COL_DATA(0x00);
COL_SEL(1 << col);
COL_DATA(data[offset + col]);
col = (col == 5) ? 0 : col + 1;
}
int main(void)
{
uint8_t mode = 0;
uint8_t pos = 0;
uint8_t delay = 0;
DDRB = 0x1F;
DDRD = 0x7F;
/* Timer0: FCPU/256 */
TCCR0 = (1<<CS02);
TIMSK = (1<<TOIE0);
sei();
while (1) {
switch (mode)
{
case 0:
if (offset == 6) {
offset = 0;
if (text[pos +1] == '\0') {
pos = 0;
mode++;
break;
} else {
pos++;
}
}
if (offset == 0) {
memcpy_P((void *)&data[0], font[(uint8_t)text[pos]], 5);
memcpy_P((void *)&data[1 + 5], font[(uint8_t)text[pos +1]], 5);
}
offset++;
delay = 12;
break;
case 1:
memcpy_P((void *)&data[0], &font[pos], 5);
if (pos == (ARRAY_SIZE(font) -1)) {
pos = 0;
mode++;
break;
} else {
pos++;
}
delay = 20;
break;
default:
mode = 0;
delay = 0;
break;
}
while (delay--)
_delay_ms(10);
}
return 0;
}