CodeWarrior使用教程第一部分: 认识 CodeWarrior

CodeWarrior 能做些什么?
    当你知道自己能写更好的程序时,你一定不会再使用别人开发的应用程序。但是常常会发生这种情况,就是当你写了无数行代码后,却找不到使得整个程序出错的那一行代码,导致根本没法编译和链接整个程序。这可能更令人灰心丧气。

    本文将告诉你如何使用 CodeWarrior 这一工具解决上述问题。

    从现在开始,我们将集中精力学习如何在 CodeWarrior 中使用 C/C++ 进行编程。为了学习本课程,你必须已经能够比较熟练地使用上述两种语言之一。CodeWarrior 也可以支持 Java 开发,但那是另一门课程的内容。本课程仅限于在 Windows 平台上使用 CodeWarrior 进行的开发。一旦你精通了 CodeWarrior 编程后,你可以试试在其它平台上使用 CodeWarrior。本文中讨论过的大部分内容都可以应用到开发 Mac 应用程序中。

    CodeWarrior 能够自动地检查代码中的明显错误,它通过一个集成的调试器和编辑器来扫描你的代码,以找到并减少明显的错误,然后编译并链接程序以便计算机能够理解并执行你的程序。你所使用过的每个应用程序都经过了使用象 CodeWorrior 这样的开发工具进行编码、编译、编辑、链接和调试的过程。现在你在我们的指导下,自己也可以去做这些工作了。

    你可以使用 CodeWarrior 来编写你能够想象得到的任何一种类型的程序。如果你是一个初学者,你可以选择编写一个应用程序(比如一个可执行程序),比如象微软公司的文本编辑器 WordPad 这样的应用程序。

    应用程序可能是最容易编写的程序了,而那些庞大的商业软件,比如象 Adobe Photoshop,Microsoft Word 以及 CodeWarrior 软件都是极其复杂的。其它类型的程序指的是控制面板(control panels),动态链接库(dynamic linked libraries,DLLs) 和插件(plug-ins)。我们先来简单的讨论一下这些类型的程序。

    在 Windows 中,控制面板程序是一些(通常比较小的)存放在控制面板目录下的程序,可以在开始菜单的控制面板项中看到它们。控制面板实际上是设置系统功能的一个简单界面,比如可以在控制面板中完成诸如设置音量和鼠标移动速度这样一些参数。

    动态链接库 (DLLs) 提供了一些很有用的被系统和应用程序共享的函数。通常它们都是没有用户界面的。

    插件 (Plug-ins) 有点类似于 DLLs,插件也是可供其它软件使用的小程序,但插件只能被特定的软件使用。比如说,Photoshop 的插件允许程序员方便地扩展 Photoshop 的功能,而不需要去修改它的源代码。同样的,许多 Web 浏览器也使用插件来增加功能,或者为了让你能够看到页面上的新的内容类型。实际上,有许多程序,包括 CodeWarrior,都使用这种插件结构。

    一旦你掌握了 CodeWarior 和你所使用的操作系统的编程接口时,你可以编写许多其它类型的程序。实际上,本课程也是你深入学习其它编程方法的基础课程。你已经找到了一个最优秀的地方开始你的编程之旅。好,现在请坐好,放松,去吸取这门课程的精华吧,你将踏上一条成为一个编程武士的道路!

CodeWarrior 入门

    CodeWarrior 是一个复杂的应用程序,你必须花点时间来了解它的各种各样的组件和功能。第一课将讲述 CodeWarrior IDE 的安装。我们将学习菜单、窗口和其它的一些方面。建议你最好一边学习本课程,一边学习使用 CodeWarrior 的集成开发环境。我们从运行 CodeWarrior 开始,如果你按照默认方式安装的 CodeWarrior 软件,那么在 Windows 的桌面上将会有一个该软件的快捷方式图标。双击该图标启动 CodeWarrior 的集成开发环境。如果在 Windows 桌面上没有这个快捷图标(这种情况经常发生),你可以在 C:\Program Files\Metrowerks\CodeWarrior\Bin 中找到 IDE.exe 文件,然后运行它。

工具条

    启动 CodeWarrior 后,你将会看到,在屏幕上方的菜单下面有一个工具条。这个工具条(见图1-1)包含了一些常用菜单项的快捷方式。在后面的章节中,你将学到如何设置这个工具条,甚至是整个 IDE 环境。现在,你应记住,这个工具条用于快捷使用 IDE 中的功能。

图 1-1: CodeWarrior IDE 的工具条

