打印

C51嵌入汇编的问题

[复制链接]
10150|21
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
沙发
ayb_ice| | 2011-9-8 10:29 | 只看该作者
可能你的汇编有问题

使用特权

评论回复
板凳
chen3bing|  楼主 | 2011-9-8 11:16 | 只看该作者
C程序中.h文件
#define SetBit(sfr,bit) (sfr|=(1<<bit))
#define ClrBit(sfr,bit) (sfr&=~(1<<bit))
#define SetM7_BUSWR() SetBit(P1,2)
#define ClrM7_BUSWR() ClrBit(P1,2)
.C文件
ClrM7_BUSWR();
SetM7_BUSWR();
我嵌入的汇编
#pragma asm
  CLR  P1.2
  SETB P1.2
  #pragma endasm
有问题吗?

使用特权

评论回复
地板
alicedodo| | 2011-9-8 11:25 | 只看该作者
LZ先看看你编译时有没有警告
有的话坚决消灭掉

使用特权

评论回复
5
chen3bing|  楼主 | 2011-9-8 13:18 | 只看该作者
编译时有30多个警告,不知道怎么去掉。还有嵌入汇编前后工程窗口不一样

TARGET.jpg (31.71 KB )

TARGET.jpg

TARGET1.jpg (20.73 KB )

TARGET1.jpg

使用特权

评论回复
6
chen3bing|  楼主 | 2011-9-8 13:29 | 只看该作者
有32个警告。Build target 'Target 1'
compiling M7_B2.C...
assembling M7_B2.src...
assembling extern.A51...
linking...
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  _SPRINTF
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?_SPRINTF?BYTE
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?IMUL
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CLDPTR
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CSTPTR
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CLDOPTR
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C_STARTUP
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?FCASTL
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?FPMUL
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?LSTXDATA
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?FCASTI
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?FPDIV
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?FPADD
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?SLCMP
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?IMUL
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4CFBH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDPTR
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4D58H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDPTR
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4D96H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CSTPTR
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4D9BH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?IMUL
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4F33H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDOPTR
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4F5DH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?FCASTL
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 48BFH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?FPMUL
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 48CAH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?LSTXDATA
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 48D0H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?FCASTI
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 48DCH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?FPMUL
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 48E6H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?FPDIV
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4906H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?FPADD
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4911H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?_SPRINTF?BYTE
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4914H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?LSTXDATA
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4923H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  _SPRINTF
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 492CH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?SLCMP
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4C40H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?SLCMP
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 4C70H
Program Size: data=16.0 xdata=74 code=20719
creating hex file from "M7_2"...
"M7_2" - 0 Error(s), 32 Warning(s).

使用特权

评论回复
7
chen3bing|  楼主 | 2011-9-8 13:41 | 只看该作者
这些警告都源于嵌入汇编,感觉C51嵌入汇编不好用。

使用特权

评论回复
8
ayb_ice| | 2011-9-8 15:16 | 只看该作者
本帖最后由 ayb_ice 于 2011-9-8 15:28 编辑

如图设置即可

未命名.JPG (114.59 KB )

未命名.JPG

使用特权

评论回复
9
chen3bing|  楼主 | 2011-9-8 15:23 | 只看该作者
不行啊!生不成目标文件。
Build target 'Target 1'
compiling M7_B2.C...
Target has no object modules
Target not created

使用特权

评论回复
10
chen3bing|  楼主 | 2011-9-8 15:26 | 只看该作者
好了。刚才我把STARTUP.A51删掉了。

使用特权

评论回复
11
chen3bing|  楼主 | 2011-9-8 15:27 | 只看该作者
谢谢8楼!

使用特权

评论回复
12
chen3bing|  楼主 | 2011-9-8 17:09 | 只看该作者
坏了,又不行了。我怀疑刚才是不是真的好了,看错也有可能。

使用特权

评论回复
13
alicedodo| | 2011-9-8 18:31 | 只看该作者
本帖最后由 alicedodo 于 2011-9-8 18:34 编辑

9# chen3bing
LZ你在6楼贴出的警告都是提示C51编译器自带的库函数无法找到,不嵌入汇编时,编译器会将相应的库文件自动添加进来,但是使用了嵌入汇编以后就需要手动添加。

这是keil帮助文档中的库列表。

Library File Description
C51S.LIB Small model library without floating-point arithmetic.
C51FPS.LIB Small model floating-point arithmetic library.
C51C.LIB Compact model library without floating-point arithmetic.
C51FPC.LIB Compact model floating-point arithmetic library.
C51L.LIB Large model library without floating-point arithmetic.
C51FPL.LIB Large model floating-point arithmetic library.
80C751.LIB Library for the Philips 750/751/752 derivatives.



