我刚开始学习32位单片机的编程,mc68376.结果程序不能调用子程序,把子程序的代码写在main()函数里就可以执行.比如我想调用延时子程序:delay()
void delay(void);
void main(void) { //系统初始化开始,初始化CPU,外部rom,ram,片选 asm(" ORI.W #$2700,SR"); asm(" MOVEA.L #$111e00,A7"); SIMCR=0x60CF;
SYNCR=0x7F00; SYPCR=0xD0; CSBARBT=0x0003; CSBAR0=0x1003; CSBAR1=0x1003; CSPAR0=0x00FF; CSPAR1=0x0000; CSORBT=0x68B0; CSOR0=0x3830; CSOR1=0x5830;  ICR=0x0446; PITR=0x0052; PEPAR=0x00; DDRE=0x1F; PORTE0=0x00;  FPAR=0x00; DDRF=0x00; PORTF0=0x00; RAMBAH=0x0011; RAMBAL=0x0000; RAMMCR=0x0A00;//系统初始化结束
delay();//调用子程序,想在这里延时
while(1){
//依次点亮led
PORTC=0x70;  ORTE0=0x00; for(i=0;i<50000;i++) asm(" NOP ");  ORTC=0x68; for(i=0;i<50000;i++) asm(" NOP ");  ORTC=0x58; for(i=0;i<50000;i++) asm(" NOP "); PORTC=0x38; for(i=0;i<50000;i++) asm(" NOP ");
}
}
void delay(void) {
asm(" NOP ");
}
在程序里只要调用delay()函数时程序就不向下执行,停在这个地方.搞不明白这是什么原因?
编译后生成的汇编文件:
_main: ?file ./reg.h ?endf ?file ./vec.h ?endf ?file C:\MGC\embedded\include\mcc68k/stdlib.h ?endf ?file C:\MGC\embedded\include\mcc68k/stddef.h ?endf ?file C:\MGC\embedded\include\mcc68k/string.h ?endf ?file C:\MGC\embedded\include\mcc68k/float.h ?endf ORI.W #$2700,SR
MOVEA.L #$111e00,A7
move.w #24783,16775680 move.w #32512,16775684 clr.b 16775713 move.w #3,16775752 move.w #4099,16775756 move.w #4099,16775760 move.w #255,16775748 clr.w 16775750 move.w #26800,16775754 move.w #14384,16775758 move.w #22576,16775762 clr.b 16775745 move.w #1094,16775714 move.w #82,16775716 clr.b 16775703 move.b #255,16775701 clr.b 16775697 clr.b 16775711 clr.b 16775709 clr.b 16775705
move.w #17,16776004 clr.w 16776006
move.w #2560,16776000 move.w #37824,16775200
move.w #32899,16773632 move.w #32899,16776192 move.w #39680,16774144 move.w #32899,16776704 move.w #33024,16775936 move.w #55680,16773248
jsr _delay
L1: move.b #112,16775745
clr.l _i bra.w L5
L4: NOP
addq.l #1,_i L5: cmpi.l #50000,_i bcs.s L4
move.b #104,16775745 clr.l _i bra.w L9 L8: NOP
addq.l #1,_i
L9: cmpi.l #50000,_i bcs.s L8
move.b #88,16775745
clr.l _i bra.w L13
L12: NOP
addq.l #1,_i
L13: cmpi.l #50000,_i bcs.s L12
move.b #56,16775745 clr.l _i bra.w L17
L16: NOP
addq.l #1,_i L17: cmpi.l #50000,_i bcs.s L16 bra.w L1
rts ; code: 378 + asm() bytes stack: 0 bytes ?end
_delay:
NOP
rts ; code: 2 + asm() bytes stack: 0 bytes ?end
编译器是mentor graphics的编译器.汇编程序只是原文件的一部分,从汇编程序看,好像也是正确,可就是运行的时候,运行到子程序时就停止.
求大侠指教.
[此贴子已经被作者于2005-12-30 16:00:52编辑过] |