Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

help me please

i'm a student working for the first time with altera DE2 board .i'm using the NIOSII soft processor with the altera monitor program (using C language)

i've some troubles with the program i wrote.i'm creating a dynamique list (ie using pointers) and at each time i creat a an element i display it in the seven segment display (i used the seven segment inorder to check if the elements of the dynamique list are created ) .the problem is that the program is not working (nothing is displayed ) so can you PLEASE help me and tell me what's wrong.

here is the program:

# include <stdio.h># include <stdlib.h># define HEX_BASE_ADDRESS 0x00021000# define SWITCHES_BASE_ADDRESS 0x00021010

/*__________________________~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

creat a node that enable us to work with the linked list */

struct node

{

int info;

struct node *link;

};

typedef struct node *NODE;

/*_________________________________________________________

get node */

NODE getnode()

{

NODE x;

x = (NODE)malloc(sizeof(struct node));

return x;

}

/*_______________________________________________________

insertion of an available place in the linked list */

NODE SortedInsert (int num,struct node**headRef)

{

NODE newNode;

newNode = getnode();

newNode->info = num;

newNode->link = NULL;

struct node *prev, *curr = *headRef;

if (*headRef == NULL || newNode-> info <= (*headRef) -> info)

{

newNode -> link = *headRef;

*headRef = newNode;

return newNode;

} else {

while (curr && curr -> info <= newNode -> info)

{

prev = curr;

curr = curr -> link;

}

prev -> link = newNode;

newNode -> link = curr;

return *headRef;

}

}

/*---------------------------------------*/

int get_hex (int NO)

{

int hexd;

if (NO==0x01)

{

return hexd=0x79;

}

else if (NO==0x02)

{

return hexd=0x24;

}

else if (NO==0x03)

{

return hexd=0x30;

}

else if (NO==0x04)

{

return hexd=0x19;

}

else if (NO==0x05)

{

return hexd=0x12;

}

else if (NO==0x06)

{

return hexd=0x02;

}

else

return hexd=0x40;

}

/*-------------------------------------*/

int main()

{

volatile int * switches = (int *) SWITCHES_BASE_ADDRESS;

int * hex=(int*) HEX_BASE_ADDRESS;

int num,NO,delay_count;//HEX_bit1;

NODE list1=NULL;

NODE temp;

while(1)

{

//printf("enter the code");

//scanf("%d",&num);

num= *(switches);

list1=SortedInsert(num,&list1);

if(list1 == NULL)

{

//printf("List is empty\n");

*(hex)=0x06;//display E

}

printf("The contents of the queue are\n");

temp=list1;

while(temp!=NULL)

{

NO=temp->info;

// printf("%d",NO);

*(hex)= get_hex (NO);

temp = temp->link;

for (delay_count = 5000000; delay_count != 0; --delay_count);

}

}

}

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Have you checked your displaying on seven segments only ?

    For displaying, I expected printf() or IOWR... or user function.

    your# define hex_base_address 0x00021000 may be wrong : it depends of your generated SOPC (I think you are using Altera example for DE2 board). In system.h (generated by sopc builder for quartus version <= 9.1) (or equivalent) you should look at, there are already# DEFINE for hardware.

    You should use IO_WR... functions : I think it takes care of wait time, delay, time hold... (I am not sure at 100%)

    Printf() your "list1" so as to see its value.

    The same "list1" doesn't change within you superloop (while(1))

    ++