Serial Mouse Program
-
Upload
jyothis-thaliath -
Category
Documents
-
view
228 -
download
0
Transcript of Serial Mouse Program
-
8/2/2019 Serial Mouse Program
1/8
SERIAL MOUSE PROGRAM
#include //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
//valuedivide1(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
-
8/2/2019 Serial Mouse Program
2/8
//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; /*for ADC controlling process*/
ADGO=1; /*A/D convertet
module enable*/
while(ADGO==1)c=ADRESH; /*loading MSB of ADC
value*/
c=c
-
8/2/2019 Serial Mouse Program
3/8
/
***********************************************************************/
/*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
-
8/2/2019 Serial Mouse Program
4/8
mov5(q); //the quotient is sent to move function
}
if(m>=180)
{
q=m;
m=q%180;
q=q/180;
mov6(q);
}
if(m>=50)
{
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 pixelsto the right */
/
***********************************************************************/
void mov2(m)
{
while(m>0)
-
8/2/2019 Serial Mouse Program
5/8
{
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 */
-
8/2/2019 Serial Mouse Program
6/8
/
***********************************************************************/
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;
}
}
/
***********************************************************************/
-
8/2/2019 Serial Mouse Program
7/8
/*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
-
8/2/2019 Serial Mouse Program
8/8
INTE=1; //External Interrupt Enable bit: Enabled
RBPU=0; //PORTB Pull up enable bit: Enabled
INTEDG=1; // Interrupt edge select: Interrupt on rising
edge
TRISB=0X01; // external interrupt set
}