CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

my list not work

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
t90



Joined: 07 Aug 2008
Posts: 11
Location: saigon,vietnam

View user's profile Send private message Yahoo Messenger

my list not work
PostPosted: Sun Dec 07, 2008 10:12 am     Reply with quote

I'm working with 18f4550. I implement the static_list via array 20 element that every element is a struct. Main method in my list is insert(); In this function I invoke 2 function bcopy() (I tested this function and this work well) and memcmp() (exist in CCS PIC C). But when I test values in this array, the values are not the values I had inserted in the array. Someone give me some solution.
Code:

#include "18f4550.h"
#device HIGH_INTS=TRUE
#use delay(clock=20000000)
#fuses HS,NOPROTECT,NOLVP,NODEBUG,NOWDT
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)

#include "ewl_glcd.c"
#include "ewl_realtime.c"

char glcd_buff[128];
char xuat1[6];
char xuat2[6];
char xuat3[6];
char xuat4[6];
struct Node{
int time[4];
};/**/
struct Node tim[20];
static int num;
static int header;
static int tailer;
static int index;
static BYTE temp[4];



void bcopy(int *a, int *b) // This function requires 2 pointers
{
int i;
for (i = 0; i < 4; i++)
{
*b++ = *a++; // or *b++ = *a++; should work as well
}
}

//them vao 1 phan tu
int insert(int8 rtb[4]){
int temp1[4];
int temp2[4];
int temp3;
int count;
int1 flag;
count=0;
flag=1;
index=header;
if(num==20)//is ovrload?
return 0;//overflow
if(num==0){//overlow
//strcpy(tim[index].time,timt);
bcopy(rtb,tim[index].time);
tailer=index;
num=1;//increase number of element
return 1;//suc
}
//less than header
if(memcmp(tim[index].time,rtb,4)>0){
if(index==0){
index=19;
}else
index--;
bcopy(rtb,tim[index].time);
num++;
header=index;
return 1;
}
while(flag){//find the location of the element that greater than rtb
if(memcmp(tim[index].time,rtb,4)==0)//if equal
return 2;//the array has this value,return
else if(memcmp(tim[index].time,rtb,4)<0){//if less than
count++;//count is increased
if(count>num){//counter greater than the max number of element in this array
bcopy(rtb,tim[index].time);
tailer=index;
num++;
return 1;
}
if(index==19)//simulate the cyclic buffer
index=0;//index goback 0 when index reach the max index of array(19)
else
index++;
}
else
flag=0;
}
count=num-count;
bcopy(rtb,temp1);
for(count;count>0;count--){//change values of element form index to tailer
tailer=index;
bcopy(tim[index].time,temp2);
bcopy(temp1,tim[index].time);
bcopy(temp1,temp2);
if(index==19)
index=0;
else
index++;
}
num++;
return 1;
}


void main()
{

int a1[4];
int a2[4];
int a3[4];
int a4[4];
int a5[4];
int a6[4];
int receive1;
int receive2;
int receive3;
int cp1;
int cp2;
int cp3;
num=0;
header=0;
tailer=0;
temp[0]=0xFF;
temp[1]=0xFF;
temp[2]=0xFF;
temp[3]=0xFF;
a1[0]=0x00;
a1[1]=0x00;
a1[2]=0x00;
a1[3]=0x00;
a2[0]=0x01;
a2[1]=0x01;
a2[2]=0x01;
a2[3]=0x01;
a3[0]=0x02;
a3[1]=0x02;
a3[2]=0x02;
a3[3]=0x02;
a4[0]=0x03;
a4[1]=0x03;
a4[2]=0x03;
a4[3]=0x03;

receive1=insert(a1);
receive2=insert(a2);
receive3=insert(a3);
receive=insert(a3);
set_time();
set_tris_e(0x00);
set_tris_d(0x00);
set_tris_b(0xfc);
set_tris_c(0b10000000);
set_tris_a(0x00);
///////////////
glcd_init(ON);
glcd_fillScreen(OFF);
//glcd_text57_Vn(0,0,text,1,1);

//set up LCD
set_tris_c(get_tris_c()&0b11111011);
init_DS1307();

sprintf(xuat1,"%u-%u-%u-%u\n",tim[3].time[0],tim[3].time[1],tim[3].time[2],tim[3].time[3]);
sprintf(xuat3,"%u-%u-%u-%u\n",tim[4].time[0],tim[4].time[1],tim[4].time[2],tim[4].time[3]);
sprintf(xuat4,"%u-%u-%u-%u\n",tim[5].time[0],tim[5].time[1],tim[5].time[2],tim[5].time[3]);
while(1){
glcd_text57(20,20,xuat1,1,ON);//display element of the list
glcd_text57(20,30,xuat3,1,ON);
glcd_text57(20,40,xuat4,1,ON);
}
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group