Need some help to convert C code

I’am trying to convert this code to a pde but it just doesnt work form me :frowning:

#include <avr/pgmspace.h>
#include "leds.h"
#include "pic.h"
#include "sintab.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>

//Routine to read the sine table from sintab.h
const static char mysin(const char p) {
    if (p==-128) return mysin(0);
    if (p<-63) return -mysin(127+p);
    if (p<0) return -mysin(-p);
    if (p>63) return mysin(127-p);
    return pgm_read_byte(sintab+p);

//Calculates the value of the plasma at location x,y at time n.
const static unsigned char getpixel(const char x, const char y, const short n) {
    unsigned char p;

    //This is the base of the plasma: nothing more than some strange
    //random sine functions. Modify these to modify the shape of the plasma.
    //Take the sine of the result

    return p;

int main(void) {
    int x,y,n;
    //init led board
    //copy picture from pic.h to display memory
    for (x=0; x<512; x++) dispmem[x]=pgm_read_byte(picture+x);
    sei(); //let the ledboard-routine do it's job
    //Wait. Because the delay routine keeps getting interrupted by the
    //(processor intensive) led-board-routines, this'll take much longer than
    //the implicated 2 seconds (actually, almost 3 times as long.)
    for (x=0; x<200; x++) _delay_ms(10);

    //Go and generate plasma for all eternity :)
    while(1) {
      for (y=0; y<16; y++) {
          for (x=0; x<32; x++) {
            //Calculate the plasma value at that point and stuff it into the
            //display memory
    return 0;

Umm I’m really trying not to sound “UGLY” here…

There is definitely not enough information for anyone to really help you very much. EXAMPLE: We have no idea what is in PIC.H… and we can only assume how big SINTAB.H is. These two files sound like BIG structures to me.

The crazy thing is… “YOU” sort of have to know in advance (Before you start trying to translate the code) what will happen if you installed the regular AVRGCC package on your system and then compiled this source collection in it’s native form and then flashed it to the hardware since that’s is what it was written for…

Will it even work the hardware that is actually on your Arduino board?.

(I can’t tell, sorry) The ARDUINO isn’t magic and sometimes you really do need an BIG AVR CHIP with 1) enough memory and 2) NO BOOTLOADER.

I personally can’t tell see the whole picture with just a small slice of information.

Maybe telling us where you pulled the code from so we could all look at it as a whole?

thanks for your honest reply, but i got it working with a big avr chip ::)

So what's the problem?

Just a guess but this…

for (x=0; x<512; x++) dispmem[x]=pgm_read_byte(picture+x);

…implies a processor with less than 1K of memory isn’t going to work.

I suspect that’s what he meant by “big avr chip”; one with more memory.

  • Brian