根据你设定的编译模式下选择对应的库文件到你的工程中来。
库文件的路径:..\keil\c51\lib
我看到你的警告中有
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?FPMUL
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 48CAH

所以要添加的是浮点库。

PS: 还是把STARTUP.A51填上吧,保险

使用特权

评论回复
14
chen3bing|  楼主 | 2011-9-8 18:45 | 只看该作者
谢谢!加了C51FPS.LIB。31个警告了。

使用特权

评论回复
15
chen3bing|  楼主 | 2011-9-8 18:45 | 只看该作者
Build target 'Target 1'
assembling STARTUP.A51...
compiling M7_B2.C...
assembling M7_B2.src...
linking...
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C_START
    MODULE:  STARTUP.obj (?C_STARTUP)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C_START
    MODULE:  STARTUP.obj (?C_STARTUP)
    ADDRESS: 5968H
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?IMUL
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CLDPTR
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CSTPTR
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CLDOPTR
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?SLCMP
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?IMUL
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 55DFH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDPTR
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 561CH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDPTR
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 5644H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CSTPTR
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 5649H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?IMUL
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 57BBH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDOPTR
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 57D8H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?SLCMP
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 5541H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?SLCMP
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 5565H
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?LNEG
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (?C?FCAST)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?LNEG
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (?C?FCAST)
    ADDRESS: 4BE8H
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?PLDIIDATA
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CLDPTR
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CSTPTR
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CCASE
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  _PUTCHAR
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CLDOPTR
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?PLDIIDATA
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
    ADDRESS: 4E0DH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDPTR
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
    ADDRESS: 4E10H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?PLDIIDATA
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
    ADDRESS: 4E4BH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CSTPTR
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
    ADDRESS: 4E4FH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  _PUTCHAR
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
    ADDRESS: 4E52H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDOPTR
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
    ADDRESS: 4F2EH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDPTR
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
    ADDRESS: 4F51H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CCASE
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
    ADDRESS: 5132H
Program Size: data=124.1 xdata=0 code=22892
creating hex file from "STC60S2"...
"STC60S2" - 0 Error(s), 31 Warning(s).

使用特权

评论回复
16
chen3bing|  楼主 | 2011-9-8 18:55 | 只看该作者
我又加了C51BS.LIB,只剩8个警告了。
Build target 'Target 1'
assembling STARTUP.A51...
compiling M7_B2.C...
assembling M7_B2.src...
linking...
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CLDOPTR
    MODULE:  M7_B2.obj (M7_B2)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDOPTR
    MODULE:  M7_B2.obj (M7_B2)
    ADDRESS: 592FH
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CLDOPTR
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDOPTR
    MODULE:  C:\Keil\C51\LIB\C51FPS.LIB (PRINTF)
    ADDRESS: 4FCFH
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CLDXPTR
    MODULE:  C:\Keil\C51\LIB\C51BS.LIB (?C?CLDPTR)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CLDXPTR
    MODULE:  C:\Keil\C51\LIB\C51BS.LIB (?C?CLDPTR)
    ADDRESS: 4E14H
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?C?CSTXPTR
    MODULE:  C:\Keil\C51\LIB\C51BS.LIB (?C?CSTPTR)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  ?C?CSTXPTR
    MODULE:  C:\Keil\C51\LIB\C51BS.LIB (?C?CSTPTR)
    ADDRESS: 4E2BH
Program Size: data=124.1 xdata=0 code=23263
creating hex file from "STC60S2"...
"STC60S2" - 0 Error(s), 8 Warning(s).
现在彩屏已经显示了。感谢alicedodo兄!

使用特权

评论回复
17
chen3bing|  楼主 | 2011-9-8 19:04 | 只看该作者
我把C51BS.LIB去掉,加上c51ms.lib,就没有警告了。OK!

使用特权

评论回复
18
guipo123| | 2011-9-9 00:12 | 只看该作者
好长代码。。。汇编还不懂啊。帮顶希望高手能帮你

使用特权

评论回复
19
mcu5i51| | 2011-9-9 08:15 | 只看该作者
自己该自己找麻烦,潜入汇编的话单独建一个源文件;不要和main函数在一个文件中,这样就没有这么多麻烦了;另外你的setb P1.2真的没有必要用汇编,C语言会生成相同的代码。

使用特权

评论回复
20
chen3bing|  楼主 | 2011-9-9 08:25 | 只看该作者
setb P1.2是我想实验怎么嵌入汇编用的。
实验成功了,我再嵌入实用的汇编。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

439

主题

2540

帖子

2

粉丝