文件菜单

    CodeWarrior IDE 的菜单是按照标准方式设置的。其中的文件菜单用于处理和文件相关的一些操作,比如创建、打开、保存和打印等等。

编辑菜单

    CodeWarrior 的编辑菜单和其它的 Windows 应用程序也很相像。其中包括了剪切、复制和粘贴等操作,以及其它一些使得程序员能够更方便地管理源码版面布局的选项。在编辑菜单中还有一个 Preferences 项,我们在这一课的后面将提到它。

查看菜单

    查看菜单(图1-2)用于安排工具条和其它窗口在 CodeWarrior 环境中如何显示的选项。所谓的“其它窗口”包括许多特殊的窗口,比如观察点(Watchpoints)窗口,表达式(Expressions)窗口,过程(Processes)窗口和全局变量(Global Variables)窗口等。

图 1-2: 查看菜单中的工具条子菜单

查找菜单

    查找菜单用于在单个文件或硬盘的目录中查找指定的代码。你可以使用它来方便地替换文本块或在你的代码中搜索指定的项目。即使是在小工程中使用这个工具也非常方便。

工程菜单

    工程菜单中的工具用于管理 CodeWarrior 工程。一个工程包括组成你正在编写的程序的所有的文件,包括头文件、源代码和库文件。工程窗口显示了所有这些文件的名称。我们将在第二课中深入讨论这部分内容。

调试菜单

    这是在编制程序中最常用到的工具。我们将在第五课中详细介绍它的使用方法。

窗口菜单

    用于在 CodeWarrior 环境管理窗口显示方式的菜单。

帮助菜单

    通过帮助菜单可以到网上寻求关于 CodeWarrior 任何问题的在线解答。够酷的吧?

了解 CodeWarrior 集成开发环境的设置

    CodeWarrior IDE 提供了许多设置以便让你定制你的工作环境。当你选择了编辑菜单中的 Preferences 项时,你将会看到一个设置对话框(如图1-3)。在该对话框中,有控制 CodeWarrior 编辑器、调试器和其它许多功能的界面和行为的选项。在这一节中,我们将学习这些设置的使用。

图 1-3:  设置对话框

你可以在自己的 CodeWarrior 中试试上述这些设置项。你可以先点击问号标志,然后点击你感兴趣的项目,就可以得到一个有关该项目的用途的简短介绍,也可以从帮助菜单中得到更详细的信息。

通用设置
•编译设置(Build Settings): 选择是否在执行编译之前保存已打开的源文件,以及有多少内存被用于编译工作;
•IDE 之外(IDE Extras): 几个独立的设置。比如指定 CodeWarrior 是否使用一个第三方的文本编辑器——因为集成的编辑器并不是很完美,这可以通过指定一个你惯用的编辑器来替代它;  
•插件设置(Plug-In Settings): 供插件开发商调试他们的插件;  
•隐藏文件夹(Shielded Folders): 在这里指定的文件夹在工程设计期间,或执行查找和比较操作期间,将要被忽略掉。如果在你的工程级有一个巨大的“数据”文件目录,而你又不想让这些文件降低 CodeWarrior 的操作速度时,这个设置就很管用了;  
•资料树(Source Trees): 用于指定 CodeWarrior 在编译程序时用不着的目录。

编辑器设置
•编辑器设置(Editor Settings): 几个用于定制编辑器显示、管理文本和窗口的设置项;  
•字体和制表符(Fonts and Tabs): 设置编辑器中的文本大小、字体、制表符和其它显示设置;  
•文本颜色(Text Colors): 用于指定特定语言元素(比如程序的注释)在编辑窗口中的显示的颜色。

调试器设置
•显示设置(Display Settings): 几个用于定制调试器显示的设置项;  
•视窗化(Windowing): 设定调试器如何管理它的窗口(比如隐藏所有打开的编辑器窗口);  
•全局设置(Global Settings): 几个用于定制调试器在全局层次如何工作的设置。比如当一个包含了程序调试信息的文件被打开时,是否启动这个程序;  
•远程连接(Remote Connections): 允许通过 TCP/IP 进行远程调试。这样,你就可以在地球的另一边调试你的软件了;
•Java 设置/Java 调试(Java Settings/Java Debugging): 允许你设置特定的 Java 编程语言选项。本课程不涉及这部分内容。

RAD 工具
•Layout 编辑器: 几个用于在 CodeWarrior 中定制快速应用程序开发工具的使用的设置。

    正如你所见到的,CodeWarrior 有许多设置项和选项。设置完后点击“Save”按钮保存你所作的修改,点击“Close”按钮将忽略你所作的所有修改。在进入下一节课之前,多练习几次。最后请确认“默认的文本文件格式(Default Text File Format)”(在编辑器设置面板中)保持为 DOS 设置。


