Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/22/09 12:16
Read: times


 
#162637 - Please have a look
Responding to: ???'s previous message
In the following code the value of a variable "row" is not increasing(automatically goes back to zero) due to which P2 is not working properly.
But when i remove the "switch" statement, it starts working properly.
Why??any help?

#include <reg51.h>

sbit P2_0 = P2^0;
sbit P2_1 = P2^1;
sbit P2_2 = P2^2;
sbit P2_3 = P2^3;
sbit P2_4 = P2^4;
sbit P2_5 = P2^5;
sbit P2_6 = P2^6;
sbit P2_7 = P2^7;

sbit P1_0 = P1^0;
sbit P1_1 = P1^1;
sbit P1_2 = P1^2;
sbit P1_3 = P1^3;

unsigned int row_data1[5][5]={
{1,1,1,1,1},
{0,1,0,0,0},
{0,0,1,0,0},
{1,1,1,1,1},
{1,1,1,1,1}
};
unsigned int word;
unsigned int i;
unsigned int j;

unsigned char row_data[5][5];
unsigned char loop_words;
unsigned char loop;
unsigned char loop1;
unsigned char a;
unsigned int row;
unsigned char delay;
unsigned char col;
unsigned char sr;

unsigned char msg[3];
unsigned char row_buff[6];

code unsigned char msg_org[3]={"ABC"};

main()
{
while (1)
{
word=0;
a=0;
  //strobe
   P1_0=0;

  //EO enable
P1_3=0;

for (sr=0;sr<7;sr++) {

row_buff[sr]=0; }

for (loop_words=0;loop_words<3;loop_words++) {
for (loop=0;loop<=5;loop++) {
for (loop1=0;loop1<50;loop1++) {
for (row=0;row<=5;row++)
 { 

for (word=0;word<=loop_words;word++) 
{
msg[word]=msg_org[word];

//WHEN I REMOVE THIS SWITCH IT WORKS PROPERLY

switch(msg[word])
{
case 'A':

  for (i=0;i<6;i++)
{
for (j=0;j<6;j++)
{row_data[i][j]=row_data1[i][j];
}
     }

	 break;
}
if (loop_words==0)
{
for (col=0;col<=loop;col++)
{
row_buff[a]=row_data[row][col];

 P1_1=row_buff[a] ;
 //clock
 P1_2=0;
P1_2=1;
 a=a+1;
 }
 }//if loop words==0
 else if (loop_words>0)
 {
 if (word<loop_words)
 {
 for (col=0;col<=5;col++)
{
row_buff[a]=row_data[row][col];

 P1_1=row_buff[a] ;
 //clock
 P1_2=0;
P1_2=1;
 a=a+1;
 }//for col
 }//for if

 else if (word=loop_words)
 {
 for (col=0;col<=loop;col++)
{
row_buff[a]=row_data[row][col];

 P1_1=row_buff[a] ;
 //clock
 P1_2=0;
P1_2=1;
 a=a+1;
 }//for col
}//for if
}//for if



}//for word



//PROBLEM

// "NOT INCREASING and every time P2_2 is zero"
if (row==0)
 P2_0=0 ;
 if (row==1) 
 P2_1=0 ;
if (row==2) 
 P2_2=0;
if (row==3)
  P2_3=0;
if (row==4) 
 P2_4=0;
    //strobe
   P1_0=1;
  //EO enable
P1_3=1;
 // delay
 for (delay=0;delay<200;delay++) {
 }
 //clr the buffer here
 for (sr=0;sr<6;sr++){
row_buff[sr]=0;
}
a=0;
//clr strobe
   P1_0=0;
//clr EO enable
P1_3=0;
//ports initializaion
 P2=0xFF;
//clr the SR
for (sr=0;sr<9;sr++){
P1_1=0;
//clock
P1_2=0;
P1_2=1;

}

}//for row

}//fr loop1
}//for loop
}//for loop_words
}//while
}//main

 



List of 35 messages in thread
TopicAuthorDate
C++ and Keil problem            01/01/70 00:00      
   be less suprised,            01/01/70 00:00      
   Keil C51 is _not_ a C++ compiler.            01/01/70 00:00      
   Very old!            01/01/70 00:00      
      Ok guys            01/01/70 00:00      
         Totally missing the point!            01/01/70 00:00      
            Now what is the problem...            01/01/70 00:00      
               Post the full build output            01/01/70 00:00      
                  the code...            01/01/70 00:00      
                     Missing the point again            01/01/70 00:00      
                     No successful output from compiler possible            01/01/70 00:00      
                        C99            01/01/70 00:00      
                           C99 in Keil            01/01/70 00:00      
                     About your Code            01/01/70 00:00      
                        Local variables within inner blocks            01/01/70 00:00      
                           Thanks for correcting me.            01/01/70 00:00      
                              Improved scope            01/01/70 00:00      
   an often missed fact is ...            01/01/70 00:00      
      Coming to harware implementation.            01/01/70 00:00      
         Consultancy fees            01/01/70 00:00      
         will help            01/01/70 00:00      
         problems of Keil with C            01/01/70 00:00      
         New Topic, New Thread            01/01/70 00:00      
   I got the error            01/01/70 00:00      
      C241 Error            01/01/70 00:00      
         RTFM            01/01/70 00:00      
            how to get rid of it?            01/01/70 00:00      
               if something is too big, you need to make it smaller            01/01/70 00:00      
                  Please have a look            01/01/70 00:00      
                     Bounds checking            01/01/70 00:00      
                        Thanks            01/01/70 00:00      
                           But did you look at your code?            01/01/70 00:00      
                              ok            01/01/70 00:00      
                              ISR Problem            01/01/70 00:00      
                                 Start a new thread!            01/01/70 00:00      

Back to Subject List