Skip to content

Instantly share code, notes, and snippets.

@dimme
Created April 10, 2013 01:35
Show Gist options
  • Save dimme/5351038 to your computer and use it in GitHub Desktop.
Save dimme/5351038 to your computer and use it in GitHub Desktop.
/* ATMEL ATMEGA16 POV program made by Dimme.net */
#include "avr/io.h"
#define SPACE 100
#define SHORTLINE 100
#define MIDLINE 300
#define RSPACE 400
void ch(char);
void write(char*);
void wait(unsigned long int);
void led(unsigned long int);
void alloff();
void init();
unsigned long int mirror(unsigned long int, unsigned int);
int main(void){
init();
unsigned long int i,j;
while(1){
write("HAI");
}
}
void write(char* w){
unsigned int i = 0;
while (w[i] != 0){
ch(w[i]);
i++;
}
}
void ch(char c){
if (c == 'A') {
led(0b0011111111110000);
wait(SHORTLINE);
led(0b1100001100000000);
wait(MIDLINE);
led(0b0011111111110000);
wait(SHORTLINE);
alloff();
wait(SPACE);
} else if (c == 'H') {
led(0b1111111111110000);
wait(SHORTLINE);
alloff();
led(0b0000011000000000);
wait(MIDLINE);
alloff();
led(0b1111111111110000);
wait(SHORTLINE);
alloff();
wait(SPACE);
} else if (c == 'I') {
led(0b1100000000110000);
wait(SHORTLINE);
alloff();
led(0b1111111111110000);
wait(SHORTLINE);
alloff();
led(0b1100000000110000);
wait(SHORTLINE);
alloff();
wait(SPACE);
} else if (c == ' ') {
wait(RSPACE);
}
}
void wait(unsigned long int j){
unsigned long int i;
for(i = 0; i < j; i++);
}
void led(unsigned long int n){
PORTA = (n >> 15) * 0b10;
PORTB = mirror((n >> 7) << 1,9);
PORTD = mirror(n,16) >> 9;
}
void alloff(){
PORTD = 0;
PORTB = 0;
PORTA = 0;
}
void init(){
DDRD = (1<<DDD6)|(1<<DDD5)|(1<<DDD4)|(1<<DDD3)|(1<<DDD2)|(1<<DDD1)|(1<<DDD0);
DDRB = (1<<DDB7)|(1<<DDB6)|(1<<DDB5)|(1<<DDB4)|(1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0);
DDRA = (1<<DDA1);
alloff();
}
unsigned long int mirror(unsigned long int n, unsigned int size){
int i;
unsigned long int nb = 0;
for (i = size-1; i >= 0; i--){
int last = 0;
if (n%2 != 0) last = 1;
nb |= last;
if (i != 0) nb *= 2;
n >>= 1;
}
return nb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment