Cần giúp giúp em sửa code bị lỗi với

ducnamtq89

Học sinh phổ thông
#1
Em có tìm được 1 mạch điện trên intenet nhưng code họ cho bị lỗi em không biên dịch ra file hex được.các bác xem giúp em xem nó bị lỗi chỗ nào với,em mù tịt về phần mềm nên ngồi cả ngày mà vẫn không tìm ra.
Nếu có thẻ thì tiện tay các bác cho em luôn file hex thì càng tốt ạ.
cảm ơn mọi người.
trang web đây ạ http://www.lamja.com/?p=284
code của nó đây
Mã:
//
// LamjaStep v1
// Copyright Arvid Mortensen
//
// Bipolar microstep enabled
// stepper motor driver with power save
// www.lamja.com
//
//This code is for use with Atmega328 under Arduino enviroment.
//
// Inputs:
// - Direction
// - Step
// - Enable
// - Step resolution bit 0-2
// - Power save
//
// Outputs:
// - DAC A bit 0-5
// - DAC B bit 0-5
//
//
//
//

int StepNumber = 0; // Step number in current table
int MS = 8; // Microstep skip in table with direction +/-
int MSNew = 8; // Microstep skip in table, new without direction +
int J1 = 0; // J1 Jumper bit (1=open, 0=short)
int J2 = 0; // J2 Jumper bit (1=open, 0=short)
int J3 = 0; // J3 Jumper bit (1=open, 0=short)
int J4 = 0; // J4 Jumper bit (1=open, 0=short)
int D = 0; // Direction Bit (0 or 1)
int Direction = 1; // Direction (-1 or 1)
int StepResolution = 0; // Stepresolution (0-7)
int t; // General counter
unsigned int PowerSaveCount = 0; // Counter for power save time out
int PS = 0; // Power Save reached(% of full power)
int PSNew = 0; // Power Save reached new reading (% of full power)
int E = 0; // Enable (1=disabled, 0=enabled)
int ENew = 0; // Enable new reading (1=disabled, 0=enabled)
unsigned char TempB = 0;
unsigned char TempC = 0;
unsigned char PhaseCurrentOriginal[641] = {32,32,33,33,34,34,34,35,35,35,36,36,37,37,37,38,38,38,39,39,40,40,40,41,41,41,42,42,42,43,43,44,44,44,45,45,45,46,46,46,47,47,47,48,48,48,49,49,49,50,50,50,50,51,51,51,52,52,52,53,53,53,53,54,54,54,54,55,55,55,55,56,56,56,56,57,57,57,57,58,58,58,58,58,59,59,59,59,59,60,60,60,60,60,60,60,61,61,61,61,61,61,61,62,62,62,62,62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63,62,62,62,62,62,62,62,62,62,62,62,61,61,61,61,61,61,61,60,60,60,60,60,60,60,59,59,59,59,59,58,58,58,58,58,57,57,57,57,56,56,56,56,55,55,55,55,54,54,54,54,53,53,53,53,52,52,52,51,51,51,50,50,50,50,49,49,49,48,48,48,47,47,47,46,46,46,45,45,45,44,44,44,43,43,42,42,42,41,41,41,40,40,40,39,39,38,38,38,37,37,37,36,36,35,35,35,34,34,34,33,33,32,32,32,31,31,30,30,30,29,29,29,28,28,27,27,27,26,26,26,25,25,24,24,24,23,23,23,22,22,22,21,21,20,20,20,19,19,19,18,18,18,17,17,17,16,16,16,15,15,15,14,14,14,14,13,13,13,12,12,12,11,11,11,11,10,10,10,10,9,9,9,9,8,8,8,8,7,7,7,7,6,6,6,6,6,5,5,5,5,5,4,4,4,4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,13,13,13,14,14,14,14,15,15,15,16,16,16,17,17,17,18,18,18,19,19,19,20,20,20,21,21,22,22,22,23,23,23,24,24,24,25,25,26,26,26,27,27,27,28,28,29,29,29,30,30,30,31,31,32,32,32,33,33,34,34,34,35,35,35,36,36,37,37,37,38,38,38,39,39,40,40,40,41,41,41,42,42,42,43,43,44,44,44,45,45,45,46,46,46,47,47,47,48,48,48,49,49,49,50,50,50,50,51,51,51,52,52,52,53,53,53,53,54,54,54,54,55,55,55,55,56,56,56,56,57,57,57,57,58,58,58,58,58,59,59,59,59,59,60,60,60,60,60,60,60,61,61,61,61,61,61,61,62,62,62,62,62,62,62,62,62,62,62,63,63,63,63,63,63,63,63,63,63,63,63,63,63,63}; // SIN Phase current levels for microstepping. Zero = 32, min = 1, max = 63
unsigned char PhaseCurrentCopy[641];


 
void setup()
{
DDRB = 63; //Bit 0-5 as ouput on B and C
DDRC = 63;

EICRA=3; //External interrupt INT0
EIMSK=1;

PCICR = 4; //External interrupt PCINT2
PCMSK2 = 8;

pinMode(5, INPUT); // J1 (Step resolution)
pinMode(6, INPUT); // J2 (Step resolution)
pinMode(7, INPUT); // J3 (Step resolution)
pinMode(0, INPUT); // J4 = Power Save
pinMode(4, INPUT); // Enable

for(t=0;t<641;t++) // Copy phase current table { PhaseCurrentCopy[t] = PhaseCurrentOriginal[t]; } D = digitalRead(3); //Read direction pin if(D == 1) { Direction = 1; } else { Direction = -1; } MS = MSNew*Direction; } void loop() { J1 = digitalRead(5); // Read pin Step resolution bit 2 J2 = digitalRead(6); // Read pin Step resolution bit 1 J3 = digitalRead(7); // Read pin Step resolution bit 0 J4 = digitalRead(0); // Read pin Power Save ENew = digitalRead(4); // Read pin Enable StepResolution = J1*4 + J2*2 + J3; // Calculate step resolution setting if(StepResolution == 0)MSNew = 1; // 1/128 Microstepping (less accurate) if(StepResolution == 1)MSNew = 2; // 1/64 Microstepping (almost accurate) if(StepResolution == 2)MSNew = 4; // 1/32 Microstepping (should be accurate) if(StepResolution == 3)MSNew = 8; // 1/16 Microstepping (should be accurate) if(StepResolution == 4)MSNew = 16; // 1/8 Microstepping (should be accurate) if(StepResolution == 5)MSNew = 32; // 1/4 Microstepping (should be accurate) if(StepResolution == 6)MSNew = 64; // 1/2 Microstepping (should be accurate) if(StepResolution == 7)MSNew = 128; // 1/1 Microstepping (should be accurate) if(MSNew != abs(MS)) // Step resolution has changed. Reset to step position 0 and activate step resolution. { StepNumber = 0; MS = MSNew*Direction; } PowerSaveCount++; // Hold track of power save feature PSNew = 100; // Power save time limit not reached, as default if(PowerSaveCount > 30000)
{
PSNew = 90; // Power save time limit reached
}
if(PowerSaveCount > 35000)
{
PSNew = 80; // Power save time limit reached
}
if(PowerSaveCount > 40000)
{
PSNew = 70; // Power save time limit reached
}
if(PowerSaveCount > 45000)
{
PSNew = 60; // Power save time limit reached
}
if(PowerSaveCount > 50000)
{
PSNew = 50; // Power save time limit reached
}
if(PowerSaveCount > 55000)
{
PSNew = 40; // Power save time limit reached
PowerSaveCount--; // Stay at 55000
}

if(PSNew != PS) // Change in power save from old reading
{
if((PSNew != 100) and (J4 == 0)) // New power save mode is on
{
cli();
TempB = (((int)PhaseCurrentCopy[StepNumber]-32)*PSNew)/100+32;
TempC = (((int)PhaseCurrentCopy[StepNumber+128]-32)*PSNew)/100+32;
PORTB = TempB;
PORTC = TempC;
sei();
}
PS = PSNew; //Store new power save setting
}

if(ENew != E) //Enable has changed
{
if(ENew == 1) // Enable is set. Turn on power
{
for(t=0;t<641;t++) { PhaseCurrentCopy[t] = PhaseCurrentOriginal[t]; } } if(ENew == 0) // Enable is not set. Turn off power. { for(t=0;t<641;t++) { PhaseCurrentCopy[t] = 32; } } E = ENew; // Store new enable setting } } ISR(INT0_vect) // Step rising edge interrupt { cli(); PowerSaveCount = 0; StepNumber += MS; StepNumber &= 511; //if StepNumber >= 512, then StepNumber = Stepnumber - 512. If StepNumber <= 0, then StepNumber = StepNumber + 512. //if(StepNumber > 511)
//{
// StepNumber = 0;
//}
//if(StepNumber < 0) //{ // StepNumber = 511; //} PORTB = PhaseCurrentCopy[StepNumber]; PORTC = PhaseCurrentCopy[StepNumber+128]; } ISR(PCINT2_vect) //Direction change interrupt { cli(); D = digitalRead(3); //if((PORTD & 8 ) != 0) // digitalRead(3); if(D) // digitalRead(3); { Direction = 1; } else { Direction = -1; } MS = MSNew*Direction; }
 

Quảng cáo Google