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

Microsoft Serial mouse

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







Microsoft Serial mouse
PostPosted: Wed Mar 29, 2006 2:51 am     Reply with quote

I am using PIC 16f877 as amouse controller
This is my code in C language

i am using the already example code but i do not make it as interrupt

The computer recognize a serial mouse and shows that it works.

But when i send data for movement or pushing a click it does not work.

i am sure that i send data correctly.. but no respond.
Can any one Help me.
Thanks...


Code:

#elif defined(__PCM__)
#include <16F877.h>
#device ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOPUT
#use delay(clock=20000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7,errors)  // Jumpers: 8 to 11, 7 to 12

#define MICROSOFT TRUE
#define MOUSE_SYSTEMS FALSE   //not tested.  may not be compatable with Windows

#DEFINE LEFT_BUTTON PIN_B6
#DEFINE RIGHT_BUTTON PIN_B7
#DEFINE MIDDLE_BUTTON PIN_B5

#DEFINE X_CHANNEL 0
#DEFINE Y_CHANNEL 1

struct {
   short int delta;
   short int left;
   short int right;
   short int middle;
   signed int x;
   signed int y;
} mouse;

void clear_all_mouse(void) {
   mouse.delta=0;
   mouse.x=0;
   mouse.y=0;
   mouse.left=0;
   mouse.right=0;
   mouse.middle=0;
}

#int_ext
void reset(void) {
 #if MICROSOFT
   clear_all_mouse();
   putc(0x80|'M');
 #endif
}

void get_data(void) {
   signed int pos;

   if ((input(LEFT_BUTTON))&&(mouse.left)) {mouse.left=0;mouse.delta=1;}
   if ((input(RIGHT_BUTTON))&&(mouse.right)) {mouse.right=0;mouse.delta=1;}
   if ((input(MIDDLE_BUTTON))&&(mouse.middle)) {mouse.middle=0;mouse.delta=1;}

   if ((!input(LEFT_BUTTON))&&(!mouse.left)) {mouse.left=1;mouse.delta=1;}
   if ((!input(RIGHT_BUTTON))&&(!mouse.right)) {mouse.right=1;mouse.delta=1;}
   if ((!input(MIDDLE_BUTTON))&&(!mouse.middle)) {mouse.middle=1;mouse.delta=1;}

   set_adc_channel(X_CHANNEL);
   delay_us(10);
   pos=read_adc() & 0xF8;
   mouse.x=(pos-0x80)/10;

   set_adc_channel(Y_CHANNEL);
   delay_us(10);
   pos=read_adc() & 0xF8;
   mouse.y=(pos-0x80)/10;

   if ((mouse.x)||(mouse.y)) {mouse.delta=1;}
}

void send_data(void) {
#if MICROSOFT
    putc(0xC0 | (mouse.left << 5) | (mouse.right <<4 ) | ((mouse.y >> 4) & 0x0C) | ((mouse.x >> 6) & 0x03));
    putc(0x80 | mouse.x & 0x3F);
    putc(0x80 | mouse.y & 0x3F);
#elif MOUSE_SYSTEMS
   putc(0x80 | (!mouse.left<<2) | (!mouse.middle<<1) | !mouse.right);
   putc(mouse.x);
   mouse.x=0;
   putc(mouse.y);
   mouse.y=0;
   putc(mouse.x);
   putc(mouse.y);
#endif
   mouse.delta=0;
   mouse.x=0;
   mouse.y=0;
}

void main(void) {

   clear_all_mouse();

   setup_adc_ports(RA0_RA1_RA3_ANALOG);
   setup_adc(ADC_CLOCK_DIV_2);
   ext_int_edge(H_TO_L);
   enable_interrupts(int_ext);
   enable_interrupts(global);

   while (TRUE) {
      get_data();
      if (mouse.delta) {send_data();delay_ms(17);}
   }
}
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