我最近在一個與Arduinos合作的模塊中提供了這項任務。我們以前的任務是C語言,但是當涉及到這個時,我根本不知道該怎麼做,甚至不知道該如何開始。我們也沒有提供任何類型的講座或其他方式來解決這個問題。任何人都可以幫助或只是讓球滾動一點,這樣我就能更好地理解它?謝謝。AVR彙編語言 - 交通燈
的,我不得不修改代碼的第一位是如下:
"delay_ms%=: nop ; code to replace nop \n"
"delay_100us%=: nop ; code to replace nop \n"
"delay_1us%=: nop ; code to replace nop \n"
" sbiw r30,1 ; decrement ms count (r31:r30)\n"
" brne delay_ms%= ; loop to delay_ms while > 0 \n"
" ret ; return from subroutine \n"
,然後將代碼的其餘部分是這樣的:
" blink%=: ; start of blink code \n"
//
// turn onboard LED on
//
" ldi r18,0x20 ; bit 5 (pin 13) = high \n"
" out 5,r18 ; output to port B \n"
//
// delay by value in millisecs variable
//
" lds r30,millisecs ; r30 = hi byte \n"
" lds r31,millisecs + 1 ; r31 = lo byte \n"
" call delay_ms%= ; call millisec delay sub \n"
//
// turn onboard LED off
//
" ldi r18,0x00 ; value for all LEDs off \n"
" out 5,r18 ; output to port B \n"
//
// delay by value in millisecs variable
//
" lds r30,millisecs ; r30 = hi byte \n"
" lds r31,millisecs + 1 ; r31 = lo byte \n"
" call delay_ms%= ; call millisec delay sub \n"
::: "r16", "r17", "r18", "r30", "r31"); // clobbered registers
//------------------------------------------------------------------------- -------
// calculate the execution time of the blink routine, and print details
long endtime = millis(); // make a note of the end time
float ms = endtime-starttime; // calculate the interval
float expected = 2 * millisecs; // expected delay is millisecs * 2 (2 delays in blink)
float overheads = 17; // overheads due to the timing
expected = expected + overheads;
float error_percent = 100.0*(ms-expected)/expected;
Serial.print("delay="); Serial.print(ms); Serial.print("ms ");
Serial.print("error: ");
if(error_percent>0)
Serial.print("+");
Serial.print(error_percent);Serial.println("%");
}
的指令集是在這裏:http://www.atmel.com/images/Atmel-0856-AVR-Instruction-Set-Manual.pdf