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 CCS Technical Support

pin "state" (output/input) is important? RA8835

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



Joined: 03 Mar 2008
Posts: 55

View user's profile Send private message

pin "state" (output/input) is important? RA8835
PostPosted: Fri Jun 19, 2009 12:04 pm     Reply with quote

hi,

Since I started to programmed with CCS I never had to configure direction for pin, I was just doing output_low, output_high, input(XX) and it was working perfectly fine.

Now I want to speak with an RA8835. I wrote my own driver which is working.

But when it comes to reading data, I get corrupted data.

To ask what's on a register you must firstly tell him which memory case you want to read.
Code:

//retrieve data from the cursor position
int8 GetData(int16 addr)
{
   setCursorAddress(addr);
   glcd_sendCMD(0x43); //send the reading request command
   DATA_MODE //A0
   return glcd_readByte();
}

//send a command
void glcd_sendCMD(int8 cmd)
{
   COMMAND_MODE //A0
   glcd_sendByte(cmd); //send a byte
}

//send a byte
void glcd_sendByte(byte data)
{
   GlcdPutData(data); //put data on the right pins
   output_low(GLCD_CS);
   //delay_cycles(1);
   output_low(GLCD_WR);
  // delay_cycles(2);
   output_high(GLCD_WR);
   output_high(GLCD_CS);
}

void GlcdPutData(byte data)
   {
   output_bit(GLCD_DB0, !!(data & 1));     
   output_bit(GLCD_DB1, !!(data & 2));                   
   output_bit(GLCD_DB2, !!(data & 4));                   
   output_bit(GLCD_DB3, !!(data & 8));
   output_bit(GLCD_DB4, !!(data & 16));
   output_bit(GLCD_DB5, !!(data & 32));                   
   output_bit(GLCD_DB6, !!(data & 64));                 
   output_bit(GLCD_DB7, !!(data & 128));
   }

//read a byte from the cursor pos
int8 glcd_readByte()
{
   int8 data;
   output_low(GLCD_CS);
   delay_cycles(1);
   output_low(GLCD_RD);
   delay_cycles(2);
   data = TakeData();
   output_high(GLCD_RD);
   output_high(GLCD_CS);

   return data;
}

//retrieve data from the right pin, fully working, used in others code
int8 TakeData(void)
   {
   int8 data = 0;
   data += input(GLCD_DB0);
   data += input(GLCD_DB1)*2;
   data += input(GLCD_DB2)*4;
   data += input(GLCD_DB3)*8;
   data += input(GLCD_DB4)*16;
   data += input(GLCD_DB5)*32;
   data += input(GLCD_DB6)*64;
   data += input(GLCD_DB7)*128;
   return data;
   }


Could my data be corrupted because I let CCS handle the "direction" of the pins?
Should I change myself just after writing my pin "state"?

Example: I should read 0b00000000 from him but instead I'm getting stuff such as:

0b01000000 or 0b11000000

thanks
_________________
yup, i know, i don't speak english very well

CCS V4.057
Ttelmah
Guest







PostPosted: Fri Jun 19, 2009 2:43 pm     Reply with quote

Why output the data one bit at a time, and input it the same way?. Risks timing errors. As it stands, there will be dozens of machine cycles between inputting or outputing the low bit, and the top bit. Just output/input the whole byte.

Code:

#define GlcdPutData(X) output_b(x)
#define glcd_readByte() input_b()

and remove your routines for these.

The output routine, is appalling. It has to perform a bytewise and on the whole byte, then invert it twice, to get the value of a single bit. If you want to do it this way, use:

output_bit(GLCD_DB0, bit_test(data,0));

Which the compiler can generate in just one machine instruction to evaluate the value of the bit.

Outputting 'bit at a time' though, also runs the risk of hitting the PIC RMW problem, depending on the capacitance/loading of the lines.

Best Wishes
sliders_alpha



Joined: 03 Mar 2008
Posts: 55

View user's profile Send private message

PostPosted: Fri Jun 19, 2009 4:19 pm     Reply with quote

Quote:
Why output the data one bit at a time, and input it the same way?. Risks timing errors. As it stands, there will be dozens of machine cycles between inputting or outputing the low bit, and the top bit. Just output/input the whole byte.

Because I don't want to use a whole port, I want to be able to wire DB0 to DB7 anywhere.

Here I'm using B0 to B5 and C3-C4.

Quote:

The output routine, is appalling. It has to perform a bytewise and on the whole byte, then invert it twice, to get the value of a single bit. If you want to do it this way, use:

output_bit(GLCD_DB0, bit_test(data,0));

Thanks for the tip.

So now my function is :
Code:

void GlcdPutData(byte data)
   {
   output_bit(GLCD_DB0, bit_test(data,0));     
   output_bit(GLCD_DB1, bit_test(data,1));                   
   output_bit(GLCD_DB2, bit_test(data,2));                   
   output_bit(GLCD_DB3, bit_test(data,3));
   output_bit(GLCD_DB4, bit_test(data,4));
   output_bit(GLCD_DB5, bit_test(data,5));                   
   output_bit(GLCD_DB6, bit_test(data,6));                 
   output_bit(GLCD_DB7, bit_test(data,7));
   

Forgot to tell, I'm using a 16F876A here.
_________________
yup, i know, i don't speak english very well

CCS V4.057
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