Sie sind auf Seite 1von 10

miniPOV with Atmega328P

/*
* miniPOV_atmega328p.cpp
*
* Created: 09.09.2015 19:38:46
* Author: Cristi
*/

#ifndef F_CPU
#define F_CPU 20000000UL
#endif

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <string.h>
#include "font.h"
int j,k,rot=1,sec=-4;
uint_fast16_t ms[77],mj[77];
typedef struct{
volatile uint8_t *pr;
uint8_t pn;
}dap;
dap v[16];
uint16_t
cruce2[10]={0x1820,0x2420,0x2428,0x2428,0x1FFE,0x1FFE,0x2428,0x2428,0x
2420,0x1820};

uint16_t
cruce[10]={0x0C00,0x0C00,0x0C00,0x0C00,0xFFFF,0xFFFF,0x0C00,0x0C00,0x0
C00,0x0C00};
uint16_t
fulger[10]={0x8000,0x4080,0x30C0,0x1CF0,0x0FFC,0x07FE,0x01FE,0x00E6,0x0
062,0x0020};
uint_fast16_t
vs[16]={0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100
,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000};
uint_fast16_t
vj[16]={0x8000,0x4000,0x2000,0x1000,0x0800,0x0400,0x0200,0x0100,0x0080,
0x0040,0x0020,0x0010,0x0008,0x0004,0x0002,0x0001};
void write(uint8_t led,bool st){
if(st)
*v[led].pr|=(1<<v[led].pn);
else
*v[led].pr&=~(1<<v[led].pn);
}
void delayus(int d){
for(j=1;j<=d;j++)_delay_us(1);
}
int i;
uint16_t doublebinary(uint8_t x){
int ret=0,db=0;
for(int bt=0;bt<8;bt++){
ret+=(x&(1<<bt))<<db;
db++;
ret+=(x&(1<<bt))<<db;
}
return ret;
}
void ScrieLiteraSus(int cl,int ln,char ch){

if (ch < 32 || ch > 126){


ch = 32;
}
// subtract the space character (converts the ASCII number to the font
index number)
ch -= 32;
if(ln<2){
for(int wh=0;wh<5;wh++){
ms[cl*6+wh]&=~(0xFF<<ln*8);
ms[cl*6+wh]|=font[int(ch)][wh]<<(ln*8);
}
}
else{
for(int wh=0;wh<5;wh++){
ms[cl*12+wh*2]=0;
ms[cl*12+wh*2+1]=0;
ms[cl*12+wh*2]=doublebinary(font[int(ch)][wh]);
ms[cl*12+wh*2+1]=doublebinary(font[int(ch)][wh]);
}
}
}
void ScrieCharSus(int ln,int cl,unsigned int r[]){
if(ln<2){
for(int wh=0;wh<5;wh++){
ms[cl*6+wh]&=~(0xFF<<ln*8);
ms[cl*6+wh]|=r[wh]<<(ln*8);
}
}
else{

for(int wh=0;wh<10;wh++)
ms[cl*12+wh]=r[wh];
}
}
void ScrieCharJos(int ln,int cl,unsigned int r[]){
if(ln<2){
for(int wh=0;wh<5;wh++){
mj[cl*6+wh]&=~(0xFF<<ln*8);
mj[cl*6+wh]|=r[wh]<<(ln*8);
}
}
else{
for(int wh=0;wh<10;wh++)
mj[cl*12+wh]=r[wh];
}
}
void ScrieLiteraJos(int cl,int ln,char ch){
if (ch < 32 || ch > 126){
ch = 32;
}
// subtract the space character (converts the ASCII number to the font
index number)
ch -= 32;
if(ln<2){
for(int wh=0;wh<5;wh++){
mj[cl*6+wh]&=~(0xFF<<(ln*8));
mj[cl*6+wh]|=font[int(ch)][wh]<<(ln*8);
}
}

