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 support@ccsinfo.com

1D to 2D array

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







1D to 2D array
PostPosted: Sun Dec 15, 2002 2:14 pm     Reply with quote

Hello pic c gurus
i would be pleased if someone can help me out this
problem.
i am trying to convert the 1D array pat[32] to a
2D array then send this to port b.
this works perfectly as a 1D array so i need to change
CHAR const pat[32] to a 2D array and also
where port_b = pat[index] to port_b=pat[down][across];
but the display don't work at all i have being trying
to see where i am going wrong for a few nights with no joy
so guys i do really need your help here.

Thanks in advance
Isaac

(oo)
\/
/( )\
/(____)\
~ ~





#include <16F876.H>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)


#IFNDEF EXP_OUT_ENABLE
#define Row 4
#define Col 8
#define EXP_OUT_ENABLE PIN_C2
#define EXP_OUT_CLOCK PIN_C1
#define EXP_OUT_DO PIN_C0
#define NUMBER_OF_74595 4
#ENDIF
#include <74595.C>

#byte port_a=5
#byte port_b=6
#byte port_c=7



char const pat[Row][Col]={
//CHAR const pat[32] = {
0,0xfc,0xfe,0x33,0x33,0xfe,0xfe,0, /* Fort A*/
0,0xff,0xff,0xdb,0xdb,0xff,0x66,0, /* Font B*/
0,0x7e,0xff,0xc3,0xc3,0xc3,0xc3,0, /* Font C*/
0,0xff,0xff,0xc3,0xc3,0xff,0x7e,0, /* Font D*/
};







