mega168 version

This commit is contained in:
Olaf Rempel 2010-03-13 00:01:50 +01:00
parent 526dbbf4ee
commit 8250d528a5
8 changed files with 98 additions and 49 deletions

140
5x7test.c
View File

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 02/2010 by Olaf Rempel *
* Copyright (C) 03/2010 by Olaf Rempel *
* razzor@kopf-tisch.de *
* *
* This program is free software; you can redistribute it and/or modify *
@ -20,71 +20,109 @@
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#define F_CPU 3686400
#define F_CPU 8000000
#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)
*/
#define nop() asm volatile ("nop")
/* 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 nCLEAR PB0
#define RCLK PB1
#define nOE PB2
#define MOSI PB3
#define MISO PB3
#define SCK PB5
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
static const char text[] = " <<<AT90S2313:Scrolltext-Demo>>>";
static const char text[] = " <<<atmega168:Scrolltext-Demo>>> ";
/* scrollbuffer */
static volatile uint8_t data[5 + 1 + 5];
static volatile uint8_t data[32];
static volatile uint8_t offset;
void setRow(uint8_t row)
{
uint8_t i;
volatile uint8_t *p = data + offset + 19;
row = (1 << row);
/* bit-banging spi, 20 cols */
for (i = 0; i < 20; i++) {
PORTB &= ~(1<<MISO);
if (*p-- & row)
PORTB |= (1<<MOSI);
PORTB |= (1<<SCK);
PORTB &= ~(1<<SCK);
/* insert extra cols (unused hc595 outputs) */
if (i == 5 || i == 12 || i == 19) {
PORTB |= (1<<SCK);
PORTB &= ~(1<<SCK);
}
}
/* disable outputs, update register */
PORTB |= ((1<<nOE) | (1<<RCLK));
/* select row */
PORTC |= 0x07;
PORTC &= ~(row & 0x07);
PORTD |= 0x78;
PORTD &= ~(row & 0x78);
/* enable outputs again */
PORTB &= ~((1<<nOE) | (1<<RCLK));
}
ISR(SIG_OVERFLOW0)
{
static uint8_t col;
/* ~2,8ms */
TCNT0 = 0xFF - 40;
static uint8_t row;
COL_DATA(0x00);
COL_SEL(1 << col);
COL_DATA(data[offset + col]);
/* 2ms */
TCNT0 = 0xFF - 64;
col = (col == 5) ? 0 : col + 1;
setRow(row++);
if (row == 7)
row = 0;
}
int main(void)
{
/* row 1-3 */
DDRC = 0x07;
PORTC = 0x07;
/* row 4-7 */
DDRD = 0x78;
PORTD = 0x78;
/* ctrl signals */
DDRB = (1<<nCLEAR) | (1<<RCLK) | (1<<nOE) | (1<<MOSI) | (1<<SCK);
PORTB = (1<<nCLEAR) | (1<<nOE);
/* F_CPU/256, Overflow Interrupt */
TCCR0B = (1<<CS02);
TIMSK0 = (1<<TOIE0);
sei();
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') {
if (text[pos +3] == '\0') {
pos = 0;
mode++;
break;
} else {
pos++;
@ -92,27 +130,37 @@ int main(void)
}
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);
int i;
for (i = 0; i < 5; i++) {
memcpy_P((void *)&data[i * 6], font[(uint8_t)text[pos + i]], 5);
}
}
offset++;
delay = 12;
delay = 6;
break;
case 1:
memcpy_P((void *)&data[0], &font[pos], 5);
if (offset == 6) {
offset = 0;
if (pos == (ARRAY_SIZE(font) -3)) {
pos = 0;
mode++;
if (pos == (ARRAY_SIZE(font) -1)) {
pos = 0;
mode++;
break;
} else {
pos++;
} else {
pos++;
}
}
delay = 20;
if (offset == 0) {
int i;
for (i = 0; i < 5; i++) {
memcpy_P((void *)&data[i * 6], font[(uint8_t)pos + i], 5);
}
}
offset++;
delay = 6;
break;
default:

View File

@ -1,3 +1,4 @@
// font from http://www.mikrocontroller.net/topic/54860 */
const prog_char font[][5]={
{0x00,0x00,0x00,0x00,0x00}, // 0x00
{0x1E,0x35,0x31,0x35,0x1E}, // 0x01

View File

@ -1,6 +1,6 @@
PRG = 5x7test
OBJ = 5x7test.o
MCU_TARGET = at90s2313
MCU_TARGET = atmega168
OPTIMIZE = -Os
DEFS =
@ -41,5 +41,5 @@ bin: $(PRG).bin
$(OBJCOPY) -j .text -j .data -O binary $< $@
install: all
avrdude -p 2313 -c avr910 -b 115200 -P /dev/ttyUSB0 -e -V -U flash:w:$(PRG).hex
# avrdude -c dragon_isp -P usb -p 2313 -B 2 -e -V -U flash:w:$(PRG).hex
# avrdude -p 2313 -c avr910 -b 115200 -P /dev/ttyUSB0 -e -V -U flash:w:$(PRG).hex
avrdude -c dragon_isp -P usb -p m168 -e -V -U flash:w:$(PRG).hex

BIN
eagle/5x7led-bot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
eagle/5x7led-sch.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

BIN
eagle/5x7led-top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
eagle/5x7led.brd Normal file

Binary file not shown.

BIN
eagle/5x7led.sch Normal file

Binary file not shown.