Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

SERIAL MOUSE PROGRAM

#include<pic.h>
//Header File
void default();
//function declarations
void mov1(int m);
void mov2(int m);
void mov3(int m);
void mov4(int m);
void mov5(int m);
void mov6(int m);
void mov7(int m);
void mov8(int m);
void divide1(int p);
void divide2(int q);
void click();
void interrupt ext()
void usartinit()
void ExternalInt()
void adc();
int x,y,u,m,c,p,q;
/
***********************************************************************/
/*MainFunction */
/
***********************************************************************/
void main()
{
uartinit();
//call UART transmission
intializing function
ExternalInt();
//call External Interrupt
intializing function
default();
//call Default Condition function
while(1)
//infinite loop
{
RB3=1;
//Pin 3 of port B is made
high(5v) & Pin 2 is made low
RB2=0;
//for making left side 0v and right 5v.
x=adc();
//adc function initialized
for finding x coordinate digital
//value
if(x>90)
{
RB3=0;
//Top side is made 0v and bottom 5v
RB2=1;
y=adc();
//adc function initialized
finding y coordinate digital
//value
divide1(x);
//divide function called to find
how much movements
//to the right
divide2(y);
//divide function called to find
how much movements
//to the bottom
click();
// mouse click function
default();
// function for mouse default
position and check for

//touch
}
}
}
/
***********************************************************************/
/*Interrupt*/
/
***********************************************************************/
void interrupt ext()
{
INTF=0;
//interrupt enable
TXREG='M';
//to make the PC detect the
touchscreen as mouse
while(TRMT==0)
//check whether transmission over
{
}
}
/
***********************************************************************/
/*Default*/
/
***********************************************************************/
void default()
{
TXREG=0x43;
// move mouse to default position
while(TRMT==0);
TXREG=0x43;
while(TRMT==0);
TXREG=0x43;
while(TRMT==0);
}
/
***********************************************************************/
/*ADC*/
/
***********************************************************************/
void adc()
{
TRISA=0XFF;
//PORTA initialization ADCON1=0X80;
while(1)
{
ADCON0=0XA1;
ADGO=1;
module enable*/
while(ADGO==1)
c=ADRESH;
value*/
c=c<<8;
c=c|ADRESL;
return(c);
}}

/*for ADC controlling process*/


/*A/D convertet
/*loading MSB of ADC
/*shifting left 8 bit places */
/*OR-ing with LSB value*/
/*return value*/

