Professional Documents
Culture Documents
Servo, Wheels Program
Servo, Wheels Program
h>
#include <stdio.h>
#include <sio.h>
#define timer0_PRES 0x00
#define timer0_RELD 0x01CC
#define timer0_MODE 0x01
unsigned
unsigned
m2_pos =
m3_pos =
m4_pos =
m5_pos =
int t0;
int m1_pos = 60,
60,
60,
60,
60;
void isr_TIMER0(void)
{
t0++;
if(t0>m1_pos)
PAOUT&=~0x01;
if(t0>m2_pos)
PAOUT&=~0x02;
if(t0>m3_pos)
PAOUT&=~0x04;
if(t0>m4_pos)
PAOUT&=~0x08;
if(t0>m5_pos)
PAOUT&=~0x10;
if(t0>1000)
{
t0=0;
PAOUT |= 0xFF;
}
}
void init_TIMER0(void)
{
T0CTL1 = (timer0_PRES << 3)|timer0_MODE;
T0H = 0x00; T0L = 0x01;
T0RH = (timer0_RELD >> 8);
T0RL = (timer0_RELD & ~0xFF00);
DI();
SET_VECTOR(TIMER0,isr_TIMER0);
IRQ0ENH |= 0x20;
ity medium
IRQ0ENL &= ~0x20;
IRQ0 &= ~0x20;
interrupt
T0CTL1 |= 0x80;
EI();
}
void init_port(void)
{
PADD=0x00;
PAAF=0x00;
PAOC=0x00;
PAHDE=0xFF;
PBDD=0x00;
PBAF=0x00;
PBOC=0x00;
PBHDE=0xFF;
}
// default
T0CTL1&=~0x80;
rx='\0';
}
else if(rx=='l')
{
move(1,90);
T0CTL1 |= 0x80;
delay_ms(300);
T0CTL1&=~0x80;
rx='\0';
}
else if(rx=='y')
{
move(2,18);
T0CTL1 |= 0x80;
delay_ms(300);
T0CTL1&=~0x80;
rx='\0';
}
else if(rx=='u')
{
move(2,36);
T0CTL1 |= 0x80;
delay_ms(300);
T0CTL1&=~0x80;
rx='\0';
}
else if(rx=='i')
{
move(2,52);
T0CTL1 |= 0x80;
delay_ms(300);
T0CTL1&=~0x80;
rx='\0';
}
else if(rx=='o')
{
move(2,72);
T0CTL1 |= 0x80;
delay_ms(300);
T0CTL1&=~0x80;
rx='\0';
}
else if(rx=='p')
{
move(2,90);
T0CTL1 |= 0x80;
delay_ms(300);
T0CTL1&=~0x80;
rx='\0';
}
else if(rx=='y')
{
move(3,18);
T0CTL1 |= 0x80;
delay_ms(300);
T0CTL1&=~0x80;
rx='\0';
}
else if(rx=='u')
{
move(3,36);
T0CTL1 |= 0x80;
delay_ms(300);
T0CTL1&=~0x80;
rx='\0';
}
else if(rx=='i')
{
move(3,52);
T0CTL1 |= 0x80;
delay_ms(300);
T0CTL1&=~0x80;
rx='\0';
}
else if(rx=='o')
{
move(3,72);
T0CTL1 |= 0x80;
delay_ms(300);
T0CTL1&=~0x80;
rx='\0';
}
else if(rx=='p')
{
move(3,90);
T0CTL1 |= 0x80;
delay_ms(300);
T0CTL1&=~0x80;
rx='\0';
}
//******************WHEELS****************************
else if(rx=='w')
//forward
{
PBOUT=~0x05;
//printf("Forward %c for w\n",DATA);
}
else if(rx=='s')
// backward
{
PBOUT=~0x0A;
//printf("Backward %c for s\n",DATA);
}
else if(rx=='d')
//right
{
PBOUT=~0x01;
//printf("Right %c for d\n",DATA);
}
else if(rx=='a')
// left
{
PBOUT=~0x04;
//printf("Left %c for a\n",DATA);
}
else if(rx=='x')
// left
{
PBOUT=~0x00;
//printf("Stop %c for x\n",DATA);
}
//******************WHEELS****************************
while(rx=='\0');
}
}