附原文:

Lesson 1: Getting to Know CodeWarrior

What Will CodeWarrior Do for Me?

It can be frustrating to use other people's applications when you know you can make something better. But it can also be frustrating when you have a zillion lines of code and can't find the one typo that's making the whole application go kablooey -- not to mention getting it all compiled and linked and so on.

This is why you are here. And this is why CodeWarrior was created.

For now, we'll focus on writing programs in CodeWarrior using the C or C++ programming languages. This course assumes that you're pretty comfortable using at least one of these languages. CodeWarrior also supports Java development, but that will be covered in a separate class. This course concerns itself with Windows platform development. Once you get really good at programming with CodeWarrior, you can explore the other platforms for which tools have been designed. Much of what will be discussed here can also be applied to developing Mac applications.

CodeWarrior automatically checks your code for obvious errors, helps you scan it for less obvious ones (via an integrated debugger and editor), and then compiles and links the code so that your computer can understand and execute your program. Every application that you have used has been through the coding, compiling, editing, linking, and debugging process, using tools like CodeWarrior. Now you can do it too! But we still have to teach you how.

Using CodeWarrior, you can write just about any type of program you can imagine. If you are a beginner, you may choose to write an application (also known as an executable) as your first program. You might choose to create something as basic as WordPad, Microsoft's text editor, for example.

Applications are probably the simplest type of program to write, though large commercial ones like Adobe Photoshop, Microsoft Word and even CodeWarrior itself are quite complex. Other program types include control panels, dynamic linked libraries (DLLs), and plug-ins. Let's talk about these types for a minute.

Under Windows, control panels are those (usually small) programs that are stored in your Control Panels directory and visible in the Control Panel section on the Start menu. The control panel itself is simply an interface to a system-wide feature, like setting the sound volume or the mouse's motion speed, for example.

DLLs supply useful functions that are shared by the operating system and applications. They typically don't have a user interface

Plug-ins are similar to DLLs in that they provide small pieces of code that are used by other software. However, a single program typically uses this code. For example, Photoshop plug-ins allow programmers to easily extend the capabilities of the Photoshop application without having access to its source code. Likewise, many Web browsers use plug-ins that add extra features to the application or allow you to manipulate new content types on the Web. Many programs, including CodeWarrior, make use of this plug-in architecture.

There are plenty of other types of programs you can write once you master CodeWarrior and the programming interfaces for your operating system. In fact, once you complete this course, you can take other courses in which you will learn more in-depth methods of programming your computer. You've chosen an excellent place to begin your journey, however. So sit back, relax, and absorb the lessons in this course, and you'll be well on your way to becoming a CodeWarrior!
 


An Introduction to the CodeWarrior Application

