我最近在一个与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