else{
for(int wh=0;wh<5;wh++){
mj[cl*12+wh*2]=0;
mj[cl*12+wh*2+1]=0;
mj[cl*12+wh*2]=doublebinary(font[int(ch)][wh]);
mj[cl*12+wh*2+1]=doublebinary(font[int(ch)][wh]);
}
}
}
void ScrieSus(int ln,int cl,char *st){
for(int nc=0;st[nc]!='\0';nc++)
ScrieLiteraSus(cl+nc,ln,st[nc]);
}
void ScrieJos(int ln,int cl,char *st){
for(int nc=0;st[nc]!='\0';nc++)
ScrieLiteraJos(cl+nc,ln,st[nc]);
}
void ClearSus(){
for(i=0;i<77;i++)
ms[i]=0x0000;
}
void ClearJos(){
for(i=0;i<77;i++)
mj[i]=0x0000;
}
int main(void)
{
v[0].pr=&PORTB;v[0].pn=1;

v[1].pr=&PORTB;v[1].pn=0;
v[2].pr=&PORTD;v[2].pn=7;
v[3].pr=&PORTD;v[3].pn=6;
v[4].pr=&PORTD;v[4].pn=5;
v[5].pr=&PORTD;v[5].pn=4;
v[6].pr=&PORTD;v[6].pn=3;
v[7].pr=&PORTD;v[7].pn=2;
v[8].pr=&PORTD;v[8].pn=1;
v[9].pr=&PORTD;v[9].pn=0;
v[10].pr=&PORTC;v[10].pn=5;
v[11].pr=&PORTC;v[11].pn=4;
v[12].pr=&PORTC;v[12].pn=3;
v[13].pr=&PORTC;v[13].pn=2;
v[14].pr=&PORTC;v[14].pn=1;
v[15].pr=&PORTC;v[15].pn=0;
DDRB=0x03;
DDRD=0xFF;
DDRC=0x3F;
PORTB=0;
PORTC=0;
PORTD=0;
//timer2_init();
ClearSus();
ClearJos();
ScrieSus(2,0,"Turbo");
ScrieJos(2,1,"Lover");
while(1)
{

if(!(PINB&0x08)){
rot++;
for(i=76;i>=0;i--)
for(j=0;j<16;j++){
write(15-j,ms[i]&vs[j]);
//_delay_us(1);
}
_delay_us(30);
for(i=0;i<16;i++)
write(i,0);
_delay_us(600);
for(i=0;i<77;i++)
for(j=15;j>=0;j--){
write(j,mj[i]&vs[j]);
//_delay_us(1);
}
_delay_us(30);
for(i=0;i<16;i++)
write(i,0);
}
if(rot==250){sec++;rot=0;}
if(sec>13)sec=0;
if(rot==0){
if(sec==0)
{
ClearJos();
ClearSus();
ScrieSus(0,0,"Turbo Lover");

ScrieSus(1,0,"Judas Priest");
ScrieJos(1,1,"Turbo Lover");
ScrieJos(0,2,"I'm your");
}
if(sec==2){
ClearJos();
ClearSus();
ScrieSus(0,1,"I Was Made");
ScrieSus(1,1,"For Lovin'");
ScrieJos(0,2,"You Baby");
ScrieJos(1,4,"KISS");

}
if(sec==4){
ClearJos();
ClearSus();
ScrieSus(0,0,"Judas Priest");
ScrieSus(1,1,"Nightwish");
ScrieJos(0,2,"Bucovina");
ScrieJos(1,3,"Burzum");
}
if(sec==6){
ClearJos();
ClearSus();
ScrieSus(0,1,"Eluveitie");
ScrieSus(1,1,"Moonspell");
ScrieJos(0,3,"Nirvana");
ScrieJos(1,0,"Septic Flesh");

}
if(sec==8){
ClearJos();
ClearSus();
ScrieSus(0,2,"Roses are");
ScrieSus(1,4,"Gay");
ScrieJos(0,1,"Violets are");
ScrieJos(1,4,"Gayer");
}
if(sec==9){
ClearJos();
ClearSus();
ScrieSus(0,2,"Fuck this");
ScrieSus(1,4,"Poem");
ScrieJos(0,1,"And Listen");
ScrieJos(1,2,"to SLAYER");
}
if(sec==10){
ClearJos();
ClearSus();
ScrieSus(2,1,"AC DC");
ScrieCharSus(2,3,fulger);
ScrieJos(1,0,"Rock N' Roll");
}
if(sec==12){
ClearSus();
ClearJos();
ScrieSus(0,4,"Corpus");

ScrieSus(1,3,"Christii");
ScrieCharJos(2,2,cruce);
ScrieCharJos(2,4,cruce);
ScrieCharJos(2,3,cruce2);
}
if(sec==-2){
ClearSus();
ClearJos();
ScrieSus(0,4,"Three");
ScrieSus(1,4,"Happy");
ScrieJos(2,0,"Months");
}
}
/*for(k=strlen(string1);k>=0;k--)
printLetterboven(string1[k]);*/
//TODO:: Please write your application code
}
}