大家好!!我用PICC编写了一个很简单的程序如下:
/*************************************
晶振:外部4M
单片机:PIC16F877A
功能:利用PORTC端口实现循环流水灯
**************************************/
#include<pic.h>
#define uint unsigned int
#define uchar unsigned char
void delay_ms(uint time)//大约延时1ms
{
uint j;
for(;time>0;time--)
for(j=109;j>0;j--)
{;}
}
void main(void)
{
uchar loop;
TRISC=0x00;//设置为输出
while(1)
{
PORTC=0xfe;//先将端口赋值0xfe
delay_ms(300);
for(loop=0;loop<8;loop++)
{
PORTC<<=1;//读端口左移再赋值给PC端口
delay_ms(300);//延时300ms
}
}
}
PICC编绎之后所生成的代码可以正常地运行,但是用烧写器打开之后如下图所示!
(原文件名:编绎出来之后的代码分配情况.JPG)
第一部分从0x00~0x07,第二部分从0x7CE~0x7FF。为什么编绎器所生成的代码不是从0x00开始一直依次排列下去的!而是分成两部分排列!我试过编写超过7K的程序源码!PICC编绎器所生成的代码还分成三部分!是不是我的程序在编写时就出现了问题啊??但是编绎器却没有提示错误或警告!请大家指点!如何解决这个问题!谢谢 ?
?
#include<pic.h>
应该有空格符将关键字分开。
理论上,此处最好使用:
typedef unsigned int uint;
typedef unsigned char uchar;
而不是:
#define uint unsigned int
#define uchar unsigned char
PICC连接重定位的算法是尾部地址对齐,即代码从一个页的末端地址开始向前分配。个人认为,这种做法没有什么意义。
以下是我的山寨编译器产生的结果:
[CODE]:
0004: delay_ms CODE2 chinese.obj
001E: main CODE2 chinese.obj
003A: _$init$ CODEi chinese.obj
[SYSTEM]:
0020: delay_ms_$data$ (4)
0024: main_$data$ (1)
0025: _$
007F: _$$
007E: _$heap$
007D: _$acc0$
007C: _$acc1$
007B: _$acc2$
007A: _$acc3$
* * * * * * * * * * * * * DATA SHARING MAP * * * * * * * * * * * * *
SHARING GROUP #1:
delay_ms (BANK0: 4)
_$init$ (BANK0: 0)
SHARING GROUP #2:
main (BANK0: 1)
* * * * * * * * * * * * * DATA MEMORY MAP * * * * * * * * * * * * *
000: ---------------- ---------------- XXXXX........... ................
040: ................ ................ ................ ................
080: ---------------- ---------------- ................ ................
0C0: ................ ................ ................ ----------------
100: ---------------- ................ ................ ................
140: ................ ................ ................ ----------------
180: ---------------- ................ ................ ................
1C0: ................ ................ ................ ----------------
* * * * * * * * * * * * * CODE MEMORY MAP * * * * * * * * * * * * *
0000: 0000 nop
0001: 3000 movlw 0x00
0002: 008A movwf PCLATH
0003: 281E goto 0x01e
; ::: 'chinese.c' #9: void delay_ms(uint time)
delay_ms::
L2:
; ::: 'chinese.c' #12: time>0;
0004: 0183 clrf STATUS
0005: 0820 movf 0x20, W
0006: 0421 iorwf 0x21, W
0007: 1903 btfsc STATUS, 2
0008: 281C goto 0x01c
; ::: 'chinese.c' #13: for(j=109;
0009: 306D movlw 0x6d
000A: 00A2 movwf 0x22
000B: 01A3 clrf 0x23
L5:
; ::: 'chinese.c' #13: j>0;
000C: 0183 clrf STATUS
000D: 0822 movf 0x22, W
000E: 0423 iorwf 0x23, W
000F: 1903 btfsc STATUS, 2
0010: 2816 goto 0x016
; ::: 'chinese.c' #13: j--)
0011: 30FF movlw 0xff
0012: 07A2 addwf 0x22, F
0013: 1C03 btfss STATUS, 0
0014: 03A3 decf 0x23, F
0015: 280C goto 0x00c
L6:
; ::: 'chinese.c' #12: time--)
0016: 0183 clrf STATUS
0017: 30FF movlw 0xff
0018: 07A0 addwf 0x20, F
0019: 1C03 btfss STATUS, 0
001A: 03A1 decf 0x21, F
001B: 2804 goto 0x004
L3:
001C: 0183 clrf STATUS
001D: 0008 return
; ::: 'chinese.c' #16: void main(void)
main::
001E: 203A call 0x03a
; ::: 'chinese.c' #19: TRISC=0x00;
001F: 1683 bsf STATUS, 5
0020: 0187 clrf 0x7
L9:
; ::: 'chinese.c' #20: while(1) ; ::: 'chinese.c' #22: PORTC=0xfe;
0021: 30FE movlw 0xfe
0022: 0183 clrf STATUS
0023: 0087 movwf 0x7
; ::: 'chinese.c' #23: delay_ms(300);
0024: 302C movlw 0x2c
0025: 00A0 movwf 0x20
0026: 3001 movlw 0x01
0027: 00A1 movwf 0x21
0028: 2004 call 0x004
; ::: 'chinese.c' #24: for(loop=0;
0029: 01A4 clrf 0x24
L12:
; ::: 'chinese.c' #24: loop<8;
002A: 0183 clrf STATUS
002B: 0824 movf 0x24, W
002C: 3C08 sublw 0x08
002D: 1D03 btfss STATUS, 2
002E: 1C03 btfss STATUS, 0
002F: 2839 goto 0x039
; ::: 'chinese.c' #26: PORTC<<=1;
0030: 0D87 rlf 0x7, F
0031: 1007 bcf 0x7, 0
; ::: 'chinese.c' #27: delay_ms(300);
0032: 302C movlw 0x2c
0033: 00A0 movwf 0x20
0034: 3001 movlw 0x01
0035: 00A1 movwf 0x21
0036: 2004 call 0x004
; ::: 'chinese.c' #24: loop++)
0037: 0AA4 incf 0x24, F
0038: 282A goto 0x02a
L13:
0039: 2821 goto 0x021
_$init$::
003A: 3025 movlw 0x25
003B: 00FE movwf 0x7e
003C: 0183 clrf STATUS
003D: 0008 return
* * * * * * * * * * * * CALLING CHAIN * * * * * * * * * * * *
[main] ........ delay_ms (calling depth: 1)
[main] ........ _$init$ (calling depth: 1)
一周热门 更多>