elmayadunna
Banned
- Joined
- Oct 14, 2013
- Messages
- 10
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 0
i don't know find errors and complete this program. plz help me.
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 int k=0; unsigned int motor1; unsigned int motor2; unsigned char hundred; unsigned char tense; unsigned char onece; const float x=0.1; float a; float b; float m; float n; float u; float v; int res; a=sinu; b=cosu; m=sinv; n=cosv; // 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; float d; char txt[10]; void decode(int var_1) { hundred=(var_1/100)+48; tense=(var_1%100)/10 + 48; onece=(var_1%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) { u = x*motor1; v = x*motor2; d=(a*m)/((b*m)+(a*n)); Lcd_Cmd(_LCD_CLEAR); floattostr(d,txt); lcd_out(2,1,txt); } } }
Last edited by a moderator: