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

how to convert this code to c
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nasbyc



Joined: 27 Apr 2009
Posts: 50

View user's profile Send private message AIM Address

PostPosted: Fri Jun 12, 2009 11:07 am     Reply with quote

hmmm
I already tested my program. For the first read, I got FAH and the second one FCH then it suddenly stop executing my program. I also try without loop for example
Code:
keyin=fgetc(COM_B);
fprintf(COM_A,"keyin = %LX\n",keyin);

When I try execute it, it generates continuous data. The program executed nonstop. Should I use code like in software uart ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 12, 2009 11:14 am     Reply with quote

The software UART has to constantly check the Rx pin for a start bit,
to see the beginning of an new incoming character. If you have code
(such as a printf statement for COM_A) that does something else for
a time period, the software UART will miss the incoming start bit.
It will miss the incoming byte on the Rx pin.

This is a limitation of the CCS software UART code.
nasbyc



Joined: 27 Apr 2009
Posts: 50

View user's profile Send private message AIM Address

PostPosted: Fri Jun 12, 2009 11:28 am     Reply with quote

Do you mean I have to remove the printf and put delay on it? Or check acknowledgement signal has been received?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 12, 2009 11:44 am     Reply with quote

Don't use printf or delays, in a loop that is getting characters
from a software UART. The complete processing time of the
PIC must be used for the software UART only. If you take
time away from the software UART, you will lose incoming characters.
nasbyc



Joined: 27 Apr 2009
Posts: 50

View user's profile Send private message AIM Address

PostPosted: Mon Jun 15, 2009 4:42 pm     Reply with quote

I tried using for loop to get the 5 bytes
Code:
for(i=1;i<6;i++)
{
   keyin[i]=fgetc(COM_B);
}

x1 =keyin[1];
fprintf(COM_A,"x1 = %LX \n",x1);
delay_ms(1000);
x2 =keyin[2];
fprintf(COM_A,"x2= %LX \n",x2);
delay_ms(1000);
y1 =keyin[3];
fprintf(COM_A,"y1 = %LX \n"y1);
delay_ms(1000);
y2 =keyin[4];
fprintf(COM_A,"y2 = %LX \n",y2);
delay_ms(1000);
button =keyin[5];
fprintf(COM_A,"button = %LX \n",button);
delay_ms(1000);

this is the result that I got

x1 = FA
x2= FA
y1 = 08
y2 = 00
button = 00

I don't think the data are correct. is it because error in data sampling and it is correct that every data send by mouse to the host will has acknowledgement
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 15, 2009 4:55 pm     Reply with quote

Post the manufacturer, name, and model number of the mouse.
nasbyc



Joined: 27 Apr 2009
Posts: 50

View user's profile Send private message AIM Address

PostPosted: Mon Jun 15, 2009 5:01 pm     Reply with quote

I used two mouse
1. genius model:GM-03020U/A
2.LOGITECH:VALUE OPTICAL MOUSE M/N:M-BT83 P/N:810-000361
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 16, 2009 1:44 pm     Reply with quote

Post a link to documents that show the serial output protocol
used by these mouse devices.
nasbyc



Joined: 27 Apr 2009
Posts: 50

View user's profile Send private message AIM Address

PostPosted: Tue Jun 16, 2009 4:12 pm     Reply with quote

This is the website link to the pak-xi that I used to connect my mouse

http://www.awce.com/pak11.htm

this is the manual

http://www.awce.com/pak11.pdf
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Jun 17, 2009 2:30 am     Reply with quote

nasbyc wrote:
I tried using for loop to get the 5 bytes
Code:
for(i=1;i<6;i++)
{
   keyin[i]=fgetc(COM_B);
}

x1 =keyin[1];
fprintf(COM_A,"x1 = %LX \n",x1);
delay_ms(1000);
x2 =keyin[2];
fprintf(COM_A,"x2= %LX \n",x2);
delay_ms(1000);
y1 =keyin[3];
fprintf(COM_A,"y1 = %LX \n"y1);
delay_ms(1000);
y2 =keyin[4];
fprintf(COM_A,"y2 = %LX \n",y2);
delay_ms(1000);
button =keyin[5];
fprintf(COM_A,"button = %LX \n",button);
delay_ms(1000);

this is the result that I got

x1 = FA
x2= FA
y1 = 08
y2 = 00
button = 00

I don't think the data are correct. is it because error in data sampling and it is correct that every data send by mouse to the host will has acknowledgement


Where is your definition of keyin ?
looking at this I bet it is defined as
int keyin[5];

Arrays in C have a 0 based index as default so you either need to define it as
int keyin[6]; // for indexes [0] to [5]

or change your loop and references
for (i=0; i<5; i++)
...
x1 = keyin[0];

What data are you expecting ?
nasbyc



Joined: 27 Apr 2009
Posts: 50

View user's profile Send private message AIM Address

PostPosted: Sun Jun 28, 2009 3:47 pm     Reply with quote

hi there

I already managed to get the correct data. However this is only data from one mouse. What should I do if want to read the data from several mouse simultaneously? I already tried several attempts to read a mouse and display its values before collecting data from another mouse, but this will cause lost of data and reduce the performance of the system.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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