tan function use with mikroc....?

Status
Not open for further replies.

naya2013

Newbie level 2
Joined
Oct 19, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
62
what is the error of this mikroc program....???

int i=0; // State Counter is incremented sequentially to determine the next state of the winding energizing sequence
int t=0;
int j=0;
int k=0;
unsigned int motor1;
unsigned int motor2;
unsigned char hundred;
unsigned char tense;
unsigned char onece;
unsigned d1;
unsigned d2;
unsigned d3;
unsigned d4;
unsigned d5;
unsigned d6;

double const pi=3.14159265;
double tanval1=0.0;
double tanval2=0.0;
double distance=0.0;
double distance_1=0.0;
double var_3;
double var_4;

// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;

void decode(int var_1)
{
hundred=(var_1/100)+48;
tense=(var_1%100)/10 + 48;
onece=(var_1%10)+48;
}

void decode2(int var_2)
{
d1=(var_2/100000)+48;
d2=(var_2%100000)/10000 + 48;
d3=(var_2%10000)/1000 + 48;
d4=(var_2%1000)/100 + 48;
d5=(var_2%100)/10 + 48;
d6=(var_2%10) +48;
}
void main()
{
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_out(1,1,"SYSTEM ON");
TRISC = 0X00;
PORTC = 0X00;
TRISD = 0XFF;
motor1=0;
motor2=0;

while (1)
{
// Forward Rotation - Full Step
if(RD0_bit==0 && i==0)
{
PORTC = 0B00000111; // 0001 - Energize winding D
i = 1;
Delay_ms(1200);
motor1++;
};

if(RD0_bit==0 && i==1)
{
PORTC = 0B00001110; // 0100 - Energize winding B
Delay_ms(1200);
i = 2;
motor1++;
}
if(RD0_bit==0 && i==2)
{
PORTC = 0B00001011; // 0010 - Energize winding C
Delay_ms(1200);
i = 3;
motor1++;
}

if(RD0_bit==0 && i==3)
{
PORTC = 0B00001101; // 1000 - Energize winding A
Delay_ms(1200);
i = 0;
motor1++;
}

// Backward Rotation - Full Step
if(RD1_bit==0 && j==0)
{
PORTC = 0b00001101; // 1000 - Energize winding A
j = 1;
Delay_ms(1200);
motor1--;

};

if(RD1_bit==0 && j==1)
{
PORTC = 0b00001011; // 0010 - Energize winding C
Delay_ms(1200);
j = 2;
motor1--;
}

if(RD1_bit==0 && j==2)
{
PORTC = 0b00001110; // 0100 - Energize winding B
Delay_ms(1200);
j = 3;
motor1--;
}

if(RD1_bit==0 && j==3)
{
PORTC = 0b00000111; // 0001 - Energize winding A
Delay_ms(1200);
j = 0;
motor1--;
}

// Forward Rotation - stepper motor2
if(RD2_bit==0 && t==0)
{
PORTC = 0B01110000; // 1000 - Energize winding A
t = 1;
Delay_ms(1200);
motor2++;
};

if(RD2_bit==0 && t==1)
{
PORTC = 0b11100000; // 0101 - Energize windings B & D
Delay_ms(1200);
t = 2;
motor2++;
}

if(RD2_bit==0 && t==2)
{
PORTC = 0b10110000; // 0100 - Energize winding B
Delay_ms(1200);
t = 3;
motor2++;
}

if(RD2_bit==0 && t==3)
{
PORTC = 0b11010000; // 0110 -Energize windings B & C
Delay_ms(1200);
t = 0;
motor2++;
}
if(RD3_bit==0 && k==0)
{
k=1;
PORTC = 0b11010000;
Delay_ms(1200);
motor2--;
};
if(RD3_bit==0 && k==1)
{
PORTC = 0b11100000; // 0101 - Energize windings B & D
Delay_ms(1200);
k = 2;
motor2--;
}
if(RD3_bit==0 && k==2)
{
PORTC = 0b10110000; // 0100 - Energize winding B
Delay_ms(1200);
k = 3;
motor2--;
}
if(RD3_bit==0 && k==3)
{
PORTC = 0b11010000; // 0110 -Energize windings B & C
Delay_ms(1200);
k = 0;
motor2--;
}
if(RD4_bit==0)
{
Lcd_Cmd(_LCD_CLEAR);
decode(motor1);
Lcd_out(1,1,"ANGLE-1=");
Lcd_chr_cp(hundred);
Lcd_chr_cp(tense);
Lcd_chr_cp('.');
Lcd_chr_cp(onece);

}
if(RD5_bit==0)
{
Lcd_Cmd(_LCD_CLEAR);
decode(motor2);
Lcd_out(1,1,"ANGLE-2=");
Lcd_chr_cp(hundred);
Lcd_chr_cp(tense);
Lcd_chr_cp('.');
Lcd_chr_cp(onece);
}
if(RD6_bit==0)
{
tanval1=tan(pi*motor1/1800);
tanval2=tan(pi*motor2/1800);
distance=//(tanval1*tanval2)/(tanval1+tanval2);
distance_1=tan(pi/4)*1000;

ar_4=sin(var_3)*1000;
Lcd_Cmd(_LCD_CLEAR);
decode2(var_3);
Lcd_out(1,1,"DISTANCE ");
Lcd_out(2,1,"=");
Lcd_chr_cp(d1);
Lcd_chr_cp(d2);
Lcd_chr_cp(d3);
Lcd_chr_cp('.');
Lcd_chr_cp(d4);
Lcd_chr_cp(d5);
Lcd_chr_cp(d6);

}

}
}
 

Post code in syntax tags.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
void decode(int var_1)
{
hundred=(var_1/100)+48;
tense=(var_1/10)%10 + 48;
onece=(var_1%10)+48;
}
 
void decode2(int var_2)
{
d1=(var_2/100000)+48;
d2=(var_2/10000)%10000 + 48;
d3=(var_2/1000)%1000 + 48;
d4=(var_2/100)%100 + 48;
d5=(var_2/10)%10 + 48;
d6=(var_2%10) +48;
}
 
 
 
void main()
{
TRISB = 0x00;
PORTB = 0x00;
TRISC = 0X00;
PORTC = 0X00;
TRISD = 0XFF;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_out(1,1,"SYSTEM ON");
 
 
while(1){
 
if((RD0_bit==0) && (i==0))
 
if((RD0_bit==0) && (i==1))
 
if((RD0_bit==0) && (i==2))
 
if((RD0_bit==0) && (i==3))
 
if((RD1_bit==0) && (j==0))
 
if((RD1_bit==0) && (j==1))
 
if((RD1_bit==0) && (j==2))
 
if((RD1_bit==0) && (j==3))
 
if((RD1_bit==0) && (j==3))
 
if((RD2_bit==0) && (t==0))
 
 
if((RD2_bit==0) && (t==1))
 
 
if((RD2_bit==0) && (t==2))
 
if((RD2_bit==0) && (t==3))
 
if((RD3_bit==0) && (k==0))
 
if((RD3_bit==0) && (k==1))
 
if((RD3_bit==0) && (k==2))
 
if((RD3_bit==0) && (k==3))
 
}

 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…