#pragma CODE_SEG __NEAR_SEG NON_BANKED/#pragma CODE_SEG DEFAULT

简介:   在写到SCI 中断发送,中断接收程序的时候,在程序中会出现#pragma CODE_SEG __NEAR_SEG NON_BANKED/#pragma CODE_SEG DEFAULT,这两句话在程序中具体的代码如下: 1 /****************************...

  在写到SCI 中断发送,中断接收程序的时候,在程序中会出现#pragma CODE_SEG __NEAR_SEG NON_BANKED/#pragma CODE_SEG DEFAULT,这两句话在程序中具体的代码如下:

 1 /*************************************************/
 2 /*               串口中端接受函数                */
 3 /*************************************************/
 4 #pragma CODE_SEG __NEAR_SEG NON_BANKED     //将接下来的代码(一般是中断函数)置于非分页区
 5 interrupt void recievedata(void) {
 6   data_recieve = SCI_recieve();
 7   if(data_recieve == 'O') {
 8     SCI_send('Y');
 9     LEDCPU = LED_ON;
10   }
11   if(data_recieve == 'C') {
12     LEDCPU = LED_OFF;
13   }
14 }
15 #pragma CODE_SEG DEFAULT
Interrupt_recieve

  总的来说这两句话是这样的意思:

#pragma CODE_SEG __NEAR_SEG  NON_BANKED //中断函数置于非分页区内代码段
#pragma CODE_SEG DEFAULT //后续代码置于默认区域内

  freescale16位的板子中断向量位是16位,中断函数只有被置于非分页区内才能被寻址到,这就是第一行的作用。由于单片机内部非分页区大小有限,非中断函数一般置于分页区内,最后一行即为此作用。

  这里要从FLASH分页和非分页的区别说起, FLASH里非分页工作机制如下:
  FLASH一共为128K,一页是16K,那么应该有8页才是,但是实际只有6个分页。有2个非分页放在4000-7FFF,和C000-FFFF两个逻辑地址窗里。那么,当程序的寻址在64K之内(2^16=64K,16位机的寻址能力是64K)时,就不用分页了,直接使用那两个非分页的数据。实际上,3E页 3F页是可见的,其实他们就是那2个非分页的映射。因此,使用非分页FLASH,就不须设置PPAGE寄存器,直接使用逻辑地址即可。

  这点我们可以从以下看出:

/* non-paged FLASHs */
      ROM_4000      = READ_ONLY     0x4000 TO   0x7FFF;
      ROM_C000      = READ_ONLY     0xC000 TO   0xFEFF;
PLACEMENT
      NON_BANKED,    INTO ROM_C000/*, ROM_4000*/;

 

  NON_BANKED一般位于0xc000-0xffff区域,而这个区域是16位单片机cpu可以直接寻址的区域,那么中断函数放在 NON_BANKED里,就可以把函数放在64K的寻址程序段中。这么一来,进中断就方便多了,效率也高很多(因为中断函数要求的就是实时性)...而 __NEAR_SEG告诉编译器函数放在固定页中,只有固定页中的函数才能访问其他页的数据,同时CODE_SEG定义了一个代码段.

相关文章
|
JavaScript
Invalid char (/) found at index (10) in sheet name异常原因|导出excel出现Invalid char (/) found at index (10)
Invalid char (/) found at index (10) in sheet name异常原因|导出excel出现Invalid char (/) found at index (10)
|
XML 数据格式
XML问题: The processing instruction target matching "[xX][mM][lL]" is not allowed
XML问题: The processing instruction target matching "[xX][mM][lL]" is not allowed
207 0
|
编译器
relocation value does not fit in 26 bits (offset: 0x10, type: 1)
relocation value does not fit in 26 bits (offset: 0x10, type: 1)
206 0
relocation R_X86_64_PC32 against symbol can not be used when making a shared object recompile with
relocation R_X86_64_PC32 against symbol can not be used when making a shared object recompile with
705 0
libgsm.a relocation R_X86_64_PC32 can not be used when making a shared object; recompile with -fPIC
libgsm.a relocation R_X86_64_PC32 can not be used when making a shared object; recompile with -fPIC
239 0
relocation R_X86_64_PC32 against symbol ff_pw_9 can not be used when making a shared object
relocation R_X86_64_PC32 against symbol ff_pw_9 can not be used when making a shared object
289 0
relocation R_X86_64_PC32 against symbol lua_newstate can not be used when making a shared object
relocation R_X86_64_PC32 against symbol lua_newstate can not be used when making a shared object
278 0
TestRange.cs error CS0104: `Range' is an ambiguous reference between `System.Range' and Gtk.Range
TestRange.cs error CS0104: `Range' is an ambiguous reference between `System.Range' and Gtk.Range
183 0
|
编译器
warning C4995: strcat name was marked as #pragma deprecated
warning C4995: strcat name was marked as #pragma deprecated
100 0
成功解决absl.flags._exceptions.IllegalFlagValueError: flag --train_size=inf: Expect argument to be a str
成功解决absl.flags._exceptions.IllegalFlagValueError: flag --train_size=inf: Expect argument to be a str