CodeWarrior is a complex application. If you really want to benefit from all of its features, you should take this time to get to know its various components and the capabilities that will be available to you. This first lesson will give you a basic overview of how the CodeWarrior IDE is set up. (That acronym gets thrown around a lot, and it's short for Integrated Development Environment. ) We'll take a look at menus, windows, and other aspects of the program. Follow along with the CodeWarrior IDE while you read through these lessons. Start by launching the IDE application. If you followed the defaults for the CodeWarrior software installation, there will be an icon that represents a shortcut to the program. Double-click on it to start the IDE. If the shortcut icon is absent (these things happen), you can typically find the program at C:\Program Files\Metrowerks\CodeWarrior\Bin\IDE.exe.

Toolbar

When you launch the CodeWarrior IDE, you'll notice a toolbar attached to the menu at the top of your screen. This toolbar (Figure 1-1) contains buttons that are shortcuts to frequently used menu items. You'll learn how to customize this toolbar -- and even the entire IDE -- in a later lesson. For now, notice that this toolbar can be used to quickly access features within the IDE.

Figure 1-1: The CodeWarrior IDE toolbar

File Menu

The menus in the CodeWarrior IDE are set up in a relatively standard manner. The File menu contains choices that manage the care and feeding of files. It has standard items that let you create, open, save, and print files.

Edit Menu

The Edit menu will also seem familiar if you use other Windows applications. You'll find commands that cut, copy, and paste text, as well as a few other options to help programmers more easily manage source code layout. There is also a Preferences item in the Edit menu that we'll discuss later in this lesson.

View Menu

The View menu (Figure 1-2) gives you options to manage which toolbars and other windows are displayed in the CodeWarrior environment. Some of these windows include various specialty windows, such as the Watchpoints window, Expressions window, Processes window, and Global Variables window.

Figure 1-2: The Toolbar submenu of the View Menu

Search Menu

The Search menu's commands allow you to locate source code within a single file, or within the directories of your hard disk. You can also easily replace large blocks of text or search your source code for references to other source code. These tools can be very handy, even for small projects.

Project Menu

Tools in the Project menu allow you to manage CodeWarrior projects. A project includes all of the files that make up a program you are writing, including its headers, source code, and libraries. The Project window serves as a container for these files. We'll discuss this in more depth in Lesson 2.

Debug Menu

When your source code doesn't do exactly what you want it to (or your computer crashes when you run your program), you'll develop a close relationship with the items on the Debug menu. We'll discuss debugging in Lesson 5.

Window Menu

The Window menu gives you the basic options to manage cascading and tiling windows in the CodeWarrior environment.

Help Menu

Lastly, use the Help menu to get online help with just about any item in CodeWarrior. Pretty cool setup, huh?

Getting to Know IDE Preferences

The CodeWarrior IDE has numerous preferences that you can use to customize your work environment. You may only want to change the text color, or you might want to get more personal, changing lots of settings. When you select Preferences from the Edit menu, you are presented with the IDE Preferences dialog box (Figure 1-3). There, you'll find options that control the appearance and behavior of the CodeWarrior editor, debugger, and lots more. In this section, we'll take a look at these preferences.


Figure 1-3: The Preferences dialog box.

As each item is described below, follow along in your own copy of CodeWarrior, and check out the various options available. You can get additional help by clicking on the question mark, then the item you're interested in. You'll see a terse description of the selected item's purpose. More detailed information is also available from the Help menu.


The General Preferences
•Build Settings: Choose whether to save open-source code files before performing a build and how much memory to use while building.
•IDE Extras: Various settings that don't belong anywhere else. Here's where you can have CodeWarrior interoperate with a third-party text editor. The integration of editors with the IDE is often less than perfect, but this limitation may be offset by the ability to use an editor that you know and like.
•Plug-In Settings: Used by plug-in developers to assist in the debugging of plug-ins.
•Shielded Folders: Directories listed here are skipped (ignored) during project and/or find and compare operations. This can be useful if you have a large directory of "data" files inside your project hierarchy yet you do not want those files to slow down certain operations of CodeWarrior.
•Source Trees: This lets you specify directories other than the standard ones CodeWarrior searches when it builds a program.

Editor Preferences
•Editor Settings: Various settings to customize the way the Editor displays and manages text and windows.
•Fonts and Tabs: Text size, font, tab, and other display settings for the Editor windows.
•Text Colors: Like the browser display, you choose the color in which certain language elements (such as comments) appear in the Editor window.

Debugger Preferences
•Display Settings: Various settings to customize the display of the debugger.
•Windowing: How the debugger manages its windows (e.g., hiding any open editor windows).
•Global Settings: Various settings that customize how the debugger works on a global level, such as whether to launch a program when you open a file that contains the program's debugging information.
•Remote Connections: Allows debugging over TCP/IP. You can debug software on a computer on the other side of the Earth!
•Java Settings/Java Debugging: Allows you to set specific java programming language options, not covered in this course.

RAD Tools
•Layout Editor: Various settings to customize the use of rapid application development tools within CodeWarrior.

As you can see, there are numerous settings and options that can be set. Clicking the Save button will save any changes you've made. Clicking the Close box for the Preferences window will cause CodeWarrior to ignore any changes you've made. Go ahead and play with it a little before you proceed to the next lesson. Make sure the Default Text File Format (in the Editor Settings panel) remains set for DOS.

  • 10
    点赞
  • 79
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: CodeWarrior是一种集成开发环境(IDE),主要用于嵌入式系统开发,可提高开发效率和可靠性。下面是一些使用CodeWarrior的教程: 1.安装CodeWarrior:首先需要从官方网站下载CodeWarrior,然后按照向导安装。这个过程很简单,只需要按照指示进行就可以了。 2.创建项目:打开CodeWarrior后,你会看到一个欢迎界面。点击新建项目,然后选择你要开发的平台,输入项目的名称和存储路径。CodeWarrior提供了各种处理器的采用系统和支持。选择适当的选项后,按'test project'开始新的测试项目。 3.编写代码:编写代码是主要的工作。点击CodeWarrior界面的源代码窗口,然后使用自己喜欢的编程语言定义函数和变量并编写其代码。 4.调试程序:CodeWarrior提供了各种调试工具和方式。在调试过程中,你可以查看变量的值、检查代码的执行流程、停止并单步运行程序等。 5.生成可执行文件:当你的程序完成后,需要将代码出口保存到可执行文件中。CodeWarrior可以为你生成各种类型的可执行文件,如二进制可执行文件、库文件等。选择适当的输出选项,然后构建程序以生成最终的可执行文件。 总之,CodeWarrior是一款功能强大的IDE,可以显著提高嵌入式开发的效率和可靠性。只要按照上述步骤进行,你就可以轻松创建项目、编写代码和调试程序,最终生成可执行文件并将其部署到目标设备上。 ### 回答2: Codewarrior是一款功能强大的集成开发环境,用于嵌入式系统的开发,采用了易于使用的GUI界面,帮助开发者更快速地实现各种应用。Codewarrior的安装和使用都比较简单,只需按照以下步骤进行操作即可。 1.安装Codewarrior 首先需要从官方网站下载Codewarrior,并进行安装。安装完成后,会生成Codewarrior的快捷方式,可以通过双击打开。如果之前已经安装了Codewarrior,需要先将之前版本的卸载干净。 2.创建新项目和工程 打开Codewarrior后,需要创建新的项目和工程。在菜单栏中选择“File”->“New”->“Project”,然后选择需要使用的工具链和操作系统。在这里可以选择常用的MCU厂商和芯片,以及对应的SDK版本。 3.添加源文件 将需要编译运行的源文件导入该工程中,可以在菜单栏中选择“File”->“New”->“Source File”,或者右键点击工程选项,选择“New”->“Source File”来添加。 4.配置编译选项 配置编译选项可以在工程的属性窗口中进行,选择“Project”->“Properties”来打开工程属性页面。在这里可以选择编译器和调试器,并设置编译选项。 5.编写代码 在Codewarrior中编写代码和其他IDE是一样的,使用内置的编辑器即可。不过需要注意的是,Codewarrior使用的是ANSI C标准,使用非ANSI C标准的函数需要开启相应的编译选项。 6.编译和调试 所有配置完成后,可以开始编译和调试。编译可以选择菜单栏中的“Project”->“Build”,或者使用快捷键Ctrl+B来进行。调试可以选择“Debug”->“Debugger”->“Attach”,或者使用快捷键F5来启动。Codewarrior也提供了更加丰富的调试工具,用户可以根据需要使用。 以上是Codewarrior使用教程,希望能够提供一定的帮助。在使用过程中需要注意的是,多看官方文档和经验交流论坛,了解更多的使用技巧和注意事项,以提高开发效率和质量。 ### 回答3: Codewarrior是一款强大的集成开发环境(IDE),由美国Freescale公司推出,目前已被收购为尽力科技公司推广。它具备开发嵌入式系统所需的所有功能。Codewarrior支持大量的MCU系列,如:Freescale公司的ColdFire,Kinetis和HCS12,NXP Semiconductors公司的ARM Cortex-M,以及其他MCU系列,如AVR。在Codewarrior中,开发人员可以编写C/C++代码,并使用调试器、分析器、编译器和器件编程器来开发、测试和部署。 Codewarrior的主要功能和特点: 1. 支持多种MCU系列,可以在一个集成开发环境中开发多种嵌入式系统。 2. 提供了代码编辑器和高级调试器,用于快速开发和测试嵌入式系统。 3. 支持直接调试Bootloader,允许在Flash中下载并调试应用程序。 4. 提供器件编程器和时钟工具,可简化和自动化制造流程。 5. 支持代码版本控制和协作开发,允许多人协作开发同一项目。 下面是Codewarrior使用教程: 1. 下载和安装Codewarrior IDE。 2. 创建一个新项目,将MCU型号和其他项目设置设置为所需的编译器选项。 3. 创建和修改源代码文件,例如添加文件、修改文件名或移动文件。 4. 编写代码后,设置Debug Configuration。 5. 在Debug Configuration窗口中,添加断点以调试代码。 6. 运行程序并使用调试器查看调试输出。 7. 分析调试信息并修正代码错误。 8. 代码测试完成后,使用编译器和器件编程器将程序烧录到MCU中。 总的来说,Codewarrior是一款功能全面的IDE,提供了快速开发嵌入式系统所需的所有工具和资源。用户可以根据需要自定义设置,并使用Debug Configuration和其他工具来调试和分析代码。因此,如果你需要开发嵌入式系统,Codewarrior是一个不错的选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值