搜索
bottom↓
回复: 32

公布PIC HI-TECH lib库文件的制作过程

[复制链接]

出0入0汤圆

发表于 2011-11-30 17:32:04 | 显示全部楼层 |阅读模式
首先要知道HI-TECH的库文件的后缀名是.lpp  这个LPP是由.p1后缀名的文件生成的,这就意味着要生成库文件必须先有.p1文件,那么.P1文件从那里来的呢?你的工程项目(已经通过正确编译的)里有,自己去查

废话少说,举例如下:
假设我们需要将其中的1621.c做成库文件

我们必须要有1621.c的 h头文件,而且将h文件包含在项目文件中,没有头文件将来无法使用——别说你不知道神马是.h文件,如果是这样,你就不用看这个贴子了

做库前必须保证我们的C源文件编译是没有问题的.而且起码被成功编译过一次.因为这样才会产生该C文件的*. p1文件。
假设编译器的版本为:PICC v9.81
编译器的安装目录为: C:\Program Files\HI-TECH Software\PICC\9.81

呵呵,开始进入,还有一点,就是要在C盘建立一个文件夹存放.p1文件 假设为libtest
        
1: 点开始->运行
2: 输入”cmd”运行
3: 进入PICC Pro v9.81的bin目录 C:\Program Files\HI-TECH Software\PICC\9.70\bin  这个是非常关键,可能有一些人会卡在这里,提示一下用DOS 里的DC 命令 不了解DOS就google 一下吧
4: 输入命令行:libr 回车
5: 输入指令(注意r后面的空格)r C:\libtest\bin\1621.lpp C:\librest\1621.p1
6: 你会发现librest文件夹中多一个1621.lpp的库文件——那么恭喜你,你XX了

做好库之后,如何使用,这就简单了——就如一个女人脱光了躺在你的床上,相信你知道怎么做:
1: 在MPLAB项目的Source Files 中将1621.c移除并删除——呵呵,兄弟这个是源码你知道怎么做,别跟我说“你直接用Shift+Delete删除,没有备份”
2: 在MPLAB项目的Library Files 中将1621.lpp添加进来。
3: 验证,重新编译通过,编译结果和使用源代码的相同

(原文件名:LIB.jpg)


(原文件名:LIB2.jpg)

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2011-11-30 17:44:07 | 显示全部楼层
希望大家不要用这个库做出邪恶的事情,会害人害己,切记!!这个只是方便自己编程使用!!!

出0入0汤圆

发表于 2011-11-30 18:08:42 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-11-30 18:35:56 | 显示全部楼层
来学习下

出0入0汤圆

发表于 2011-11-30 18:53:22 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-11-30 18:54:52 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-11-30 20:16:35 | 显示全部楼层
记下

出0入0汤圆

 楼主| 发表于 2011-12-1 11:04:43 | 显示全部楼层
不知道win7系统能不能通过,用过的兄弟说一下

出0入0汤圆

发表于 2012-2-14 23:58:56 | 显示全部楼层
这样做,有什么用处呢?

出0入0汤圆

发表于 2012-2-15 08:10:40 | 显示全部楼层
学习下。

出0入0汤圆

发表于 2012-2-15 09:30:31 | 显示全部楼层
mark

出0入0汤圆

发表于 2012-2-15 09:32:39 | 显示全部楼层
相当感谢啊

出0入0汤圆

发表于 2012-2-15 09:53:11 | 显示全部楼层
回头试试。

出0入0汤圆

发表于 2012-2-15 09:55:32 | 显示全部楼层
记号

出0入0汤圆

发表于 2012-2-15 10:20:43 | 显示全部楼层
关键是不知道会有什么用,带来哪些好处

出0入0汤圆

发表于 2012-2-15 12:09:25 | 显示全部楼层
不错

出0入0汤圆

发表于 2012-2-24 10:59:57 | 显示全部楼层
哥对一个脱光了躺在床上的女人不感兴趣,路过……

出0入0汤圆

发表于 2012-2-24 11:39:31 | 显示全部楼层
灰常感谢啊,找的就是这个哈!

出0入0汤圆

发表于 2012-2-24 12:10:50 | 显示全部楼层
mark

出5入42汤圆

发表于 2012-2-24 12:12:20 | 显示全部楼层
啥意思啊,求真相,在各个到底有什么用啊

出0入0汤圆

发表于 2012-2-24 15:31:00 | 显示全部楼层
可以用来整人哦。

出0入0汤圆

发表于 2012-3-24 12:52:07 | 显示全部楼层
                                             Creating Library with HI-TECH Compiler
Steps:
1.  Creating the “*.c” library source file  
2.  Generating Library
a)  Use the –output=lpp option to create library  
b)  Use the libr.exe utility to create library  
c)  Create library from MPLAB IDE
3.  Including the Libraries
a)  Add to Library category in MPLAB IDE  
b)  Add to Build Options in MPLAB IDE
c)  Add to command line  
4.  Calling the library  

Step I : Creating the “*.c” library source file  
1.   Create the ‘c file’ containing the library routine.  
       Save this ‘c file’ in your project directory.  
// Library Code File   : lib_add.c  
// Library Routine   : int lib_add(int x, int y);
int lib_add (int x, int y)
{
    return (int)(x + y);
}

