C for Minipov2

MiniPOV4 and previous versions

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
eman12
 
Posts: 3
Joined: Fri May 20, 2011 4:18 pm

C for Minipov2

Post by eman12 »

Hello guys,

Sorry but I am a newbie.

I have built the MiniPOV2 and it does work nicely. Unfortunately I do not know to interpret the C instructions wrote for it! I have worked with atmega16 but here the instructions are somewhat strange.
http://www.ladyada.net/make/minipov2/

Is any expert able to help me out plz?

Thanks a bunch

eman12
 
Posts: 3
Joined: Fri May 20, 2011 4:18 pm

Re: C for Minipov2

Post by eman12 »

For instance what the below instruction does actually? What are those binary codes? If they are for turning the LEDs on/ of then how to decide which code to be used for a word (say for instance the word "M").
[Edit - moderator - use code block]

Code: Select all


#include <avr/io.h>      // this contains all the IO port definitions
#include <avr/interrupt.h>
#include <avr/signal.h>

#define TIMER1_PRESCALE_1 1
#define TIMER1_PRESCALE_8 2
#define TIMER1_PRESCALE_64 3
#define TIMER1_PRESCALE_256 4
#define TIMER1_PRESCALE_1024 5

#define HEX__(n) 0x##n##UL

#define B8__(x) ((x&0x0000000FLU)?1:0)  \
               +((x&0x000000F0LU)?2:0)  \
               +((x&0x00000F00LU)?4:0)  \
               +((x&0x0000F000LU)?8:0)  \
               +((x&0x000F0000LU)?16:0) \
               +((x&0x00F00000LU)?32:0) \
               +((x&0x0F000000LU)?64:0) \
               +((x&0xF0000000LU)?128:0)

#define B8(d) ((unsigned char)B8__(HEX__(d)))

const static int image[] = {
  B8(00111100),
  B8(00000100),
  B8(00111000),
  B8(00000100),
  B8(00111000),
  B8(00000000),
  B8(00111101),
  B8(00000000),
  B8(00111100),
  B8(00000100),
  B8(00000100),
  B8(00111000),
  B8(00000000),
  B8(00111101),
  B8(00000000),
  B8(11111100),
  B8(00100100),
  B8(00100100),
  B8(00011000),
  B8(00000000),
  B8(00011000),
  B8(00100100),
  B8(00100100),
  B8(00011000),
  B8(00000000),
  B8(00000100),
  B8(00111000),
  B8(00010000),
  B8(00001100),
  B8(00000000),
  B8(00101111),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
};

int imagesize = 35;


// This function basically wastes time, in case you want to
// do some other timing stuff
void delay_ms(long int ms) {
  unsigned long int timer;

  while (ms != 0) {
    // this number is dependant on the clock frequency
    for (timer=0; timer <= 4200; timer++);
    ms--;
  }
}

// this function is called when timer1 compare matches OCR1A
uint8_t j = 0;
SIGNAL( SIG_TIMER1_COMPA ) {
  if (j >= imagesize) 
    j = 0;

  PORTB = image[j];
 
  j++;
}

int main(void) {

  DDRB = 0xFF;       // set all 8 pins on port B to outputs

  /*
    the frequency of the interrupt overflow is determined by the 
    prescaler and overflow value.
    freq = clock_frequency / ( 2 * prescaler * overflow_val)
    where prescaler can be 1, 8, 64, 256, or 1024
    clock_freq is 8MHz
    and overflow_val is 16bit

    the overflow value is placed in OCR1A, the prescale is set in TCCR1B
    so for example:
    A good POV frequency is around 400Hz
    desired freq = 400Hz
    clock freq = 8MHz
    8MHz / (400Hz * 2) = 10000
    since 10000 is less than 655536 (largest 16 bit number)
    OCR1A = 10000 and the prescale is 1
  */

  TCCR1B = (1 << WGM12) | TIMER1_PRESCALE_1;
  OCR1A = (uint16_t)10000;

  TIMSK |= 1 << OCIE1A;   // Output Compare Interrupt Enable (timer 1, OCR1A) 

  sei();                 // Set Enable Interrupts

  while (1);
}

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: C for Minipov2

Post by adafruit_support_bill »

These binary codes define the image. Each line defines the state of the 8 LEDs (0 = off, 1 = on). The rest of the code cycles throught these lines in succession to create the POV image. If you look at them sideways, you can sort of see the pattern. Remember, all the 1's will be lit up. I've added some comments below to illustrate.

Code: Select all

const static int image[] = {
 // these lines make a lower case 'm'
  B8(00111100),
  B8(00000100),
  B8(00111000),
  B8(00000100),
  B8(00111000),

// blank space between letters
  B8(00000000),

// this line is an 'i'
  B8(00111101),

// another blank space
  B8(00000000),

// These lines make an 'n'
  B8(00111100),
  B8(00000100),
  B8(00000100),
  B8(00111000),

  B8(00000000),
  B8(00111101),
  B8(00000000),
  B8(11111100),
  B8(00100100),
  B8(00100100),
  B8(00011000),
  B8(00000000),
  B8(00011000),
  B8(00100100),
  B8(00100100),
  B8(00011000),
  B8(00000000),
  B8(00000100),
  B8(00111000),
  B8(00010000),
  B8(00001100),
  B8(00000000),
  B8(00101111),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
};

eman12
 
Posts: 3
Joined: Fri May 20, 2011 4:18 pm

Re: C for Minipov2

Post by eman12 »

arduwino wrote:These binary codes define the image. Each line defines the state of the 8 LEDs (0 = off, 1 = on). The rest of the code cycles throught these lines in succession to create the POV image. If you look at them sideways, you can sort of see the pattern. Remember, all the 1's will be lit up. I've added some comments below to illustrate.

Code: Select all

const static int image[] = {
 // these lines make a lower case 'm'
  B8(00111100),
  B8(00000100),
  B8(00111000),
  B8(00000100),
  B8(00111000),

// blank space between letters
  B8(00000000),

// this line is an 'i'
  B8(00111101),

// another blank space
  B8(00000000),

// These lines make an 'n'
  B8(00111100),
  B8(00000100),
  B8(00000100),
  B8(00111000),

  B8(00000000),
  B8(00111101),
  B8(00000000),
  B8(11111100),
  B8(00100100),
  B8(00100100),
  B8(00011000),
  B8(00000000),
  B8(00011000),
  B8(00100100),
  B8(00100100),
  B8(00011000),
  B8(00000000),
  B8(00000100),
  B8(00111000),
  B8(00010000),
  B8(00001100),
  B8(00000000),
  B8(00101111),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
  B8(00000000),
};

Oh, Thanks sir, I got it.

Can yo tell me how to convert these instructions to the HEX for tiny2313?

Thanks gain

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: C for Minipov2

Post by adafruit_support_bill »

You need to use WinAVR and the AVRDUDE software. Follow the instrcutions here: http://www.ladyada.net/make/minipov3/software.html

Locked
Please be positive and constructive with your questions and comments.

Return to “MiniPOV”