picpicpikapika WROTE:So, the normal battery is not applicable to servo is it?? Thanks.
#include<pic.h>
__CONFIG ( 0x3F32 );
unsigned char b=0;
unsigned char tssdisplay[3];
unsigned char high=0;
unsigned char total=250;
unsigned char COUNT0=0;
unsigned char COUNT1=0;
unsigned long int i;
void tsselection(void);
void interrupt isr()
{
if(T0IE==1&&T0IF==1)
{
COUNT0++;
COUNT1++;
if(COUNT0>=total)
{
COUNT0=0;
COUNT1=0;
RB1=0;
}
if(COUNT1==high)
{
RB1=1;
}
TMR0 =156;
T0IF =0;
}
}
void main(void)
{
TRISA = 0x00;
TRISB = 0xC0;
TRISC = 0x00;
PORTA = 0x00;
PORTC = 0x00;
RB0=0;
RB1=0;
GIE = 1;
PEIE = 1;
T0IE = 1;
OPTION = 0x01;
TMR0 = 156;
high = total-29; //initialize, make the motor turn all the way down to 0 degree.
for(i=0;i<100000;i++){
}
high = total;
for(;;)
{
if(!RB7)
{
while(!RB7){
}
for(i=0;i<55000;i++){
}
if(b<36)
{
b++; //for displaying seven segments
high = total-6; //turning clockwise for a certain degree
}
high = total;
}
RB0=1; //buzzer
for(i=0;i<10000;i++){
}
RB0=0;
}
if(!RB6)
{
while(!RB6){
}
for(i=0;i<55000;i++){
}
if(b>0)
{
b--; //for displaying seven segments
high = total-29; //turning counter clockwise for a certain degree
for(i=0;i<5000;i++){
}
high = total;
}
RB0=1; //buzzer
for(i=0;i<10000;i++){
}
RB0=0;
}
tsselection(); //for displaying seven segments
}
}
static void interrupt isr(void)
{
if(TMR0IF==1){
TMR0IF=0;
counter++;
if(counter==position) SERVO=0;
if(counter==390){
counter=0;
SERVO=1;}
}
}
for(position=10;position<=50;position++){
for(i=0;i<speed;i++) __delay_ms(1);}
Users browsing this forum: No registered users and 21 guests