/
***********************************************************************/
/*Division for x coordinate. The Adc value is first
divided by set values inorder to obtain mouse commands in Microsoft
format. */
/
***********************************************************************/
void divide1(p)
{
if(p>=400)
{
m=p%400;
// adc value divided with set value 400 and
remainder is found out
p=p/400;
//quotient is taken as p
mov1(p);
//the quotient is sent to move function
}
if(m>=180)
{
p=m;
m=p%180;
p=p/180;
mov2(p);
}
if(m>=50)
{
p=m;
m=p%50;
p=p/50;
mov3(p);
}
if(m>=10)
{p=m;
m=p%10;
p=p/10;
mov4(p);
}
}
/
***********************************************************************/
/*Division for y coordinate. The Adc value is first
divided by set values inorder to obtain mouse commands in Microsoft
format. */
/
***********************************************************************/
void divide2(q)
{
if(q>=400)
{
m=q%400;
//adc value divided with set value 400 and
remainder is found out
q=q/400;
//quotient is taken as q

mov5(q);
}
if(m>=180)
{
q=m;
m=q%180;
q=q/180;
mov6(q);
}
if(m>=50)

//the quotient is sent to move function

{
q=m;
m=q%50;
q=q/50;
mov7(q);
}
if(m>=10)
{
q=m;
m=q%10;
q=q/10;
mov8(q);
}
}
/
***********************************************************************/
/*Mouse commands in Microsoft format to move 400 pixels
to the right */
/
***********************************************************************/
void mov1(m)
{
while(m>0)
{
TXREG=0X41;
while(TRMT==0);
TXREG=0X00;
while(TRMT==0);
TXREG=0X3F;
while(TRMT==0);
m=m-1;
}
}
/
***********************************************************************/
/*Mouse commands in Microsoft format to move 180 pixels
to the right */
/
***********************************************************************/
void mov2(m)
{
while(m>0)

{
TXREG=0X40;
while(TRMT==0);
TXREG=0X00;
while(TRMT==0);
TXREG=0X3F;
while(TRMT==0);
m=m-1;
}
}
/
***********************************************************************/
/*Mouse commands in Microsoft format to move 50 pixels
to the right
*//********************************************************************
***/
void mov3(m)
{
while(m>0)
{
TXREG=0X40;
while(TRMT==0);
TXREG=0X00;
while(TRMT==0);
TXREG=0X3F;
while(TRMT==0);
m=m-1;
}
}
/
***********************************************************************/
/*Mouse commands in Microsoft format to move 10 pixels to the right
*/
/
***********************************************************************/
void mov4(m)
{
while(m>0)
{
TXREG=0X40;
while(TRMT==0);
TXREG=0X00;
while(TRMT==0);
TXREG=0X3F;
while(TRMT==0);
m=m-1;
}
/
***********************************************************************/
/*Mouse commands in Microsoft format to move 400 pixels to the bottom */

/
***********************************************************************/
void mov5(m)
{
while(m>0)
{
TXREG=0X44;
while(TRMT==0);
TXREG=0X3F;
while(TRMT==0);
TXREG=0X00;
while(TRMT==0);
m=m-1;
}
}
/
***********************************************************************/
/*Mouse commands in Microsoft format to move 180 pixels to the bottom */
/
***********************************************************************/
void mov6(m)
{
while(m>0)
{
TXREG=0X40;
while(TRMT==0);
TXREG=0X3F;
while(TRMT==0);
TXREG=0X00;
while(TRMT==0);
m=m-1;
}
}
/
***********************************************************************/
/*Mouse commands in Microsoft format to move 50 pixels to the bottom */
/
***********************************************************************/
void mov7(m)
{
while(m>0)
{
TXREG=0X40;
while(TRMT==0);
TXREG=0X17;
while(TRMT==0);
TXREG=0X00;
while(TRMT==0);
m=m-1;
}
}
/
***********************************************************************/

/*Mouse commands in Microsoft format to move 10 pixels to the bottom */


/
***********************************************************************/
void mov8(m)
{
while(m>0)
{TXREG=0x40;
while(TRMT==0);
TXREG=0x08;
while(TRMT==0);
TXREG=0X00;
while(TRMT==0);
m=m-1;
}
}
/
***********************************************************************/
/*Mouse commands in Microsoft format to click the point of touch */
/
***********************************************************************/
void click()
{
TXREG=0X6f;
while(TRMT==0);
TXREG=0X00;
while(TRMT==0);
TXREG=0X00;
while(TRMT==0);
}
/
***********************************************************************/
/*UART Transmission */
/
***********************************************************************/
void usartinit()
{
TXEN=1;
/*transmission enable*/
BRGH=0;
/*low baud rate*/
SYNC=0;
/*asynchronous mode*/
SPBRG=255;
/* Baude rate set to 1200*/
SPEN=1;
/*serial port enable*/
}
/
***********************************************************************/
/*Interrupt Initialization*/
/
***********************************************************************/
void ExternalInt()
{
PEIE=1;
//peripheral interrupt enable bit: Enabled
GIE=1;
//Global interrupt enable bit: Enabled

INTE=1;
RBPU=0;
INTEDG=1;
edge
TRISB=0X01;
}

//External Interrupt Enable bit: Enabled


//PORTB Pull up enable bit: Enabled
// Interrupt edge select: Interrupt on rising
// external interrupt set

You might also like