i tried your suggestion as code below but with no success, at GLCD the unknown character appears at the respective column needed to be changed.
Code: Select all
int random;
int row,col;
int block=0,i=0; int j=0;
unsigned char ran,tErr[2];
unsigned char num1, num2;
char array[9][9];
char arrayaku[9][9];
/*char array1[9];
char array2[9];
char array3[9];
char array4[9];
char array5[9];
char array6[9]; */
// Glcd module connections
char GLCD_DataPort at PORTD;
sbit GLCD_CS1 at LATB0_bit;
sbit GLCD_CS2 at LATB1_bit;
sbit GLCD_RS at LATB2_bit;
sbit GLCD_RW at LATB3_bit;
sbit GLCD_EN at LATB4_bit;
sbit GLCD_RST at LATB5_bit;
sbit GLCD_CS1_Direction at TRISB0_bit;
sbit GLCD_CS2_Direction at TRISB1_bit;
sbit GLCD_RS_Direction at TRISB2_bit;
sbit GLCD_RW_Direction at TRISB3_bit;
sbit GLCD_EN_Direction at TRISB4_bit;
sbit GLCD_RST_Direction at TRISB5_bit;
// End Glcd module connections
void display(){ // if (trg2==1) {
Glcd_Fill(0x00); // Clear GLCD
Glcd_Set_Font(font5x7, 5, 7, 32); // Change font
// ByteToStr(txt, tErr); //floatToStr(value,tErr);
Glcd_Write_Text( "a1" , 1, 0, 2); // Write string
Glcd_Write_Text( array[1] , 17, 0, 2);
Glcd_Write_Text( "a2" , 65, 0, 2); // Write string
Glcd_Write_Text(array[2], 77, 0, 2);
IntToStr(row,tErr);
Glcd_Write_Text( "row" , 1, 1, 2); // Write string
Glcd_Write_Text( tErr , 17, 1, 2);
IntToStr(col,tErr);
Glcd_Write_Text( "col" , 65, 1, 2); // Write string
Glcd_Write_Text( tErr , 77, 1, 2);
Glcd_Write_Text( "aku" , 1, 2, 2); // Write string
Glcd_Write_Text( arrayaku , 17, 2, 2);
Glcd_Write_Text( "a6" , 65, 2, 2); // Write string
Glcd_Write_Text( array[6] , 77, 2, 2);
Glcd_Write_Text( "n1" , 1, 4, 2); // Write string
//Glcd_Write_Text( num1, 17, 4, 2);
Glcd_Write_Text( "n2" , 65, 4, 2); // Write string
//Glcd_Write_Text( num2, 77, 4, 2);
IntToStr(block,tErr);
Glcd_Write_Text( "j" , 65, 6, 2); // Write string
Glcd_Write_Text( tErr, 77, 6, 2);
// Glcd_Write_Text( "r" , 1, 7, 2); // Write string
//Glcd_Write_Text( ran, 27, 7, 2);
IntToStr(j,tErr);
Glcd_Write_Text( "j" , 65, 7, 2); // Write string
Glcd_Write_Text( tErr, 77, 7, 2);
Delay_ms(3000); // }
}
void FourBitsToStr( unsigned char n, unsigned char *s )
{
unsigned char mask = 0x08;
while(mask)
{
if (n & mask)
*s++ = '1';
else
*s++ = '0';
mask >>= 1;
}
*s = '\0';
}
void BitsToStr( unsigned char n, unsigned char *s )
{
unsigned char mask = 0x80;
while(mask)
{
if (n & mask)
*s++ = '1';
else
*s++ = '0';
mask >>= 1;
}
*s = '\0';
}
unsigned char StrBitsToUChar( unsigned char *s, unsigned char *buffer )
{
unsigned char mask;
unsigned char i;
unsigned char save = *buffer;
if( *buffer > 15 || *buffer == 0 )
mask = 0x80;
else
mask = 0x08;
for( i = 0; s[i]; i++, mask >>= 1 )
{
if( s[i] == '1' )
*buffer |= mask;
else if( s[i] == '0' )
*buffer &= ~mask;
else
{
*buffer = save;
return 1;
}
}
return 0;
}
void main() {
ANSELB = 0; // Configure PORTB pins as digital I/O
ANSELD = 0;
ANSELC = 0; // Set PORTC as output
TRISD = 0x00; // Set PORTD as output
LATD=0;
//ADC_init();
TRISE=0;
LATE=0;
TRISA=0x7F; ANSELA = 0; // LATA=0;
TRISB=0x00;
LATB=0;
CM1CON0=0;
CM2CON0=0;
Glcd_Init(); // Initialize GLCD
Glcd_Fill(0x00);
// Initialize UART module at 9600 bps
Delay_ms(100); // Initialize UART module at 9600 bps
Glcd_Fill(0x00);
//chrom1[1]="7";
//num1=8;
while (1) {
ran = 0x0F;
BitsToStr( ran, array[1] );
if (StrBitsToUChar(array[1], &num1))
{
asm nop
}
ran = 0xF0;
BitsToStr( ran, array[2] );
if (StrBitsToUChar(array[2], &num2))
{
asm nop
}
// ran = num1 & num2;
//BitsToStr( ran, array1 ); // array1 is "00000000"
//ran = num1 | num2;
//BitsToStr( ran, array2 ); // array2 is "11111111"
//block=strlen(array1);
//unsigned char num1;
strcpy(array[6],array[1]);
StrBitsToUChar(array[6], &num1);
ByteToStr(num1, array[6]);
//block=array1;
/* ran = rand()%256;
BitsToStr( ran, array3 );
array3[2] = 's';
if (StrBitsToUChar(array3, &num1)) //returns error num1 has unchanged
{
asm nop
}
ran = rand()%16; // random 4 bits
FourBitsToStr( ran, array4 );
ran = rand()%16;
FourBitsToStr( ran, array5 );
ran = rand()%16;
fourBitsToStr( ran, array6 ); */
random=rand()%50; //random value is between ( 0 - 49 )
// if (random==25) // Suppusiong Probability of mutation is 2 %
//{
//col=rand()%6; // random column (gene) choosing
// strcpy(arrayaku,array1);
//row=rand()%4;
// arrayaku[row][col] = ~arrayaku[row][col];
//arrayaku[row][col] = 1;}
row=0;
col=4;
strcpy(arrayaku,array[1]);
strcpy(array[6],array[1]);
arrayaku[row][col] =~arrayaku[row][col];
row=1;
array[row][col] =~array[row][col];
array[2][4] =1;
StrBitsToUChar(array[6], &num1);
ByteToStr(num1, array[6]);
display();
}
}