main() // array holds the character maps for ABCD which scrolls//
{
int mask[4];
int data[4]; // array to store our data since i am
int delaycount;
int startposition;
int index;
int i,nelly;
int down,across;
set_tris_c(0);
set_tris_b(0);
port_c = 0;
port_b = 0;
startposition = 0;
while(1)
{
delaycount = 3; // adjust this value to control scrolls speed
while (delaycount)
{
index = startposition;

mask[0]=0x01; // Initialize our mask
mask[1]=0x00;
mask[2]=0x00;
mask[3]=0x00;

for (i=0; i<32; i++) // we have 32 columns to drive
{
// store our mask in an array. we need to do this because
// the call to write_expanded_outputs will destroy the value
// passed in.
data[0] = mask[0]; // store which column we are driving
data[1] = mask[1]; // in an array
data[2] = mask[2];
data[3] = mask[3];
index = i + startposition; // point to the next pattern to display
if (index >= sizeof(pat)) // make sure that we don't exceed the array
index -= sizeof(pat);
port_b = 0; // disable driving the LEDs
write_expanded_outputs(data); // enable our column driver
// port_b = pat[index]; // drive our LEDs
/////////////////////////////////////////////////////////////////////////////////////////////////////////
nelly=i\%8;
for(down=0;down<Row;down++)
for (across =0;across port_b=pat[down][across];
printf("\%x",pat[down][across]);
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//printf("\%x",pat[index],"\r\n");
if (shift_left(mask,4,0))
mask[0] = 0x01;
// shift to the next column for next time
delay_us(700); // adjust this value to control the drive time
//for the leds
}
--delaycount; // decrement our delay loop counter
}
++startposition; // Point to the next data pattern
if (startposition >= sizeof(pat)) // make sure that we don't exceed the array
{
startposition = 0;

}

}

}









___________________________
This message was ported from CCS's old forum
Original Post ID: 10055
isaac aiyanyo
Guest







Re: 1D to 2D array (sorted)
PostPosted: Sun Dec 15, 2002 3:59 pm     Reply with quote

I have managed to get the display to work now
but i still now help in making it scroll
the scroll don't work anymore so if you have any
suggestions it would be highly welcomed

:= Thanks in advance
:= Isaac
:=
:= (oo)
:= \/
:= /( )\
:= /(____)\
:= ~ ~
:=
:=
:=
:=
:=
:=#include <16F876.H>
:=#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
:=#use delay(clock=20000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
:=
:=
:=#IFNDEF EXP_OUT_ENABLE
:=#define Row 4
:=#define Col 8
:=#define EXP_OUT_ENABLE PIN_C2
:=#define EXP_OUT_CLOCK PIN_C1
:=#define EXP_OUT_DO PIN_C0
:=#define NUMBER_OF_74595 4
:=#ENDIF
:=#include <74595.C>
:=
:=#byte port_a=5
:=#byte port_b=6
:=#byte port_c=7
:=
:=
:=
:=char const pat[Row][Col]={
:=//CHAR const pat[32] = {
:= 0,0xfc,0xfe,0x33,0x33,0xfe,0xfe,0, /* Fort A*/
:= 0,0xff,0xff,0xdb,0xdb,0xff,0x66,0, /* Font B*/
:= 0,0x7e,0xff,0xc3,0xc3,0xc3,0xc3,0, /* Font C*/
:= 0,0xff,0xff,0xc3,0xc3,0xff,0x7e,0, /* Font D*/
:= };
:=
:=
:=
:=
:=
:=
:=
:=main() // array holds the character maps for ABCD which scrolls//
:={
:=int mask[4];
:=int data[4]; // array to store our data since i am
:=int delaycount;
:=int startposition;
:=int index;
:=int i,nelly;
:=int down,across;
:=set_tris_c(0);
:=set_tris_b(0);
:=port_c = 0;
:=port_b = 0;
:=startposition = 0;
:=while(1)
:= {
:= delaycount = 3; // adjust this value to control scrolls speed
:= while (delaycount)
:= {
:= index = startposition;
:=
:= mask[0]=0x01; // Initialize our mask
:= mask[1]=0x00;
:= mask[2]=0x00;
:= mask[3]=0x00;
:=
:= for (i=0; i<32; i++) // we have 32 columns to drive
:= {
:= // store our mask in an array. we need to do this because
:= // the call to write_expanded_outputs will destroy the value
:= // passed in.
:= data[0] = mask[0]; // store which column we are driving
:= data[1] = mask[1]; // in an array
:= data[2] = mask[2];
:= data[3] = mask[3];
:= index = i + startposition; // point to the next pattern to display
:= if (index >= sizeof(pat)) // make sure that we don't exceed the array
:= index -= sizeof(pat);
:= port_b = 0; // disable driving the LEDs
:= write_expanded_outputs(data); // enable our column driver
:= // port_b = pat[index]; // drive our LEDs
:=/////////////////////////////////////////////////////////////////////////////////////////////////////////
:= nelly=i\%8;
:= for(down=0;down<Row;down++)
:= for (across =0;across := port_b=pat[down][across];
:= printf("\%x",pat[down][across]);
:=/////////////////////////////////////////////////////////////////////////////////////////////////////////
:= //printf("\%x",pat[index],"\r\n");
:= if (shift_left(mask,4,0))
:= mask[0] = 0x01;
:= // shift to the next column for next time
:= delay_us(700); // adjust this value to control the drive time
:= //for the leds
:= }
:= --delaycount; // decrement our delay loop counter
:= }
:= ++startposition; // Point to the next data pattern
:= if (startposition >= sizeof(pat)) // make sure that we don't exceed the array
:= {
:= startposition = 0;
:=
:= }
:=
:= }
:=
:=}
:=
:=
:=
:=
:=
:=
:=
:=
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 10056
isaac aiyanyo
Guest







Re: 1D to 2D array
PostPosted: Sun Dec 15, 2002 4:03 pm     Reply with quote

i forgot to include the code
here it is.
Thanks in advance
Isaac

(oo)
\/
/( )\
/(____)\
~ ~

#include <16F876.H>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)


#IFNDEF EXP_OUT_ENABLE

#define EXP_OUT_ENABLE PIN_C2
#define EXP_OUT_CLOCK PIN_C1
#define EXP_OUT_DO PIN_C0
#define NUMBER_OF_74595 4
#ENDIF
#include <74595.C>

#byte port_a=5
#byte port_b=6
#byte port_c=7



char const pat[4][8]={
//CHAR const pat[40] = {
0,0xfc,0xfe,0x33,0x33,0xfe,0xfe,0, /* Fort A*/
0,0xff,0xff,0xdb,0xdb,0xff,0x66,0, /* Font B*/
0,0x7e,0xff,0xc3,0xc3,0xc3,0xc3,0, /* Font C*/
0,0xff,0xff,0xc3,0xc3,0xff,0x7e,0, /* Font D*/
};







main() // array holds the character maps for ABCD which scrolls//
{
int mask[4];
int data[4]; // array to store our data since i am
int delaycount;
int startposition;
int index;
int i,x,nelly;
signed int down;
signed int across=8;
set_tris_c(0);
set_tris_b(0);
port_c = 0;
port_b = 0;
startposition = 0;
while(1)
{
delaycount = 2; // adjust this value to control scrolls speed
while (delaycount)
{
index = startposition;

mask[0]=0x01; // Initialize our mask
mask[1]=0x00;
mask[2]=0x00;
mask[3]=0x00;
down=-1;
for (i=0; i<32; i++) // we have 32 columns to drive
{
// store our mask in an array. we need to do this because
// the call to write_expanded_outputs will destroy the value
// passed in.
data[0] = mask[0]; // store which column we are driving
data[1] = mask[1]; // in an array
data[2] = mask[2];
data[3] = mask[3];
index = i + startposition; // point to the next pattern to display
if (index >= sizeof(pat)) // make sure that we don't exceed the array
index -= sizeof(pat);
port_b = 0; // disable driving the LEDs
write_expanded_outputs(data); // enable our column driver
// port_b = pat[index]; // drive our LEDs
/////////////////////////////////////////////////////////////////////////////////////////////////////////

across=i\%8;
if (!across) down++; //this should be ok
//BEWARE nothing stops 'down'
port_b = pat[down][across]; //incrementing beyond the array size
//so down is given a value of
// -1 outside the loop
// there might be another way!

/////////////////////////////////////////////////////////////////////////////////////////////////////////

if (shift_left(mask,4,0))
mask[0] = 0x01;
// shift to the next column for next time
delay_us(700); // adjust this value to control the drive time
//for the leds
}
--delaycount; // decrement our delay loop counter
}
++startposition; // Point to the next data pattern
if (startposition >= sizeof(pat)) // make sure that we don't exceed the array
{
startposition = 0;

}

}

}


:=
:=
:=
:=#include <16F876.H>
:=#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
:=#use delay(clock=20000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT,ERRORS)
:=
:=
:=#IFNDEF EXP_OUT_ENABLE
:=#define Row 4
:=#define Col 8
:=#define EXP_OUT_ENABLE PIN_C2
:=#define EXP_OUT_CLOCK PIN_C1
:=#define EXP_OUT_DO PIN_C0
:=#define NUMBER_OF_74595 4
:=#ENDIF
:=#include <74595.C>
:=
:=#byte port_a=5
:=#byte port_b=6
:=#byte port_c=7
:=
:=
:=
:=char const pat[Row][Col]={
:=//CHAR const pat[32] = {
:= 0,0xfc,0xfe,0x33,0x33,0xfe,0xfe,0, /* Fort A*/
:= 0,0xff,0xff,0xdb,0xdb,0xff,0x66,0, /* Font B*/
:= 0,0x7e,0xff,0xc3,0xc3,0xc3,0xc3,0, /* Font C*/
:= 0,0xff,0xff,0xc3,0xc3,0xff,0x7e,0, /* Font D*/
:= };
:=
:=
:=
:=
:=
:=
:=
:=main() // array holds the character maps for ABCD which scrolls//
:={
:=int mask[4];
:=int data[4]; // array to store our data since i am
:=int delaycount;
:=int startposition;
:=int index;
:=int i,nelly;
:=int down,across;
:=set_tris_c(0);
:=set_tris_b(0);
:=port_c = 0;
:=port_b = 0;
:=startposition = 0;
:=while(1)
:= {
:= delaycount = 3; // adjust this value to control scrolls speed
:= while (delaycount)
:= {
:= index = startposition;
:=
:= mask[0]=0x01; // Initialize our mask
:= mask[1]=0x00;
:= mask[2]=0x00;
:= mask[3]=0x00;
:=
:= for (i=0; i<32; i++) // we have 32 columns to drive
:= {
:= // store our mask in an array. we need to do this because
:= // the call to write_expanded_outputs will destroy the value
:= // passed in.
:= data[0] = mask[0]; // store which column we are driving
:= data[1] = mask[1]; // in an array
:= data[2] = mask[2];
:= data[3] = mask[3];
:= index = i + startposition; // point to the next pattern to display
:= if (index >= sizeof(pat)) // make sure that we don't exceed the array
:= index -= sizeof(pat);
:= port_b = 0; // disable driving the LEDs
:= write_expanded_outputs(data); // enable our column driver
:= // port_b = pat[index]; // drive our LEDs
:=/////////////////////////////////////////////////////////////////////////////////////////////////////////
:= nelly=i\%8;
:= for(down=0;down<Row;down++)
:= for (across =0;across := port_b=pat[down][across];
:= printf("\%x",pat[down][across]);
:=/////////////////////////////////////////////////////////////////////////////////////////////////////////
:= //printf("\%x",pat[index],"\r\n");
:= if (shift_left(mask,4,0))
:= mask[0] = 0x01;
:= // shift to the next column for next time
:= delay_us(700); // adjust this value to control the drive time
:= //for the leds
:= }
:= --delaycount; // decrement our delay loop counter
:= }
:= ++startposition; // Point to the next data pattern
:= if (startposition >= sizeof(pat)) // make sure that we don't exceed the array
:= {
:= startposition = 0;
:=
:= }
:=
:= }
:=
:=}
:=
:=
:=
:=
:=
:=
:=
:=
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 10057
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