// Library Code File   : lib_multiply.c  
// Library Routine   : int lib_multiply(int x, int y);
int lib_multiply (int x, int y)
{
    return (int)(x * y);
}

Step 2: Generating Library
Method 1: Use the –output=lpp option to create library
picc.exe --chip=16Fxxx  lib_add.c  lib_multiply.c  -olibrary.cof  --output=lpp
// --chip option is to specify the device you are using in your project
// library.lpp is the generated library source file

(For PIC18 Device use picc18.exe along with the appropriate PIC18 Device)

Method 2: Use the libr.exe utility to create a library  
"picc.exe"     lib_add.c    --chip=16Fxxx  // Creates a lib_add.p1 file     
"picc.exe"     lib_multiply.c    --chip=16Fxxx  // Creates a lib_multiply.p1 file
              (For PIC18 Device use picc18.exe along with the appropriate PIC18 Device)
   
Run the libr command as:
libr.exe"   r    library.lpp    lib_add.p1    lib_multiply.p1     
  >> libr.exe is the librarian executable
>> r is the option to replace a previous library module with a new one / creates new library if
‘library.lpp’ doesn’t  exist already
  >> ‘library.lpp’ is the generated library file

Method 3: Create library from MPLAB IDE
a)  Create a MPLAB IDE Project
b)  Add the library source files lib_add.c & lib_multiply.c to the Project
c)  Under Project >> Build Options >> Global >> Additional Command Line Options >> Add   
‘--output=lpp’
d)  Build the Project. A xxx.lpp file is created bearing the same name as the MPLAB IDE Project.  

Step 3: Including the Libraries
1.  Library can now be included into the project in 3 ways:
e)  Add the Library to the Project Window under the category “Library Files”
f)  Add the Library File ‘library.lpp’ to the Project Build Options >> Global >> Additional
Command Line Options >> Add >> ‘library.lpp’  
g)  From the command line, library can be added as  
picc.exe    main.c    library.lpp    --chip=16Fxxx (For PICC  Compiler)
                     (For PIC18 Device use picc18.exe along with the appropriate PIC18 Device)

Step 4: : Calling the library from main line code  
// Code to call the routines in the library:
extern int lib_add (int a, int b);
extern int lib_multiply(int a, int b);
void main()
{
int x=20, y=10;  
volatile int p, s;
p = lib_add (x, y);
s= lib_multiply (x,y);
}

出0入0汤圆

发表于 2012-3-30 17:23:07 | 显示全部楼层
在MPLAB IDE环境中是不能够直接生成HI-TECH编译器库文件的。只能通过HI-TECH自带的生成工具在命令行中转换。
    HI-TECH编译器生成库文件类型有两种类型p-code库文件和object库文件,后缀名分别为.lpp和.lib。 这两种库文件分别对应C语言和汇编语言编写的模块程序。p-code库文件是由C语言编写的模块程序转换而来,C语言模块程序编译后的后缀名为.p1(注意不是.pl)。object库文件是由汇编语言编写的模块程序转化而来,汇编模块编译后的后缀名为.obj。你可以在编译之后的工程目录里找到.p1文件和.obj文件。
    HI-TECH编译器库文件生成程序称为Librarian,位于安装目录C:\Program Files\HI-TECH Software\PICC\9.70\bin。程序名称为libr.exe。库文件转化格式为
(1)LIBR [options] k file.lpp [file1.p1 file2.p1...]
(2)LIBR [options] k file.lib [file1.obj file2.obj...]
    在一般应用中options忽略,k表示关键字一般为为r,表示覆盖模式,file.lpp和file.lib为转换后生成的库文件,file.p1和file.obj为模块文件,转化程序从这些模块文件中生成库文件。
    转化只能在windows命令行中进行。在命令行中,文件需要写出完整的路径,这样会很麻烦。可以将libr.exe和.lpp/.obj文件拷到同一目录下,这样会方便一些。
    具体的过程以及库文件其他转换模式请参考HI-TECH manual.pdf : Chapter 6 Utilities.

出0入0汤圆

发表于 2012-4-1 07:40:02 | 显示全部楼层
学习库文件的制作方法,这样做对自己方便很多。

出0入0汤圆

发表于 2012-4-2 21:20:08 | 显示全部楼层
学习学习

出0入0汤圆

发表于 2012-4-3 00:36:32 来自手机 | 显示全部楼层
这个有什么用啊

出0入0汤圆

发表于 2012-4-3 02:52:04 | 显示全部楼层
The C source code can be frozen (and moved to other folder), so no chance to be changed by accident.

出0入0汤圆

发表于 2012-11-3 09:16:43 | 显示全部楼层
不错,PIC介绍的好啊

出0入0汤圆

发表于 2013-1-24 15:06:00 | 显示全部楼层
WIN7-32位系统下 制作库文件 能用  MARK  谢谢楼主了

出0入0汤圆

发表于 2013-1-25 23:31:35 | 显示全部楼层
mark 一下 一下

出0入0汤圆

发表于 2013-1-26 10:05:33 | 显示全部楼层
库文件的用处何在?邪恶的事情指什么啊?

出0入0汤圆

发表于 2013-10-8 22:06:23 | 显示全部楼层
mark一下     

出0入0汤圆

发表于 2013-10-9 03:01:38 来自手机 | 显示全部楼层
不错的资料。记下了
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-19 07:14

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表