|
|
View previous topic :: View next topic |
Author |
Message |
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
Array element and restart problem |
Posted: Wed Nov 30, 2016 3:57 am |
|
|
Hello everyone,
I made a 5x5 led matrix and i am using 18f2550 to use it. I wrote the code below and it works fine until i add 7th variable on the array. Is there something wrong with my fuse settings or something else?
Here is the code
Code: |
#include <18F2550.h>
#fuses INTRC_IO, NOWDT, PUT, NOLVP,NOMCLR,NOPROTECT,NOLVP,NODEBUG,NOBROWNOUT,CPUDIV1,VREGEN
#device ADC=10
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#define poz_1 PIN_A0
#define poz_2 PIN_A1
#define poz_3 PIN_A2
#define poz_4 PIN_A3
#define poz_5 PIN_A4
#define gnd_1 PIN_B1
#define gnd_2 PIN_B2
#define gnd_3 PIN_B3
#define gnd_4 PIN_B4
#define gnd_5 PIN_B5
int sondur = 0b1111100000; //close all the lights
//these are letters
int16 Aharf[5] = {0b1001100001,0b0110100010,0b0000100100,0b0110101000,0b0110110000};
int16 Bharf[5] = {0b0001100001,0b0110100010,0b0001100100,0b0110101000,0b0001110000};
int16 Charf[5] = {0b0000100001,0b0111100010,0b0111100100,0b0111101000,0b0000110000};
int16 Dharf[5] = {0b0001100001,0b0110100010,0b0110100100,0b0110101000,0b0001110000};
int16 Eharf[5] = {0b0000100001,0b0111100010,0b0000100100,0b0111101000,0b0000110000};
int16 Fharf[5] = {0b0000100001,0b0111100010,0b0000100100,0b0111101000,0b0111110000};
int16 Gharf[5] = {0b0000100001,0b0111100010,0b0100100100,0b0110101000,0b0000110000};
int16 Hharf[5] = {0b0110100001,0b0110100010,0b0000100100,0b0110101000,0b0110110000};
int16 Iharf[5] = {0b0001100001,0b1011100010,0b1011100100,0b1011101000,0b0001110000};
int16 Jharf[5] = {0b1000100001,0b1101100010,0b1101100100,0b1101101000,0b0011110000};
int16 Kharf[5] = {0b0110100001,0b0101100010,0b0011100100,0b0101101000,0b0110110000};
int16 Lharf[5] = {0b0111100001,0b0111100010,0b0111100100,0b0111101000,0b0000110000};
int16 Mharf[5] = {0b0111000001,0b0010000010,0b0101000100,0b0111001000,0b0111010000};
int16 Nharf[5] = {0b0111000001,0b0011000010,0b0101000100,0b0110101000,0b0111010000};
int16 Oharf[5] = {0b1001100001,0b0110100010,0b0110100100,0b0110101000,0b1001110000};
int16 Pharf[5] = {0b0001100001,0b0110100010,0b0001100100,0b0111101000,0b0111110000};
int16 Rharf[5] = {0b0001100001,0b0110100010,0b0001100100,0b0101101000,0b0110110000};
int16 Sharf[5] = {0b1000100001,0b0111100010,0b1001100100,0b1110101000,0b0001110000};
int16 Tharf[5] = {0b0000000001,0b1101100010,0b1101100100,0b1101101000,0b1101110000};
int16 Uharf[5] = {0b0110100001,0b0110100010,0b0110100100,0b0110101000,0b0000110000};
int16 Vharf[5] = {0b0110100001,0b0110100010,0b0110100100,0b0110101000,0b1001110000};
int16 Yharf[5] = {0b0111000001,0b1010100010,0b1101100100,0b1101101000,0b1101110000};
int16 Zharf[5] = {0b0000000001,0b1110100010,0b1101100100,0b1011101000,0b0000010000};
int16 yazi[6] = {Rharf,Oharf,Bharf,Oharf,Tharf,Sharf}; // this is the image i try to write. If i write this it works.
// But if i write ROBOTSA the last letter 'A' becomes a weird figure.
// I thought it could be from of the array Aharf, but when i print SELAM, or A by it self, it still works right.
// The problem is it gets weird after the 7th element.
int16 i=0;
int16 k=0;
void sekilbas(int16);
void dizibas(int16 dizi[]);
void main()
{
setup_oscillator(OSC_4MHz);
while(TRUE){
for(k=0;k<6;k++) //chooses the element from yazi[] array
{
for(i=0;i<500;i++)
{
dizibas(yazi[k]); //calls the printing function and opens led for a time period
}
sekilbas(sondur); //closes all the leds after each letters printed
delay_ms(100);
}
sekilbas(sondur);
}
}
void sekilbas(int16 number) //this gives the outputs the elements of array
{
output_bit(PIN_B5,bit_test(number,9));
output_bit(PIN_B4,bit_test(number,8));
output_bit(PIN_B3,bit_test(number,7));
output_bit(PIN_B2,bit_test(number,6));
output_bit(PIN_B1,bit_test(number,5));
output_bit(PIN_A4,bit_test(number,4));
output_bit(PIN_A3,bit_test(number,3));
output_bit(PIN_A2,bit_test(number,2));
output_bit(PIN_A1,bit_test(number,1));
output_bit(PIN_A0,bit_test(number,0));
}
void dizibas(int16 dizi[]) //this opens the leds row by row with little delay
{
int i=0;
for(i=0;i<5;i++)
{
sekilbas(dizi[i]);
delay_us(500);
}
}
|
I have another question. I write a code and upload it to the 18f2550 and see that it works. If i restart pic, the code gives weird random figures. After i upload the same code it works again. What might be the problem?
Thanks for help and sorry for bad english. If anything is unclear i can try to rewrite.
Best Wishes
Doğuhan
Edit: changed the 6th element to 7th element, and i changed the variable in for loop to k<7
Edit2: hello again. i think i found the problem. it was about array dimensions. when i tried to increase the array size to 8 the compiler could not compile it. i think i did wrong when try to create an array of arrays.
so i changed the code to this.
Code: |
#include <18F2550.h>
#fuses INTRC_IO, NOWDT, PUT, NOLVP,NOMCLR,NOPROTECT,NOLVP,NODEBUG,NOBROWNOUT,CPUDIV1,VREGEN
#device ADC=10
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#define poz_1 PIN_A0
#define poz_2 PIN_A1
#define poz_3 PIN_A2
#define poz_4 PIN_A3
#define poz_5 PIN_A4
#define gnd_1 PIN_B1
#define gnd_2 PIN_B2
#define gnd_3 PIN_B3
#define gnd_4 PIN_B4
#define gnd_5 PIN_B5
int sondur = 0b1111100000;
int16 gulenyuz[3] = {0b1010100010,0b0111001000,0b1000110000};
int16 somurtanyuz[3] = {0b1010100010,0b1000101000,0b0111010000};
int16 Aharf[5] = {0b1001100001,0b0110100010,0b0000100100,0b0110101000,0b0110110000};
int16 Bharf[5] = {0b0001100001,0b0110100010,0b0001100100,0b0110101000,0b0001110000};
int16 Charf[5] = {0b0000100001,0b0111100010,0b0111100100,0b0111101000,0b0000110000};
int16 Dharf[5] = {0b0001100001,0b0110100010,0b0110100100,0b0110101000,0b0001110000};
int16 Eharf[5] = {0b0000100001,0b0111100010,0b0000100100,0b0111101000,0b0000110000};
int16 Fharf[5] = {0b0000100001,0b0111100010,0b0000100100,0b0111101000,0b0111110000};
int16 Gharf[5] = {0b0000100001,0b0111100010,0b0100100100,0b0110101000,0b0000110000};
int16 Hharf[5] = {0b0110100001,0b0110100010,0b0000100100,0b0110101000,0b0110110000};
int16 Iharf[5] = {0b0001100001,0b1011100010,0b1011100100,0b1011101000,0b0001110000};
int16 Jharf[5] = {0b1000100001,0b1101100010,0b1101100100,0b1101101000,0b0011110000};
int16 Kharf[5] = {0b0110100001,0b0101100010,0b0011100100,0b0101101000,0b0110110000};
int16 Lharf[5] = {0b0111100001,0b0111100010,0b0111100100,0b0111101000,0b0000110000};
int16 Mharf[5] = {0b0111000001,0b0010000010,0b0101000100,0b0111001000,0b0111010000};
int16 Nharf[5] = {0b0111000001,0b0011000010,0b0101000100,0b0110101000,0b0111010000};
int16 Oharf[5] = {0b1001100001,0b0110100010,0b0110100100,0b0110101000,0b1001110000};
int16 Pharf[5] = {0b0001100001,0b0110100010,0b0001100100,0b0111101000,0b0111110000};
int16 Rharf[5] = {0b0001100001,0b0110100010,0b0001100100,0b0101101000,0b0110110000};
int16 Sharf[5] = {0b1000100001,0b0111100010,0b1001100100,0b1110101000,0b0001110000};
int16 Tharf[5] = {0b0000000001,0b1101100010,0b1101100100,0b1101101000,0b1101110000};
int16 Uharf[5] = {0b0110100001,0b0110100010,0b0110100100,0b0110101000,0b0000110000};
int16 Vharf[5] = {0b0110100001,0b0110100010,0b0110100100,0b0110101000,0b1001110000};
int16 Yharf[5] = {0b0111000001,0b1010100010,0b1101100100,0b1101101000,0b1101110000};
int16 Zharf[5] = {0b0000000001,0b1110100010,0b1101100100,0b1011101000,0b0000010000};
//int16 yazi[7] = {Rharf,Oharf,Bharf,Oharf,Tharf,Sharf,Aharf};
char yazi[8] = {'R','O','B','O','T','S','A','N'};
int16 i=0;
int16 k=0;
void sekilbas(int16);
void dizibas(int16 dizi[]);
void elemansec(char dizi2[]);
void main()
{
setup_oscillator(OSC_4MHz);
while(TRUE)
{
elemansec(yazi);
}
}
void sekilbas(int16 number)
{
output_bit(PIN_B5,bit_test(number,9));
output_bit(PIN_B4,bit_test(number,8));
output_bit(PIN_B3,bit_test(number,7));
output_bit(PIN_B2,bit_test(number,6));
output_bit(PIN_B1,bit_test(number,5));
output_bit(PIN_A4,bit_test(number,4));
output_bit(PIN_A3,bit_test(number,3));
output_bit(PIN_A2,bit_test(number,2));
output_bit(PIN_A1,bit_test(number,1));
output_bit(PIN_A0,bit_test(number,0));
}
void dizibas(int16 dizi[])
{
int i=0;
int16 k=0;
for(k=0;k<500;k++)
{
for(i=0;i<5;i++)
{
sekilbas(dizi[i]);
delay_us(500);
}
}
sekilbas(sondur);
delay_ms(100);
}
void elemansec(char dizi2[])
{
int i = 0;
for(i=0;i<sizeof(yazi);i++)
{
switch(dizi2[i])
{
case 'A': dizibas(Aharf); break;
case 'B': dizibas(Bharf); break;
case 'C': dizibas(Charf); break;
case 'D': dizibas(Dharf); break;
case 'E': dizibas(Eharf); break;
case 'F': dizibas(Fharf); break;
case 'G': dizibas(Gharf); break;
case 'H': dizibas(Hharf); break;
case 'I': dizibas(Iharf); break;
case 'J': dizibas(Jharf); break;
case 'K': dizibas(Kharf); break;
case 'L': dizibas(Lharf); break;
case 'M': dizibas(Mharf); break;
case 'N': dizibas(Nharf); break;
case 'O': dizibas(Oharf); break;
case 'P': dizibas(Pharf); break;
case 'R': dizibas(Rharf); break;
case 'S': dizibas(Sharf); break;
case 'T': dizibas(Tharf); break;
case 'U': dizibas(Uharf); break;
case 'V': dizibas(Vharf); break;
case 'Y': dizibas(Yharf); break;
case 'Z': dizibas(Zharf); break;
default: sekilbas(sondur); break;
}
}
} |
i know it is a very simple and amateur way to drive a led matrix but i hope it will be useful to someone.
Best wishes
Doğuhan |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Wed Nov 30, 2016 6:03 am |
|
|
Change the declarations for the matrix drive data, so:
int16 Aharf[5] = {0b1001100001,0b0110100010,0b0000100100,0b0110101000,0b0110110000};
to 'const int16'.
This data is constant, and this will save you several hundred bytes of RAM.... |
|
|
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
|
Posted: Wed Nov 30, 2016 7:03 am |
|
|
Ttelmah wrote: | Change the declarations for the matrix drive data, so:
int16 Aharf[5] = {0b1001100001,0b0110100010,0b0000100100,0b0110101000,0b0110110000};
to 'const int16'.
This data is constant, and this will save you several hundred bytes of RAM.... |
Thank you so much Ttelmah. i tried to do it but i got this error. 'attempt to create a pointer to a constant'. i googled about it but most of the problems people face are about strings. i am trying to find an integer example and learn how access a constant integer in a function. i tried this
Code: |
int16 const Aharf[5] = {0b1001100001,0b0110100010,0b0000100100,0b0110101000,0b0110110000};
//-----------------rest of the code
case 'A': dizibas(Aharf); break;
//and
case 'A': dizibas(const Aharf); break;
//and
case 'A': dizibas(const int16 Aharf); break;
|
either way, no luck.
if i can manage it it will be very useful. thank you for your help again. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Wed Nov 30, 2016 7:43 am |
|
|
For using pointers, you have to use rom, instead of const. Sorry. |
|
|
|
|
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
|