石家庄论坛's Archiver

lyq_4652 发表于 2008-7-29 15:10

科威PLC芯片组开发实例(三)

[font=宋体]如何搭建用户驱动环境?[/font]
[font=Times New Roman] [/font]
[font=宋体]首先,教大家如何使用[/font][font=Times New Roman]KEIL3[/font][font=宋体]创建一个用户驱动工程[/font][font=Times New Roman]([/font][font=宋体]笔者目前用的是[/font][font=Times New Roman]KEIL3[/font][font=宋体],只能就此讲解,所以你用的如果是[/font][font=Times New Roman]KEIL2[/font][font=宋体]或者[/font][font=Times New Roman]Cynal[/font][font=宋体],那么就自行摸索,总的来说,功能上都相差不大。[/font][font=Times New Roman])[/font]
[font=Times New Roman] [/font]
[font=宋体]首先要注册[/font][font=Times New Roman]KEIL3[/font][font=宋体],使之可以编译超过[/font][font=Times New Roman]2K[/font][font=宋体]范围的代码。至于怎么注册,请在网上找,笔者不在此赘述。[/font]
[font=Times New Roman] [/font]
[font=宋体]新建一个文件夹,此文件夹为你将要做的项目文件夹[/font][font=Times New Roman]([/font][font=宋体]比如[/font][font=Times New Roman]D:\PLC_DRIVE[/font][font=宋体],以下的教程皆假定你的项目在此文件夹内来阐述[/font][font=Times New Roman])[/font][font=宋体]。[/font]
[font=宋体]然后打开[/font][font=Times New Roman]KEIL3[/font][font=宋体],在菜单栏选择[/font][font=Times New Roman]Project[/font][font=宋体]→[/font][font=Times New Roman]New Project…[/font][font=宋体],将会弹出一个名为“[/font][font=Times New Roman]Create New Project[/font][font=宋体]”的对话框,在对话框中选择[/font][font=Times New Roman]D:\PLC_DRIVE[/font][font=宋体]并双击进入,创建一个名为“[/font][font=Times New Roman]PLCDR[/font][font=宋体]”的[/font][font=Times New Roman]uv2[/font][font=宋体]文件。[/font]
[font=Times New Roman] [/font]
[font=宋体]接下来会弹出一个选择芯片类型的对话框,下拉竖直条选择“[/font][font=Times New Roman]Silicon Laboratories, Inc.[/font][font=宋体]”展开选择“[/font][font=Times New Roman]C8051F040[/font][font=宋体]”,点击确定。[/font]
[font=Times New Roman] [/font]
[font=宋体]随后系统问你是否需要“[/font][font=Times New Roman]Copy Standard 8051 Startup Code to Project Folder and Add File to Project?[/font][font=宋体]”,这句话的意思是问你是否需要为你的项目添加标准的[/font][font=Times New Roman]8051[/font][font=宋体]规范。这个东西对我们这个项目的开发没多大用,推荐你选择否,反正笔者就是这么干的。[/font]
[font=宋体]这个时候基本的项目框架就搭建起来了,现在是时候为你的驱动项目添加“血肉”了。[/font]
[font=Times New Roman] [/font]
[font=宋体]选择菜单中的[/font][font=Times New Roman]File[/font][font=宋体]→[/font][font=Times New Roman]New…[/font][font=宋体],点击“保存”,将此[/font][font=Times New Roman]Text1[/font][font=宋体]空白文档保存在[/font][font=Times New Roman]D:\PLC_DRIVE[/font][font=宋体]中,并更改此文件名为“[/font][font=Times New Roman]PLCDR.ASM[/font][font=宋体]”,注意后缀名是“[/font][font=Times New Roman].ASM[/font][font=宋体]”而不是“[/font][font=Times New Roman].TXT[/font][font=宋体]”了。[/font]
[font=Times New Roman] [/font]
[font=宋体]这个时候,细心的你可能已经发现了,我们将会用[/font][font=Times New Roman]51[/font][font=宋体]汇编来实现驱动程序的编写。在这个汇编已经没落,甚至连[/font][font=Times New Roman]C[/font][font=宋体]也慢慢的被人抛弃的时代,[/font][font=Times New Roman] C#[/font][font=宋体],[/font][font=Times New Roman].NET[/font][font=宋体],[/font][font=Times New Roman].COM[/font][font=宋体],[/font][font=Times New Roman]JAVA[/font][font=宋体],[/font][font=Times New Roman]J2EE[/font][font=宋体]等流行语言及技术大行其道的今天,我们为什么还要用汇编来编写程序呢?而且是在[/font][font=Times New Roman]KEIL[/font][font=宋体]也是支持[/font][font=Times New Roman]C[/font][font=宋体]语言的情况下我们做出的选择,看似更加的没有道理。其实这是仁者见仁,智者见智的。在笔者看来,汇编虽然比[/font][font=Times New Roman]C[/font][font=宋体]更加的晦涩难懂,但它最贴近硬件的特性却能够使我们的驱动程序更加的高效,在[/font][font=Times New Roman]F040[/font][font=宋体]这个[/font][font=Times New Roman]8[/font][font=宋体]位小型[/font][font=Times New Roman]CPU[/font][font=宋体]上,使用汇编语言能更加让我们“精打细算”,使我们的每条语句都精确到[/font][font=Times New Roman]0.0X[/font][font=宋体]个[/font][font=Times New Roman]US([/font][font=宋体]科威[/font][font=Times New Roman]PLC[/font][font=宋体]芯片组的系统时钟频率为[/font][font=Times New Roman]24.5MHZ[/font][font=宋体],也是[/font][font=Times New Roman]F040[/font][font=宋体]所能达到的最高系统时钟频率[/font][font=Times New Roman])[/font][font=宋体],[/font][font=Times New Roman]PLC[/font][font=宋体]是做什么的?当然是做控制的,所以实时性,高效性以及安全性是[/font][font=Times New Roman]PLC[/font][font=宋体]永恒的话题。我们选择汇编语言作为驱动程序的开发的理由也正因如此。当然,如果你对汇编一窍不通的话,笔者也建议你耐心把下面的教程看完,虽然汇编与[/font][font=Times New Roman]C[/font][font=宋体]的差异性还是蛮大的,但是多多少少会对你对芯片组开发有一定的帮助。[/font]
[font=Times New Roman] [/font]
[font=宋体]呵呵,话题扯远了,言归正转,你注意到左边那个“[/font][font=Times New Roman]Project Workspace[/font][font=宋体]”浮动工具栏没?双击里面的[/font][font=Times New Roman]Source Group 1[/font][font=宋体],路径选择到“[/font][font=Times New Roman]D:\PLC_DRIVE[/font][font=宋体]”,选择“[/font][font=Times New Roman]PLCDR.ASM[/font][font=宋体]”并点击确定。什么?没有这个“[/font][font=Times New Roman]PLCDR.ASM[/font][font=宋体]”?那你得把文件类型改为“[/font][font=Times New Roman]all files[/font][font=宋体]”才能看的到。个人[/font][font=Times New Roman]BS[/font][font=宋体]了[/font][font=Times New Roman]KEIL[/font][font=宋体]公司一下,居然连[/font][font=Times New Roman].ASM[/font][font=宋体]的文件类型都没有[/font][font=Times New Roman]…[/font][font=宋体]看来也是个喜新厌旧的主[/font][font=Times New Roman]~[/font]
[font=宋体]这个时候,你会发现[/font][font=Times New Roman]Source Group 1[/font][font=宋体]左边有个小[/font][font=Times New Roman]+[/font][font=宋体]号,点击下拉,[/font][font=Times New Roman]PLCDR.ASM[/font][font=宋体]跃然纸上了,哦不,是跃然于显示屏上了。[/font]
[font=Times New Roman] [/font]
[font=宋体]至此,准备工作已经完成,下一讲我们就要介绍此项目工程在[/font][font=Times New Roman]KEIL[/font][font=宋体]中的一些参数设置,以及科威[/font][font=Times New Roman]PLC[/font][font=宋体]芯片组用户驱动开发所需要准备的几个头文件和函数库。[/font]
[font=Times New Roman] [/font]
[font=宋体]本帖首发中国工控网科威[/font][font=Times New Roman]PLC[/font][font=宋体]论坛,转载请声明![/font]

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.