Ada编译器选择不正确的重载函数

时间:2014-12-30 20:03:25

标签: ada gnat

我正在使用avr-ada来编译我的程序。我想右移unsigned_16变量两次。 Interfaces.Shift_Right已超载,并提供Unsigned_8Unisgned_16

当我编译时,我收到错误'expected type“Interfaces.Unsigned_8”','found type“Interfaces.Unsigned_16”'。我试图指定输入是Unsigned_16,但它不起作用。如何指定正确的功能?

with AVR;                          use AVR;
with AVR.MCU;
with AVR.Timer0;
with AVR.ADC;
with Interfaces;
use Interfaces;
procedure Flash_Led is

   adc_result_10 : Unsigned_16 := 0;
   adc_result_8 : Unsigned_8 := 0;

begin
   -- set OC0A pin as output, required for output toggling
   MCU.DDRD_Bits := (others => DD_Output);
   -- set all pins low
   MCU.PortD := 16#00#;

   -- clear register
   MCU.TCCR0B := 16#00#;

   --  initialize timer to Clear Timer on Compare, scale the input
   --  clock and set a value to compare the timer against.
   Timer0.Init_CTC (Timer0.Scale_By_1024, Overflow => 1);

   --  Toggle the OC0(A)-Pin on compare match
   Timer0.Set_Output_Compare_Mode_Toggle;

   -- Initialize ADC
   ADC.Init(ADC.Scale_By_64, Ref => ADC.Is_Vcc);


   loop   -- loop forever
      adc_result_10 := ADC.Convert_10bit(Ch => 0);
      adc_result_10 := Shift_Right(Unsigned_16'(adc_result_10), 2); --'
      adc_result_8 := Unsigned_8(adc_result_10);
      Timer0.Set_Overflow_At(adc_result_10);
   end loop;
end Flash_Led;

2 个答案:

答案 0 :(得分:0)

该行:

Timer0.Set_Overflow_At(adc_result_10);

应该是:

Timer0.Set_Overflow_At(adc_result_8);

我没有仔细查看错误消息中的行号。糟糕。

答案 1 :(得分:0)

如果您不确定调用哪个函数(假设它已经过载),您可以通过重命名来构建唯一的名称...

function My16_Shift_Right (Item : in Unsigned_16; Amount : Natural) return Unsigned_16 
    renames Interfaces.Shift_Right;

然后测试您对计划的看法。