|
|
View previous topic :: View next topic |
Author |
Message |
isaac aiyanyo Guest
|
2d character array for 8 x8 led display |
Posted: Mon Dec 09, 2002 11:57 am |
|
|
Hello everyone i do need some expert help form you.
i am trying to design an 8 x 32 led display. which can receive the characters to be displayed via hyperterminal and convert this into the ascii character to be displayed .
i have with the help of mark being able to get the display to work independently with a constant array .
i have also being able to modify the serial interupt example to receive the characters from hypeterminal.
my problem now in how to sort out a 2D array that would convert this.
my knowlege of C is very limited and would be very greatful if
you could point me in the right direction.
my program is below .
Thanks in advance
Isaac
#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)
#define EXP_OUT_ENABLE PIN_C2
#define EXP_OUT_CLOCK PIN_C1
#define EXP_OUT_DO PIN_C0
#define NUMBER_OF_74595 4
#include <74595.C>
void display (void);
void convert (void);
#define BUFFER_SIZE 16
byte buffer[BUFFER_SIZE];
byte Data [16];
byte next_in = 0;
byte next_out = 0;
#byte port_a=5
#byte port_b=6
#byte port_c=7
char const pat[80]={0,255,255,24,24,255,255,0,0,255,255,219,219,195,195,0,
0,255,255,192,192,192,192,0,0,255,255,192,192,192,192,0,
0,60,126,195,195,126,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
// array holds the character maps for HELLO which scrolls//
// This needs to be converted to 8 x 8 bitmaps
#int_rda
void serial_isr() // serial interupt function
{
int t;
output_low(PIN_C4);
buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) \% BUFFER_SIZE;
if(next_in==next_out)
next_in=t; // Buffer full !!
}
#define bkbhit (next_in!=next_out)
byte bgetc()
{
byte c;
while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) \% BUFFER_SIZE;
return(c);
}
main()
{
int i;
delay_ms(10000); // 10 sec delay to enable lcd to start up
enable_interrupts(global); // enable global interupt
enable_interrupts(int_rda); // enable serial interupt
for(;;)
{
output_high(PIN_C4); //Turn on led on RC4 to tell us the pic is
//ready to receive data
printf("Receiving data !!\r\n"); //Display this on hyperterminal
delay_ms(30000); //The program will delay for 10 seconds and then display
//any data that came in during the 10 second delay
printf("\r\nBuffered data => "); // display this to hypertherminal
while(bkbhit) // cheak if (bkbhit) is set or true
putc( bgetc() ); //if true there is data so display it
printf("\r\n"); //with carriage return and new line
// be displayed is the data received during int
// and not the ones received when displaying
#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
// Now set the pins and data rate for the serial lcd on ra0
for (i=0;i<16;i++) // loop 16 times though buffer[0]
{ // to buffer[15]
Data[i]= buffer[i]; // copy buffer & store in Data array
putc(Data[i]); // display the characters in those locations
// on serial lcd connecte RA0
}
display (); // the display function
}
}
//***************************** This is the display part *****************************************************
void display (void)
{
int mask[4];
int data[4]; // array to store our data since i am
int startposition;
int index;
int i;
int delaycount;
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
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;
}
}
}
/////************************** End of display ******************************************************************
___________________________
This message was ported from CCS's old forum
Original Post ID: 9889 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: 2d character array for 8 x8 led display |
Posted: Mon Dec 09, 2002 1:18 pm |
|
|
Here is an example of initializing a two dimensional array.
char const pat[10][8]={{0,255,255,24,24,255,255,0},
{0,255,255,219,219,195,195,0},
{0,255,255,192,192,192,192,0},
{0,255,255,192,192,192,192,0},
{0,60,126,195,195,126,60,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0}};
To access the letter H's bitmap pat[0][0] through pat[0][9].
To access the letter e's bitmap pat[1][0] through pat[1][9].
and so on.
For your display what you will need to do is to create an array for all the ASCII characters you intend to display. For example 'A' through 'Z' (0x41-0x5A). This is 26 characters total.
char const pat[26][8]={.....
In this example only A-Z can be displayed. You would have to check to make sure that any data sent from Hyperterminal falls within this range. To access the character bitmap, simply take the ASCII value and substract 0x41 from it. This scheme can be modified to include a larger set of ASCII characters. You always substract the ASCII value of the first element in order to get the index of the bitmap.
:=
:= Hello everyone i do need some expert help form you.
:= i am trying to design an 8 x 32 led display. which can receive the characters to be displayed via hyperterminal and convert this into the ascii character to be displayed .
:= i have with the help of mark being able to get the display to work independently with a constant array .
:=i have also being able to modify the serial interupt example to receive the characters from hypeterminal.
:=my problem now in how to sort out a 2D array that would convert this.
:=my knowlege of C is very limited and would be very greatful if
:=you could point me in the right direction.
:=my program is below .
:=Thanks in advance
:=Isaac
:=
:=#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)
:=
:=#define EXP_OUT_ENABLE PIN_C2
:=#define EXP_OUT_CLOCK PIN_C1
:=#define EXP_OUT_DO PIN_C0
:=#define NUMBER_OF_74595 4
:=#include <74595.C>
:=
:=void display (void);
:=void convert (void);
:=#define BUFFER_SIZE 16
:=byte buffer[BUFFER_SIZE];
:=byte Data [16];
:=byte next_in = 0;
:=byte next_out = 0;
:=
:=#byte port_a=5
:=#byte port_b=6
:=#byte port_c=7
:=
:=
:=char const pat[80]={0,255,255,24,24,255,255,0,0,255,255,219,219,195,195,0,
:= 0,255,255,192,192,192,192,0,0,255,255,192,192,192,192,0,
:= 0,60,126,195,195,126,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
:= 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
:= // array holds the character maps for HELLO which scrolls//
:= // This needs to be converted to 8 x 8 bitmaps
:=
:=
:=#int_rda
:=void serial_isr() // serial interupt function
:={
:=
:= int t;
:= output_low(PIN_C4);
:= buffer[next_in]=getc();
:= t=next_in;
:= next_in=(next_in+1) \% BUFFER_SIZE;
:= if(next_in==next_out)
:= next_in=t; // Buffer full !!
:=}
:=
:=#define bkbhit (next_in!=next_out)
:=
:=byte bgetc()
:={
:= byte c;
:=
:= while(!bkbhit) ;
:= c=buffer[next_out];
:= next_out=(next_out+1) \% BUFFER_SIZE;
:= return(c);
:=}
:=
:=
:=main()
:={
:=
:= int i;
:= delay_ms(10000); // 10 sec delay to enable lcd to start up
:= enable_interrupts(global); // enable global interupt
:= enable_interrupts(int_rda); // enable serial interupt
:=
:= for(;;)
:= {
:= output_high(PIN_C4); //Turn on led on RC4 to tell us the pic is
:= //ready to receive data
:= printf("Receiving data !!\r\n"); //Display this on hyperterminal
:=
:= delay_ms(30000); //The program will delay for 10 seconds and then display
:= //any data that came in during the 10 second delay
:= printf("\r\nBuffered data => "); // display this to hypertherminal
:= while(bkbhit) // cheak if (bkbhit) is set or true
:= putc( bgetc() ); //if true there is data so display it
:= printf("\r\n"); //with carriage return and new line
:=
:= // be displayed is the data received during int
:= // and not the ones received when displaying
:=#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
:= // Now set the pins and data rate for the serial lcd on ra0
:=
:= for (i=0;i<16;i++) // loop 16 times though buffer[0]
:= { // to buffer[15]
:= Data[i]= buffer[i]; // copy buffer & store in Data array
:= putc(Data[i]); // display the characters in those locations
:= // on serial lcd connecte RA0
:= }
:= display (); // the display function
:=
:= }
:=
:=}
:=
:=
:=
:=
:=
:=
:=//***************************** This is the display part *****************************************************
:=void display (void)
:={
:=int mask[4];
:=int data[4]; // array to store our data since i am
:=int startposition;
:=int index;
:=int i;
:=int delaycount;
:=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
:= 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;
:=
:= }
:=
:= }
:=
:=}
:=
:=
:=/////************************** End of display ******************************************************************
___________________________
This message was ported from CCS's old forum
Original Post ID: 9899 |
|
|
isaac aiyanyo Guest
|
Re: 2d character array for 8 x8 led display |
Posted: Mon Dec 09, 2002 5:50 pm |
|
|
Life saver u r mark.
i am going to try it out right now
Thank y very much for your well (valued) adivce
Isaac
:=Here is an example of initializing a two dimensional array.
:=
:=char const pat[10][8]={{0,255,255,24,24,255,255,0},
:={0,255,255,219,219,195,195,0},
:={0,255,255,192,192,192,192,0},
:={0,255,255,192,192,192,192,0},
:={0,60,126,195,195,126,60,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0}};
:=
:=To access the letter H's bitmap pat[0][0] through pat[0][9].
:=To access the letter e's bitmap pat[1][0] through pat[1][9].
:=and so on.
:=
:=For your display what you will need to do is to create an array for all the ASCII characters you intend to display. For example 'A' through 'Z' (0x41-0x5A). This is 26 characters total.
:=
:=char const pat[26][8]={.....
:=
:=In this example only A-Z can be displayed. You would have to check to make sure that any data sent from Hyperterminal falls within this range. To access the character bitmap, simply take the ASCII value and substract 0x41 from it. This scheme can be modified to include a larger set of ASCII characters. You always substract the ASCII value of the first element in order to get the index of the bitmap.
:=
:=:=
:=:= Hello everyone i do need some expert help form you.
:=:= i am trying to design an 8 x 32 led display. which can receive the characters to be displayed via hyperterminal and convert this into the ascii character to be displayed .
:=:= i have with the help of mark being able to get the display to work independently with a constant array .
:=:=i have also being able to modify the serial interupt example to receive the characters from hypeterminal.
:=:=my problem now in how to sort out a 2D array that would convert this.
:=:=my knowlege of C is very limited and would be very greatful if
:=:=you could point me in the right direction.
:=:=my program is below .
:=:=Thanks in advance
:=:=Isaac
:=:=
:=:=#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)
:=:=
:=:=#define EXP_OUT_ENABLE PIN_C2
:=:=#define EXP_OUT_CLOCK PIN_C1
:=:=#define EXP_OUT_DO PIN_C0
:=:=#define NUMBER_OF_74595 4
:=:=#include <74595.C>
:=:=
:=:=void display (void);
:=:=void convert (void);
:=:=#define BUFFER_SIZE 16
:=:=byte buffer[BUFFER_SIZE];
:=:=byte Data [16];
:=:=byte next_in = 0;
:=:=byte next_out = 0;
:=:=
:=:=#byte port_a=5
:=:=#byte port_b=6
:=:=#byte port_c=7
:=:=
:=:=
:=:=char const pat[80]={0,255,255,24,24,255,255,0,0,255,255,219,219,195,195,0,
:=:= 0,255,255,192,192,192,192,0,0,255,255,192,192,192,192,0,
:=:= 0,60,126,195,195,126,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
:=:= 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
:=:= // array holds the character maps for HELLO which scrolls//
:=:= // This needs to be converted to 8 x 8 bitmaps
:=:=
:=:=
:=:=#int_rda
:=:=void serial_isr() // serial interupt function
:=:={
:=:=
:=:= int t;
:=:= output_low(PIN_C4);
:=:= buffer[next_in]=getc();
:=:= t=next_in;
:=:= next_in=(next_in+1) \% BUFFER_SIZE;
:=:= if(next_in==next_out)
:=:= next_in=t; // Buffer full !!
:=:=}
:=:=
:=:=#define bkbhit (next_in!=next_out)
:=:=
:=:=byte bgetc()
:=:={
:=:= byte c;
:=:=
:=:= while(!bkbhit) ;
:=:= c=buffer[next_out];
:=:= next_out=(next_out+1) \% BUFFER_SIZE;
:=:= return(c);
:=:=}
:=:=
:=:=
:=:=main()
:=:={
:=:=
:=:= int i;
:=:= delay_ms(10000); // 10 sec delay to enable lcd to start up
:=:= enable_interrupts(global); // enable global interupt
:=:= enable_interrupts(int_rda); // enable serial interupt
:=:=
:=:= for(;;)
:=:= {
:=:= output_high(PIN_C4); //Turn on led on RC4 to tell us the pic is
:=:= //ready to receive data
:=:= printf("Receiving data !!\r\n"); //Display this on hyperterminal
:=:=
:=:= delay_ms(30000); //The program will delay for 10 seconds and then display
:=:= //any data that came in during the 10 second delay
:=:= printf("\r\nBuffered data => "); // display this to hypertherminal
:=:= while(bkbhit) // cheak if (bkbhit) is set or true
:=:= putc( bgetc() ); //if true there is data so display it
:=:= printf("\r\n"); //with carriage return and new line
:=:=
:=:= // be displayed is the data received during int
:=:= // and not the ones received when displaying
:=:=#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
:=:= // Now set the pins and data rate for the serial lcd on ra0
:=:=
:=:= for (i=0;i<16;i++) // loop 16 times though buffer[0]
:=:= { // to buffer[15]
:=:= Data[i]= buffer[i]; // copy buffer & store in Data array
:=:= putc(Data[i]); // display the characters in those locations
:=:= // on serial lcd connecte RA0
:=:= }
:=:= display (); // the display function
:=:=
:=:= }
:=:=
:=:=}
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=//***************************** This is the display part *****************************************************
:=:=void display (void)
:=:={
:=:=int mask[4];
:=:=int data[4]; // array to store our data since i am
:=:=int startposition;
:=:=int index;
:=:=int i;
:=:=int delaycount;
:=:=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
:=:= 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;
:=:=
:=:= }
:=:=
:=:= }
:=:=
:=:=}
:=:=
:=:=
:=:=/////************************** End of display ******************************************************************
___________________________
This message was ported from CCS's old forum
Original Post ID: 9917 |
|
|
isaac aiyanyo Guest
|
Re: 2d character array for 8 x8 led display |
Posted: Mon Dec 09, 2002 6:10 pm |
|
|
Mark
i just tried to complier the 2D constant but i get this error
i can't seem to find what is wrong.
i would be working through the night to get it right .
my dream is getting closer all thinks to you.
Isaac
___________________________
This message was ported from CCS's old forum
Original Post ID: 9918 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: 2d character array for 8 x8 led display |
Posted: Mon Dec 09, 2002 9:27 pm |
|
|
I had one number shifted. This should compile now.
:=Here is an example of initializing a two dimensional array.
:=
char const pat[10][8]={{0,255,255,24,24,255,255,0},
{0,255,255,219,219,195,195,0},
{0,255,255,192,192,192,192,0},
{0,255,255,192,192,192,192,0},
{0,60,126,195,195,126,60,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}};
:=
:=To access the letter H's bitmap pat[0][0] through pat[0][9].
:=To access the letter e's bitmap pat[1][0] through pat[1][9].
:=and so on.
:=
:=For your display what you will need to do is to create an array for all the ASCII characters you intend to display. For example 'A' through 'Z' (0x41-0x5A). This is 26 characters total.
:=
:=char const pat[26][8]={.....
:=
:=In this example only A-Z can be displayed. You would have to check to make sure that any data sent from Hyperterminal falls within this range. To access the character bitmap, simply take the ASCII value and substract 0x41 from it. This scheme can be modified to include a larger set of ASCII characters. You always substract the ASCII value of the first element in order to get the index of the bitmap.
:=
:=:=
:=:= Hello everyone i do need some expert help form you.
:=:= i am trying to design an 8 x 32 led display. which can receive the characters to be displayed via hyperterminal and convert this into the ascii character to be displayed .
:=:= i have with the help of mark being able to get the display to work independently with a constant array .
:=:=i have also being able to modify the serial interupt example to receive the characters from hypeterminal.
:=:=my problem now in how to sort out a 2D array that would convert this.
:=:=my knowlege of C is very limited and would be very greatful if
:=:=you could point me in the right direction.
:=:=my program is below .
:=:=Thanks in advance
:=:=Isaac
:=:=
:=:=#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)
:=:=
:=:=#define EXP_OUT_ENABLE PIN_C2
:=:=#define EXP_OUT_CLOCK PIN_C1
:=:=#define EXP_OUT_DO PIN_C0
:=:=#define NUMBER_OF_74595 4
:=:=#include <74595.C>
:=:=
:=:=void display (void);
:=:=void convert (void);
:=:=#define BUFFER_SIZE 16
:=:=byte buffer[BUFFER_SIZE];
:=:=byte Data [16];
:=:=byte next_in = 0;
:=:=byte next_out = 0;
:=:=
:=:=#byte port_a=5
:=:=#byte port_b=6
:=:=#byte port_c=7
:=:=
:=:=
:=:=char const pat[80]={0,255,255,24,24,255,255,0,0,255,255,219,219,195,195,0,
:=:= 0,255,255,192,192,192,192,0,0,255,255,192,192,192,192,0,
:=:= 0,60,126,195,195,126,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
:=:= 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
:=:= // array holds the character maps for HELLO which scrolls//
:=:= // This needs to be converted to 8 x 8 bitmaps
:=:=
:=:=
:=:=#int_rda
:=:=void serial_isr() // serial interupt function
:=:={
:=:=
:=:= int t;
:=:= output_low(PIN_C4);
:=:= buffer[next_in]=getc();
:=:= t=next_in;
:=:= next_in=(next_in+1) \% BUFFER_SIZE;
:=:= if(next_in==next_out)
:=:= next_in=t; // Buffer full !!
:=:=}
:=:=
:=:=#define bkbhit (next_in!=next_out)
:=:=
:=:=byte bgetc()
:=:={
:=:= byte c;
:=:=
:=:= while(!bkbhit) ;
:=:= c=buffer[next_out];
:=:= next_out=(next_out+1) \% BUFFER_SIZE;
:=:= return(c);
:=:=}
:=:=
:=:=
:=:=main()
:=:={
:=:=
:=:= int i;
:=:= delay_ms(10000); // 10 sec delay to enable lcd to start up
:=:= enable_interrupts(global); // enable global interupt
:=:= enable_interrupts(int_rda); // enable serial interupt
:=:=
:=:= for(;;)
:=:= {
:=:= output_high(PIN_C4); //Turn on led on RC4 to tell us the pic is
:=:= //ready to receive data
:=:= printf("Receiving data !!\r\n"); //Display this on hyperterminal
:=:=
:=:= delay_ms(30000); //The program will delay for 10 seconds and then display
:=:= //any data that came in during the 10 second delay
:=:= printf("\r\nBuffered data => "); // display this to hypertherminal
:=:= while(bkbhit) // cheak if (bkbhit) is set or true
:=:= putc( bgetc() ); //if true there is data so display it
:=:= printf("\r\n"); //with carriage return and new line
:=:=
:=:= // be displayed is the data received during int
:=:= // and not the ones received when displaying
:=:=#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
:=:= // Now set the pins and data rate for the serial lcd on ra0
:=:=
:=:= for (i=0;i<16;i++) // loop 16 times though buffer[0]
:=:= { // to buffer[15]
:=:= Data[i]= buffer[i]; // copy buffer & store in Data array
:=:= putc(Data[i]); // display the characters in those locations
:=:= // on serial lcd connecte RA0
:=:= }
:=:= display (); // the display function
:=:=
:=:= }
:=:=
:=:=}
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=//***************************** This is the display part *****************************************************
:=:=void display (void)
:=:={
:=:=int mask[4];
:=:=int data[4]; // array to store our data since i am
:=:=int startposition;
:=:=int index;
:=:=int i;
:=:=int delaycount;
:=:=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
:=:= 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;
:=:=
:=:= }
:=:=
:=:= }
:=:=
:=:=}
:=:=
:=:=
:=:=/////************************** End of display ******************************************************************
___________________________
This message was ported from CCS's old forum
Original Post ID: 9921 |
|
|
isaac aiyanyo Guest
|
Re: 2d character array for 8 x8 led display |
Posted: Tue Dec 10, 2002 10:37 am |
|
|
Mark ,
i can't thank you enough for all your help.
i am still having problems displaying the characters from the 2D array.
i am trying the display any character entered between A to D
which i created a 2D [4][8] array.
i know somehow that the characters can be display when i force
for example port_b = pat[0][nelly] i get A displayed
port_b = pat[1][nelly] i get B displayed etc up to the character D.
the problem now is trying to get the characters to index so that when is type ABCD that is what is displayed or BDAC.
I have being really trying different things but my biggest fear
is i don't want to make too many changes to the program you already thought me.
i have put the program below so you can have a look and tell me if i am going in the right direction.
Thanks in advance
Isaac
#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)
#define EXP_OUT_ENABLE PIN_C2
#define EXP_OUT_CLOCK PIN_C1
#define EXP_OUT_DO PIN_C0
#define NUMBER_OF_74595 4
#include <74595.C>
void display (void);
void convert (void);
#define BUFFER_SIZE 16
#define Max_data 32
byte buffer[BUFFER_SIZE];
byte Data [16];
byte next_in = 0;
byte next_out = 0;
#byte port_a=5
#byte port_b=6
#byte port_c=7
char const pat[4][8]={
{0x00,0xfc,0xfe,0x33,0x33,0xfe,0xfe,0x00}, // Font A
{0x00,0xff,0xff,0xdb,0xdb,0xff,0x66,0x00}, // Font B
{0x00,0x7e,0xff,0xc3,0xc3,0xc3,0xc3,0x00}, // Font C
{0x00,0xff,0xff,0xc3,0xc3,0xff,0x7e,0x00}, // Font D
};
#int_rda
void serial_isr() // serial interupt function
{
int t;
output_low(PIN_C4);
buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) \% BUFFER_SIZE;
if(next_in==next_out)
next_in=t; // Buffer full !!
}
#define bkbhit (next_in!=next_out)
byte bgetc()
{
byte c;
while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) \% BUFFER_SIZE;
return(c);
}
main()
{
int i;
delay_ms(10000); // 10 sec delay to enable lcd to start up
enable_interrupts(global); // enable global interupt
enable_interrupts(int_rda); // enable serial interupt
for(;;)
{
output_high(PIN_C4); //Turn on led on RC4 to tell us the pic is
//ready to receive data
printf("Receiving data !!\r\n"); //Display this on hyperterminal
delay_ms(10000); //The program will delay for 10 seconds and then display
//any data that came in during the 10 second delay
printf("\r\nBuffered data => "); // display this to hypertherminal
while(bkbhit) // cheak if (bkbhit) is set or true
putc( bgetc() ); //if true there is data so display it
printf("\r\n"); //with carriage return and new line
// be displayed is the data received during int
// and not the ones received when displaying
#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
// Now set the pins and data rate for the serial lcd on ra0
for (i=0;i<16;i++) // loop 16 times though buffer[0]
{ // to buffer[15]
Data[i]= buffer[i]; // copy buffer & store in Data array
putc(Data[i]); // display the characters in those locations
// on serial lcd connecte RA0
}
for(;;)
{
display (); // the display function
}
}
}
//***************************** This is the display part *****************************************************
void display (void)
{
int mask[4];
int data[4]; // array to store our data since i am
int startposition;
int index;
int i;
int delaycount;
//888888888888888888888888888888888888 nelly starts here 888888888888888888888888888888888888888888888888888
int dex=-1; //buffer index
int ch; //arrayfont:ascii index
int nelly;
//8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
set_tris_c(0);
set_tris_b(0);
port_c = 0;
port_b = 0;
startposition = 0;
while(1)
{
delaycount = 10; // 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
{
//88888888888888888888888888 change here88888888888888888888888888888888888888888888888888888888888888888888888
nelly = i \% 8; // I DON'T KNOW WHAT I AM DOING WRONG HERE
if (!nelly) dex++;
ch = Data[dex]-65;
//88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
// 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
//............................................................................................................
port_b = pat[ch][nelly];// i think i am geting the correct value here as the led
// just flashes but don't continue so as to see the
// character.
//.............................................................................................................
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;
}
}
}
/////************************** End of display ******************************************************************
:=Here is an example of initializing a two dimensional array.
:=
:=char const pat[10][8]={{0,255,255,24,24,255,255,0},
:={0,255,255,219,219,195,195,0},
:={0,255,255,192,192,192,192,0},
:={0,255,255,192,192,192,192,0},
:={0,60,126,195,195,126,60,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0}};
:=
:=To access the letter H's bitmap pat[0][0] through pat[0][9].
:=To access the letter e's bitmap pat[1][0] through pat[1][9].
:=and so on.
:=
:=For your display what you will need to do is to create an array for all the ASCII characters you intend to display. For example 'A' through 'Z' (0x41-0x5A). This is 26 characters total.
:=
:=char const pat[26][8]={.....
:=
:=In this example only A-Z can be displayed. You would have to check to make sure that any data sent from Hyperterminal falls within this range. To access the character bitmap, simply take the ASCII value and substract 0x41 from it. This scheme can be modified to include a larger set of ASCII characters. You always substract the ASCII value of the first element in order to get the index of the bitmap.
:=
:=:=
:=:= Hello everyone i do need some expert help form you.
:=:= i am trying to design an 8 x 32 led display. which can receive the characters to be displayed via hyperterminal and convert this into the ascii character to be displayed .
:=:= i have with the help of mark being able to get the display to work independently with a constant array .
:=:=i have also being able to modify the serial interupt example to receive the characters from hypeterminal.
:=:=my problem now in how to sort out a 2D array that would convert this.
:=:=my knowlege of C is very limited and would be very greatful if
:=:=you could point me in the right direction.
:=:=my program is below .
:=:=Thanks in advance
:=:=Isaac
:=:=
:=:=#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)
:=:=
:=:=#define EXP_OUT_ENABLE PIN_C2
:=:=#define EXP_OUT_CLOCK PIN_C1
:=:=#define EXP_OUT_DO PIN_C0
:=:=#define NUMBER_OF_74595 4
:=:=#include <74595.C>
:=:=
:=:=void display (void);
:=:=void convert (void);
:=:=#define BUFFER_SIZE 16
:=:=byte buffer[BUFFER_SIZE];
:=:=byte Data [16];
:=:=byte next_in = 0;
:=:=byte next_out = 0;
:=:=
:=:=#byte port_a=5
:=:=#byte port_b=6
:=:=#byte port_c=7
:=:=
:=:=
:=:=char const pat[80]={0,255,255,24,24,255,255,0,0,255,255,219,219,195,195,0,
:=:= 0,255,255,192,192,192,192,0,0,255,255,192,192,192,192,0,
:=:= 0,60,126,195,195,126,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
:=:= 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
:=:= // array holds the character maps for HELLO which scrolls//
:=:= // This needs to be converted to 8 x 8 bitmaps
:=:=
:=:=
:=:=#int_rda
:=:=void serial_isr() // serial interupt function
:=:={
:=:=
:=:= int t;
:=:= output_low(PIN_C4);
:=:= buffer[next_in]=getc();
:=:= t=next_in;
:=:= next_in=(next_in+1) \% BUFFER_SIZE;
:=:= if(next_in==next_out)
:=:= next_in=t; // Buffer full !!
:=:=}
:=:=
:=:=#define bkbhit (next_in!=next_out)
:=:=
:=:=byte bgetc()
:=:={
:=:= byte c;
:=:=
:=:= while(!bkbhit) ;
:=:= c=buffer[next_out];
:=:= next_out=(next_out+1) \% BUFFER_SIZE;
:=:= return(c);
:=:=}
:=:=
:=:=
:=:=main()
:=:={
:=:=
:=:= int i;
:=:= delay_ms(10000); // 10 sec delay to enable lcd to start up
:=:= enable_interrupts(global); // enable global interupt
:=:= enable_interrupts(int_rda); // enable serial interupt
:=:=
:=:= for(;;)
:=:= {
:=:= output_high(PIN_C4); //Turn on led on RC4 to tell us the pic is
:=:= //ready to receive data
:=:= printf("Receiving data !!\r\n"); //Display this on hyperterminal
:=:=
:=:= delay_ms(30000); //The program will delay for 10 seconds and then display
:=:= //any data that came in during the 10 second delay
:=:= printf("\r\nBuffered data => "); // display this to hypertherminal
:=:= while(bkbhit) // cheak if (bkbhit) is set or true
:=:= putc( bgetc() ); //if true there is data so display it
:=:= printf("\r\n"); //with carriage return and new line
:=:=
:=:= // be displayed is the data received during int
:=:= // and not the ones received when displaying
:=:=#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
:=:= // Now set the pins and data rate for the serial lcd on ra0
:=:=
:=:= for (i=0;i<16;i++) // loop 16 times though buffer[0]
:=:= { // to buffer[15]
:=:= Data[i]= buffer[i]; // copy buffer & store in Data array
:=:= putc(Data[i]); // display the characters in those locations
:=:= // on serial lcd connecte RA0
:=:= }
:=:= display (); // the display function
:=:=
:=:= }
:=:=
:=:=}
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=//***************************** This is the display part *****************************************************
:=:=void display (void)
:=:={
:=:=int mask[4];
:=:=int data[4]; // array to store our data since i am
:=:=int startposition;
:=:=int index;
:=:=int i;
:=:=int delaycount;
:=:=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
:=:= 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;
:=:=
:=:= }
:=:=
:=:= }
:=:=
:=:=}
:=:=
:=:=
:=:=/////************************** End of display ******************************************************************
___________________________
This message was ported from CCS's old forum
Original Post ID: 9939 |
|
|
isaac aiyanyo Guest
|
Re: 2d character array for 8 x8 led display |
Posted: Thu Dec 12, 2002 11:46 am |
|
|
Mark,
Thanks for the example you gave me.
i have being reading about 2D arrays and i tried to get it
working.i changed the bitmap to ABCD so that A is the first character.
i remembered what you said below and tried toTo access
the ist letter A's bitmap pat[0][0] through pat[0][9].
i used a for loop as below
#include <conio.h>
#include <stdio.h>
#define Row 4
#define Col 8
main()
{
int across,down;
unsigned char const pat[Row][Col]={
{0,0xfc,0xfe,0x33,0x33,0xfe,0xfe,0},//FortA
{0,0xff,0xff,0xdb,0xdb,0xff,0x66,0},//FontB
{0,0x7e,0xff,0xc3,0xc3,0xc3,0xc3,0},//FontC
{0,0xff,0xff,0xc3,0xc3,0xff,0x7e,0},//FontD
};
clrscr();
for ( across =0;across < Col; across++)
{
cprintf("\%x",pat[down][across]);
}
getch();
}
it didn't work with my pic but it worked on my pc when i ran the program i get the contains of A's bitmap pat[0][0] through pat[0][9] displayed to the screen.
i also tried to get the characters ABCD displayed but i couldn't
i ran the for loop which i used on the pc and it does output the correct data ( the entire contents of the 2D array to the screen)
i know i must be doing something wrong but i can't spot it.
Could you be kind enough to have a look as i have being trying now for 2 nights now and i am pulling my hair out here.
i include the code below.
Hoping to hear from you soon
Isaac :)
#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 10
#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[40]={
char const pat[4][8]={
{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,across,down;
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
/////////////////////// This is the only part i changed and comment out port_b =pat[index]///////////////////////////
for (down=0;down < Row; down++)
{
for ( across =0;across < Col; across++)
port_b=pat[down][across];
// this is what i think get outputed to portb so i can't see were i am going wrong
// i need your help which this one as i have tried for 2 nights in a row and think tonite gonna be a sleep
// one
//0,fc,fe,33,33,fe,fe,0,0,ff,ff,db,db,ff,66,0,0,7e,ff,c3,c3,c3,c3,0,0,0xff,0xff,0xc3,0xc3,0xff,0x7e,0
////////////////This outputs from element 0 to 79 of the 1D array ////////////////////////////////////////////////////
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;
}
}
}
:=Here is an example of initializing a two dimensional array.
:=
:=char const pat[10][8]={{0,255,255,24,24,255,255,0},
:={0,255,255,219,219,195,195,0},
:={0,255,255,192,192,192,192,0},
:={0,255,255,192,192,192,192,0},
:={0,60,126,195,195,126,60,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0}};
:=
:=To access the letter H's bitmap pat[0][0] through pat[0][9].
:=To access the letter e's bitmap pat[1][0] through pat[1][9].
:=and so on.
:=
:=For your display what you will need to do is to create an array for all the ASCII characters you intend to display. For example 'A' through 'Z' (0x41-0x5A). This is 26 characters total.
:=
:=char const pat[26][8]={.....
:=
:=In this example only A-Z can be displayed. You would have to check to make sure that any data sent from Hyperterminal falls within this range. To access the character bitmap, simply take the ASCII value and substract 0x41 from it. This scheme can be modified to include a larger set of ASCII characters. You always substract the ASCII value of the first element in order to get the index of the bitmap.
:=
:=:=
:=:= Hello everyone i do need some expert help form you.
:=:= i am trying to design an 8 x 32 led display. which can receive the characters to be displayed via hyperterminal and convert this into the ascii character to be displayed .
:=:= i have with the help of mark being able to get the display to work independently with a constant array .
:=:=i have also being able to modify the serial interupt example to receive the characters from hypeterminal.
:=:=my problem now in how to sort out a 2D array that would convert this.
:=:=my knowlege of C is very limited and would be very greatful if
:=:=you could point me in the right direction.
:=:=my program is below .
:=:=Thanks in advance
:=:=Isaac
:=:=
:=:=#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)
:=:=
:=:=#define EXP_OUT_ENABLE PIN_C2
:=:=#define EXP_OUT_CLOCK PIN_C1
:=:=#define EXP_OUT_DO PIN_C0
:=:=#define NUMBER_OF_74595 4
:=:=#include <74595.C>
:=:=
:=:=void display (void);
:=:=void convert (void);
:=:=#define BUFFER_SIZE 16
:=:=byte buffer[BUFFER_SIZE];
:=:=byte Data [16];
:=:=byte next_in = 0;
:=:=byte next_out = 0;
:=:=
:=:=#byte port_a=5
:=:=#byte port_b=6
:=:=#byte port_c=7
:=:=
:=:=
:=:=char const pat[80]={0,255,255,24,24,255,255,0,0,255,255,219,219,195,195,0,
:=:= 0,255,255,192,192,192,192,0,0,255,255,192,192,192,192,0,
:=:= 0,60,126,195,195,126,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
:=:= 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
:=:= // array holds the character maps for HELLO which scrolls//
:=:= // This needs to be converted to 8 x 8 bitmaps
:=:=
:=:=
:=:=#int_rda
:=:=void serial_isr() // serial interupt function
:=:={
:=:=
:=:= int t;
:=:= output_low(PIN_C4);
:=:= buffer[next_in]=getc();
:=:= t=next_in;
:=:= next_in=(next_in+1) \% BUFFER_SIZE;
:=:= if(next_in==next_out)
:=:= next_in=t; // Buffer full !!
:=:=}
:=:=
:=:=#define bkbhit (next_in!=next_out)
:=:=
:=:=byte bgetc()
:=:={
:=:= byte c;
:=:=
:=:= while(!bkbhit) ;
:=:= c=buffer[next_out];
:=:= next_out=(next_out+1) \% BUFFER_SIZE;
:=:= return(c);
:=:=}
:=:=
:=:=
:=:=main()
:=:={
:=:=
:=:= int i;
:=:= delay_ms(10000); // 10 sec delay to enable lcd to start up
:=:= enable_interrupts(global); // enable global interupt
:=:= enable_interrupts(int_rda); // enable serial interupt
:=:=
:=:= for(;;)
:=:= {
:=:= output_high(PIN_C4); //Turn on led on RC4 to tell us the pic is
:=:= //ready to receive data
:=:= printf("Receiving data !!\r\n"); //Display this on hyperterminal
:=:=
:=:= delay_ms(30000); //The program will delay for 10 seconds and then display
:=:= //any data that came in during the 10 second delay
:=:= printf("\r\nBuffered data => "); // display this to hypertherminal
:=:= while(bkbhit) // cheak if (bkbhit) is set or true
:=:= putc( bgetc() ); //if true there is data so display it
:=:= printf("\r\n"); //with carriage return and new line
:=:=
:=:= // be displayed is the data received during int
:=:= // and not the ones received when displaying
:=:=#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
:=:= // Now set the pins and data rate for the serial lcd on ra0
:=:=
:=:= for (i=0;i<16;i++) // loop 16 times though buffer[0]
:=:= { // to buffer[15]
:=:= Data[i]= buffer[i]; // copy buffer & store in Data array
:=:= putc(Data[i]); // display the characters in those locations
:=:= // on serial lcd connecte RA0
:=:= }
:=:= display (); // the display function
:=:=
:=:= }
:=:=
:=:=}
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=//***************************** This is the display part *****************************************************
:=:=void display (void)
:=:={
:=:=int mask[4];
:=:=int data[4]; // array to store our data since i am
:=:=int startposition;
:=:=int index;
:=:=int i;
:=:=int delaycount;
:=:=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
:=:= 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;
:=:=
:=:= }
:=:=
:=:= }
:=:=
:=:=}
:=:=
:=:=
:=:=/////************************** End of display ******************************************************************
___________________________
This message was ported from CCS's old forum
Original Post ID: 10003 |
|
|
isaac aiyanyo Guest
|
Still strugling with my display |
Posted: Sat Dec 28, 2002 10:35 am |
|
|
Mark,
Merry xmas !!)
you have being a bit quite on the list so was just
wondering if i have lost my mentor ?
i have managed to get the 2D array working and also the
serial routine is working fine.
i can't get them to work to together i do need your help
you r avaliable.
please do get in touch as i miss you guidance
Isaac
:=Here is an example of initializing a two dimensional array.
:=
:=char const pat[10][8]={{0,255,255,24,24,255,255,0},
:={0,255,255,219,219,195,195,0},
:={0,255,255,192,192,192,192,0},
:={0,255,255,192,192,192,192,0},
:={0,60,126,195,195,126,60,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0,0},
:={0,0,0,0,0,0,0}};
:=
:=To access the letter H's bitmap pat[0][0] through pat[0][9].
:=To access the letter e's bitmap pat[1][0] through pat[1][9].
:=and so on.
:=
:=For your display what you will need to do is to create an array for all the ASCII characters you intend to display. For example 'A' through 'Z' (0x41-0x5A). This is 26 characters total.
:=
:=char const pat[26][8]={.....
:=
:=In this example only A-Z can be displayed. You would have to check to make sure that any data sent from Hyperterminal falls within this range. To access the character bitmap, simply take the ASCII value and substract 0x41 from it. This scheme can be modified to include a larger set of ASCII characters. You always substract the ASCII value of the first element in order to get the index of the bitmap.
:=
:=:=
:=:= Hello everyone i do need some expert help form you.
:=:= i am trying to design an 8 x 32 led display. which can receive the characters to be displayed via hyperterminal and convert this into the ascii character to be displayed .
:=:= i have with the help of mark being able to get the display to work independently with a constant array .
:=:=i have also being able to modify the serial interupt example to receive the characters from hypeterminal.
:=:=my problem now in how to sort out a 2D array that would convert this.
:=:=my knowlege of C is very limited and would be very greatful if
:=:=you could point me in the right direction.
:=:=my program is below .
:=:=Thanks in advance
:=:=Isaac
:=:=
:=:=#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)
:=:=
:=:=#define EXP_OUT_ENABLE PIN_C2
:=:=#define EXP_OUT_CLOCK PIN_C1
:=:=#define EXP_OUT_DO PIN_C0
:=:=#define NUMBER_OF_74595 4
:=:=#include <74595.C>
:=:=
:=:=void display (void);
:=:=void convert (void);
:=:=#define BUFFER_SIZE 16
:=:=byte buffer[BUFFER_SIZE];
:=:=byte Data [16];
:=:=byte next_in = 0;
:=:=byte next_out = 0;
:=:=
:=:=#byte port_a=5
:=:=#byte port_b=6
:=:=#byte port_c=7
:=:=
:=:=
:=:=char const pat[80]={0,255,255,24,24,255,255,0,0,255,255,219,219,195,195,0,
:=:= 0,255,255,192,192,192,192,0,0,255,255,192,192,192,192,0,
:=:= 0,60,126,195,195,126,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
:=:= 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
:=:= // array holds the character maps for HELLO which scrolls//
:=:= // This needs to be converted to 8 x 8 bitmaps
:=:=
:=:=
:=:=#int_rda
:=:=void serial_isr() // serial interupt function
:=:={
:=:=
:=:= int t;
:=:= output_low(PIN_C4);
:=:= buffer[next_in]=getc();
:=:= t=next_in;
:=:= next_in=(next_in+1) \% BUFFER_SIZE;
:=:= if(next_in==next_out)
:=:= next_in=t; // Buffer full !!
:=:=}
:=:=
:=:=#define bkbhit (next_in!=next_out)
:=:=
:=:=byte bgetc()
:=:={
:=:= byte c;
:=:=
:=:= while(!bkbhit) ;
:=:= c=buffer[next_out];
:=:= next_out=(next_out+1) \% BUFFER_SIZE;
:=:= return(c);
:=:=}
:=:=
:=:=
:=:=main()
:=:={
:=:=
:=:= int i;
:=:= delay_ms(10000); // 10 sec delay to enable lcd to start up
:=:= enable_interrupts(global); // enable global interupt
:=:= enable_interrupts(int_rda); // enable serial interupt
:=:=
:=:= for(;;)
:=:= {
:=:= output_high(PIN_C4); //Turn on led on RC4 to tell us the pic is
:=:= //ready to receive data
:=:= printf("Receiving data !!\r\n"); //Display this on hyperterminal
:=:=
:=:= delay_ms(30000); //The program will delay for 10 seconds and then display
:=:= //any data that came in during the 10 second delay
:=:= printf("\r\nBuffered data => "); // display this to hypertherminal
:=:= while(bkbhit) // cheak if (bkbhit) is set or true
:=:= putc( bgetc() ); //if true there is data so display it
:=:= printf("\r\n"); //with carriage return and new line
:=:=
:=:= // be displayed is the data received during int
:=:= // and not the ones received when displaying
:=:=#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1,RESTART_WDT,ERRORS,INVERT)
:=:= // Now set the pins and data rate for the serial lcd on ra0
:=:=
:=:= for (i=0;i<16;i++) // loop 16 times though buffer[0]
:=:= { // to buffer[15]
:=:= Data[i]= buffer[i]; // copy buffer & store in Data array
:=:= putc(Data[i]); // display the characters in those locations
:=:= // on serial lcd connecte RA0
:=:= }
:=:= display (); // the display function
:=:=
:=:= }
:=:=
:=:=}
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=//***************************** This is the display part *****************************************************
:=:=void display (void)
:=:={
:=:=int mask[4];
:=:=int data[4]; // array to store our data since i am
:=:=int startposition;
:=:=int index;
:=:=int i;
:=:=int delaycount;
:=:=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
:=:= 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;
:=:=
:=:= }
:=:=
:=:= }
:=:=
:=:=}
:=:=
:=:=
:=:=/////************************** End of display ******************************************************************
___________________________
This message was ported from CCS's old forum
Original Post ID: 10290 |
|
|
NeoMatrix
Joined: 03 May 2005 Posts: 23
|
hellp needed |
Posted: Tue May 10, 2005 5:05 pm |
|
|
Hello Everyone
its me again sorry to disturb u
i just build 1 of 5x7 dot matrix message its displaying the character 1 by 1 i want to expand this to 5 of 5x7
i use pic16f628 and 1 74hc595 for 7 rows i connected to PORTA with 220 ohm resistor for cols i connected to 595 from porta for 595 pin 11,12 connected together and from pin 11 1k resistor to gnd pin 11 connected to porta.1 and pin 12 connected to porta.2 and pin 14 connected to porta.0 and pin 13,14 with 1 resistor to gnd this is my circuit and this is my programm its not displaying continously after displaying all the characters and i want to expand this to 5 of 5x7 can u suggest me
Code: |
unsigned char const font5x7_1[] = {
0x00, 0x00, 0x00, 0x00, 0x00 , // sp
0x00, 0x00, 0x2f, 0x00, 0x00 , // !
0x00, 0x07, 0x00, 0x07, 0x00 , // "
0x14, 0x7f, 0x14, 0x7f, 0x14 , // #
0x24, 0x2a, 0x7f, 0x2a, 0x12 , // $
0xc4, 0xc8, 0x10, 0x26, 0x46 , // %
0x36, 0x49, 0x55, 0x22, 0x50 , // &
0x00, 0x05, 0x03, 0x00, 0x00 , // '
0x00, 0x1c, 0x22, 0x41, 0x00 , // (
0x00, 0x41, 0x22, 0x1c, 0x00 , // )
0x14, 0x08, 0x3E, 0x08, 0x14 , // *
0x08, 0x08, 0x3E, 0x08, 0x08 , // +
0x00, 0x00, 0x50, 0x30, 0x00 , // ,
0x10, 0x10, 0x10, 0x10, 0x10 , // -
0x00, 0x60, 0x60, 0x00, 0x00 , // .
0x20, 0x10, 0x08, 0x04, 0x02 , // /
0x3E, 0x51, 0x49, 0x45, 0x3E , // 0
0x00, 0x42, 0x7F, 0x40, 0x00 , // 1
0x42, 0x61, 0x51, 0x49, 0x46 , // 2
0x21, 0x41, 0x45, 0x4B, 0x31 , // 3
0x18, 0x14, 0x12, 0x7F, 0x10 , // 4
0x27, 0x45, 0x45, 0x45, 0x39 , // 5
0x3C, 0x4A, 0x49, 0x49, 0x30 , // 6
0x01, 0x71, 0x09, 0x05, 0x03 , // 7
0x36, 0x49, 0x49, 0x49, 0x36 , // 8
0x06, 0x49, 0x49, 0x29, 0x1E , // 9
0x00, 0x36, 0x36, 0x00, 0x00 , // :
0x00, 0x56, 0x36, 0x00, 0x00 , // ;
0x08, 0x14, 0x22, 0x41, 0x00 , // <
0x14, 0x14, 0x14, 0x14, 0x14 , // =
0x00, 0x41, 0x22, 0x14, 0x08 , // >
0x02, 0x01, 0x51, 0x09, 0x06 , // ?
0x32, 0x49, 0x59, 0x51, 0x3E , // @
0x7E, 0x11, 0x11, 0x11, 0x7E , // A
0x7F, 0x49, 0x49, 0x49, 0x36 , // B
0x3E, 0x41, 0x41, 0x41, 0x22 , // C
0x7F, 0x41, 0x41, 0x22, 0x1C , // D
0x7F, 0x49, 0x49, 0x49, 0x41 , // E
0x7F, 0x09, 0x09, 0x09, 0x01 , // F
0x3E, 0x41, 0x49, 0x49, 0x7A , // G
0x7F, 0x04, 0x08, 0x10, 0x7F , // N
0x3E, 0x41, 0x41, 0x41, 0x3E , // O
0x7F, 0x09, 0x09, 0x09, 0x06 , // P
0x3E, 0x41, 0x51, 0x21, 0x5E , // Q
0x7F, 0x09, 0x19, 0x29, 0x46 , // R
0x46, 0x49, 0x49, 0x49, 0x31 , // S
0x01, 0x01, 0x7F, 0x01, 0x01 , // T
0x3F, 0x40, 0x40, 0x40, 0x3F , // U
0x1F, 0x20, 0x40, 0x20, 0x1F , // V
0x3F, 0x40, 0x38, 0x40, 0x3F , // W
0x63, 0x14, 0x08, 0x14, 0x63 , // X
0x07, 0x08, 0x70, 0x08, 0x07 , // Y
0x61, 0x51, 0x49, 0x45, 0x43 , // Z
0x00, 0x7F, 0x41, 0x41, 0x00 , // [
0x55, 0x2A, 0x55, 0x2A, 0x55 , // 55
0x00, 0x41, 0x41, 0x7F, 0x00 , // ]
0x04, 0x02, 0x01, 0x02, 0x04 , // ^
0x40, 0x40, 0x40, 0x40, 0x40 , // _
0x00, 0x01, 0x02, 0x04, 0x00 , // '
0x20, 0x54, 0x54, 0x54, 0x78 , // a
0x7F, 0x48, 0x44, 0x44, 0x38 , // b
0x38, 0x44, 0x44, 0x44, 0x20 , // c
0x38, 0x44, 0x44, 0x48, 0x7F , // d
0x38, 0x54, 0x54, 0x54, 0x18 , // e
0x08, 0x7E, 0x09, 0x01, 0x02 , // f
0x0C, 0x52, 0x52, 0x52, 0x3E , // g
0x7F, 0x08, 0x04, 0x04, 0x78 , // h
0x00, 0x44, 0x7D, 0x40, 0x00 , // i
0x20, 0x40, 0x44, 0x3D, 0x00 } ; // j
/* 0x7F, 0x10, 0x28, 0x44, 0x00 , // k
0x00, 0x41, 0x7F, 0x40, 0x00 , // l
0x7C, 0x04, 0x18, 0x04, 0x78 , // m
0x7C, 0x08, 0x04, 0x04, 0x78 , // n
0x38, 0x44, 0x44, 0x44, 0x38 , // o
0x7C, 0x14, 0x14, 0x14, 0x08 , // p
0x08, 0x14, 0x14, 0x18, 0x7C , // q
0x7C, 0x08, 0x04, 0x04, 0x08 , // r
0x48, 0x54, 0x54, 0x54, 0x20 , // s
0x04, 0x3F, 0x44, 0x40, 0x20 , // t
0x3C, 0x40, 0x40, 0x20, 0x7C , // u
0x1C, 0x20, 0x40, 0x20, 0x1C , // v
0x3C, 0x40, 0x30, 0x40, 0x3C , // w
0x44, 0x28, 0x10, 0x28, 0x44 , // x
0x0C, 0x50, 0x50, 0x50, 0x3C , // y
0x44, 0x64, 0x54, 0x4C, 0x44); // z
*/
int j;
unsigned int k;
void Display(int place)
{
int i;
PortA.F0=0;
PortA.F1=1;
PortA.F1=0;
for(i=0;i<=4;i++)
{
PortA.F0=1;
PortA.F2=1;
PortA.F1=1;
PortA.F1=0;
PortB=font5x7_1[i + place];
PortA.F2=0;
Delay_ms(3);
}
}
void main() {
CMCON = 0x07;
PortA = 0;
TrisA = 0;
PortB = 0;
TrisB = 0;
do {
k = 0;
do {
j = 1;
do {
Display(k);
j++;
} while(j<100);
k++;
k++;
k++;
k++;
k++;
} while(1);
}while(1);
}
|
i am be so thankful to u
thank you so much
waiting for ur reply... |
|
|
|
|
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
|