当前位置:首页 >> 信息与通信 >>

Freescale Codewarrior 芯片烧写指南


Codewarrior 使用指南

TM

? 利用向导创建一个新工程项目 ? 在新项目中加入或删除文件 ? 调试 ?启动程序 ? PRM文件设置 ? 如何对IO及寄存器进行操作 ? 如何写中断程序 ?嵌入式编程注意事项 ?Codewarrior 定购信息

TM

Freescale? and t

he Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

创建新工程 1

1、创建新工程 2、选择HCS12 New Project Wizard 选择HCS12 3、输入工程名

Slide 3
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

创建新工程 2
4、选择MCU类型 选择MCU类型 MCU 5、选择语言类型

Slide 4
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

创建新工程 3
6、选择是否采用Processor Expert 选择是否采用Processor 7、选择是否使用PC-lint 选择是否使用PCPC

如果用Processor Expert, 如果用Processor Expert,选择 Yes
Slide 5
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

创建新工程 4
8、选择是否用浮点运算 9、选择存储器类型

Slide 6
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

创建新工程 5
10、 10、选择调试器类型

Slide 7
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

编译

调试

是否产生调试信息 源程序文件夹 up文件夹 Start up文件夹 Prm文件夹 Prm文件夹 Map文件夹 Map文件夹 库文件夹 列出相关文件 代码长度
TM

变量长度
Slide 8

是否被包含在Target中 是否被包含在Target中 Target

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

参考文献

www.codewarrior.com Slide 9 manuals/pdf/IED_Users_Guide.pdf Codewarrior manuals/pdf/IED_Users_Guide.pdf
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

? 利用向导创建一个新工程项目 ? 在新项目中加入或删除文件 ? 调试 ?启动程序 ? PRM文件设置 ? 如何对IO及寄存器进行操作 ? 如何写中断程序 ?嵌入式编程注意事项 ?Codewarrior 定购信息

TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

在新项目中加入或删除文件

如果编译时,出现没有调试信息警告, 如果编译时,出现没有调试信息警告,请点击这里

新建一文件, 新建一文件,并保存到原文件夹中 点击右键, 点击右键,加入或从此工程中删除文件

Slide 11
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

? 利用向导创建一个新工程项目 ? 在新项目中加入或删除文件
调试 ?启动程序 ? PRM文件设置 ? 如何对IO及寄存器进行操作 ? 如何写中断程序 ?嵌入式编程注意事项 ?Codewarrior 定购信息

TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

模拟调试器界面

工具条
打开文件 单步 进入 单步 跳出 停止 复位

保存当前 设置

运行 单步跳过

汇编单步

Slide 13
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

模拟调试器: 模拟调试器 界面
对不同的 simulator和 和 debugger,界 界 面完全相同 。对所有的 CPU,界面 , 完全相同。 完全相同。 仅仅是子窗 口中的内容 不同。 不同。

Slide 14
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

模拟调试器: 模拟调试器 界面

断点信息 汇编指令地址

汇编指令机器码 源代码 汇编指令

覆盖信息 Profiling 信息 (代码所花时间百分比) 代码所花时间百分比) 高级语言展开/折叠命令 高级语言展开 折叠命令
Slide 15
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

模拟调试器: 模拟调试器 界面

CPU 寄存器

存储区地址 存储区中的内容

存储区中的内容(字符 存储区中的内容 字符) 字符

Slide 16
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

模拟调试器: 模拟调试器 界面

执行的函数

目标类型 目标列表

Slide 17
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

? 利用向导创建一个新工程项目 ? 在新项目中加入或删除文件 ? 编译 ? 调试 ? 启动程序 ? PRM文件设置 ? 如何对IO及寄存器进行操作 ? 如何写中断程序 ? 嵌入式编程注意事项 ?Codewarrior 定购信息

TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

启动程序
Startup Code一般用汇编语言写的,并且会连接到你编译过的 一般用汇编语言写的, 一般用汇编语言写的 可执行的模块中. 它为执行C语言写的程序做准备 语言写的程序做准备: 可执行的模块中 它为执行 语言写的程序做准备:

? ? ? ? ? ? ?

关闭中断 把初始化过的数据从ROM中拷贝到RAM中 将未初始化数据区清零 给堆栈分配空间并初始化 创建并初始化堆 开放中断 调用main()
Slide 19
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

Slide 20
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

复位后第一个执行的是启动 程序,复位向量存贮了 _startup()所在位置 所在位置

Slide 21
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

? 利用向导创建一个新工程项目 ? 在新项目中加入或删除文件 ? 编译 ? 调试 ? 启动程序 ? PRM文件设置 ? 如何对IO及寄存器进行操作 ? 如何写中断程序 ? 嵌入式编程注意事项 ?Codewarrior 定购信息

TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

代码放在哪里? 代码放在哪里

? 在*.PRM文件中,SECTIONS命令块用于定义存贮 文件中, 文件中 命令块用于定义存贮
器的物理区域。 器的物理区域。 ? 在SECTIONS命令块中,每个单独的物理存贮器段 命令块中, 命令块中 用一个名字、 用一个名字、一个属性和一个地址范围描述

? PLACEMENT命令块用于将代码和数据段定位到存 命令块用于将代码和数据段定位到存
贮器段

Slide 23
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

#pragma

#pragma 是一个编译指示器, 告诉编译器如何设置

Slide 24
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

存储区分配

Slide 25
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

代码放在哪里? 代码放在哪里

? 变量放在Default_RAM 的位置,除非另外规定一个
PRAGMA声明

? 频繁使用的变量应放在直接页RAM ($40 -$FF) ? 在直接页中访问操作数采用直接寻址模式(8位寻址模式)
比扩展寻址模式(16位寻址模式)少一个时钟周期

Slide 26
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

变量定义在段中, 变量定义在段中, 它的位置由连接器 决定

数据段 (VarA) 想存放在 一个特定区域内 (0x0080-0x00A9) )

定义了一个新的存 储段

Slide 27
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

VarA 在0x80

VarB 在 DEFAULT 段中

Slide 28
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

这段代码想存储在特定 的段中

定义段, 定义段,并把函数体放在该段中

Slide 29
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

funcition1 被放在 FunctionsROM代码段中 , 其地址为 0xEF00 到 EFFF

Slide 30
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

常数段想存放在特定的位置

Slide 31
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

存放在数组里的常数并没有放在 存放在数组里的常数并没有放在 ROM中,而是直接调用了它的内容 中 如果想要更改FLASH中变量数组 。如果想要更改 中变量数组 ,就会发生错误

Slide 32
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

常数替换优化必须被关掉

Slide 33
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

用的是地址, 用的是地址,而非它的值

数组存在我们期望的位置

Slide 34
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

? 利用向导创建一个新工程项目 ? 在新项目中加入或删除文件 ? 编译 ? 调试 ? 启动程序 ? PRM文件设置 ? 如何对IO及寄存器进行操作 ? 如何写中断程序 ? 嵌入式编程注意事项

TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

如何对IO进行操作 如何对 进行操作? 进行操作

? 利用Codewarrior头文件中已经定义好的IO寄存器 ? 或者:
#define PortA ( * ( volatile unsigned char * ) 0x0000 )

? 或者
volatile unsigned char PortA @0x0000;

Slide 36
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

访问固定内存位置

? 嵌入式系统通常的特点是需要编程者访问一个指定的存贮器位 ?
置。 练习:在某个项目中需要将绝对地址0xFFA处整型变量的值设 为0xAA55(编译器为纯粹的ANSI编译器)。完成这个任务的 代码是:

Int * ptr; ptr = (int *)0x2FFA; *ptr = 0xAA55;

Slide 37
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

访问CPU寄存器 寄存器 访问

? CPU中的寄存器没有对应的固定地址 ? 可以用汇编指令对它们进行访问 ? C语言无法直接访问这些寄存器 ? C编译器允许在C代码中使用汇编指令
1)_asm AssemblyInstuction; 2)asm (AssemblyInstruction); 3)asm { ------}
Slide 38
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

修改CPU中CCR寄 中 修改 寄 存器的I位 存器的 位

Slide 39
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

利用汇编指令来修改 I 位

Slide 40
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

位域

? 位结构
效率随编译器的不同而改变; 不同的编译器不能移植。

? 位类型
无法移植 提高代码效率

? 移位和屏蔽
可移植,合理提高效率 经常被优化成位操作

Slide 41
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

联合体是一个变量, 联合体是一个变量,不同的时 间表示不同的类型和大小的对 象,编译器会根据要求决定变 量的大小。 量的大小。

Slide 42
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

只有PS位被修改 只有 位被修改 联合体提供一种可以对单一存 贮区不同类型数据操作的方法 ,程序中没有嵌入任何依赖于 机器的信息 单指令写操作

Slide 43
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

? 利用向导创建一个新工程项目 ? 在新项目中加入或删除文件 ? 编译 ? 调试 ? 启动程序 ? PRM文件设置 ? 如何对IO及寄存器进行操作 ? 如何写中断程序 ? 嵌入式编程注意事项 ?Codewarrior 定购信息

TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

方法1 方法 :利用关键字 ‘interrupt’:
CodeWarrior 编译器提供了一种非ANSI标准的方式来实现 中断:

? 在 C 源文件中,中断服务程序前面加 “interrupt 中断向量号”
中断向量表分配 – MCU 数据手册 int time_counter; interrupt 7 INT_Timer(void) { time_counter ++; }
Vector Number 0 1 2 ... n Vector Address 0xFFFE - 0xFFFF 0xFFFC – 0xFFFD 0xFFFA – 0xFFFB ... 0xFFFF – ( n*2 ) Vector Address Size 2 2 2 ... 2

Slide 45
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

中断向量表分配 – MCU 数据手册

Slide 46
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

方法2: 方法 :在PRM文件中声明 文件中声明

在PRM文件中声明 文件中声明

?在C代码中写中断服务程序

#pragma TRAP_PROC void INCcount(void) { int card1; tcount++; }

文件中, 在 PRM 文件中,将中断服务 程序名和中断向量地址对应

VECTOR ADDRESS 0xFFF0 INCcount

Slide 47
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

方法3: 方法 :在向量表中初始化

语言文件中的常量表中初始化: 在C语言文件中的常量表中初始化 语言文件中的常量表中初始化

?在C代码中定义

#pragma CONST_SEG VectorTable void (*const procTable[])(void) = { intFunc1, intFunc2, intFunc3 } #pragma CONST_SEG DEFAULT

在PRM文件中分配 文件中分配

PLACEMENT VectorTable INTO READ_ONLY 0xFFFA TO 0xFFFF; … END

连接向量表

ENTRIES table END

Slide 48
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

利用interrupt关键字声明 关键字声明 利用 中断服务程序

Slide 49
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

用 RTI 而不是 RTS

函数指针

中断向量存储了中 断服务程序的起始 地址
Slide 50
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

? 利用向导创建一个新工程项目 ? 在新项目中加入或删除文件 ? 编译 ? 调试 ? 启动程序 ? PRM文件设置 ? 如何对IO及寄存器进行操作 ? 如何写中断程序 ? 嵌入式编程注意事项 ?Codewarrior 定购信息

TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

嵌入式编程 vs. PC编程 编程

嵌入式编程环境的主要特点: 嵌入式编程环境的主要特点:

? 有限的 有限的RAM; ; ? 有限的 有限的ROM; ; ? 有限的栈空间; 有限的栈空间; ? 面向硬件编程; 面向硬件编程; ? 严格的定时(ISR,任务,…); 严格的定时( ,任务, ); ? 很多不同种类的指针

(far/near/rom/uni/paged/…); ); ? 特殊关键字 标识符(@, 特殊关键字/标识符(@,interrupt,tiny,…) 标识符(@, , , )
Slide 52
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

数据类型
? 通过为变量选择最合适的数据类型可以最大程度地得到 最短的代码和执行时间 ? 8位微控制器内部的数据的长度是 位(一字节),然而 位微控制器内部的数据的长度是8位 一字节), ),然而 位微控制器内部的数据的长度是 C首选的数据类型是 首选的数据类型是‘int‘ 首选的数据类型是 ? 8位机处理 位数据类型比 位数据类型效率更高 位机处理8位数据类型比 位机处理 位数据类型比16位数据类型效率更高 ? “int“和大数据类型只有当所描述的数据的大小需要时 和大数据类型只有当所描述的数据的大小需要时 才使用 ? 当优先考虑代码效率时,双精度和浮点操作效率低,应 当优先考虑代码效率时,双精度和浮点操作效率低, 当避免
Slide 53
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

HC08的数据类型 的数据类型
ANSI标准没有精确定义数据类型的大小,但是 CodeWarrior 定义了 标准没有精确定义数据类型的大小, 定义了... 标准没有精确定义数据类型的大小

0

255

所有的数据类型 默认为有符号( 默认为有符号 除了 char)signed 例如: 例如 ‘int’ = ‘signed int’

Slide 54
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

默认CodeWarrior 的数据类型 默认
所有的基本数据类型可以被改变… 所有的基本数据类型可以被改变 但是建议尽量使用默认值

Slide 55
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

数据类型选择
对8位MCU, 在选择数据类型时,有3条原则:
> 尽量使用最小的数据类型 >尽可能使用无符号数 > 在表达式内声明数据类型,以便将数据类型减小到最小(强制类型 转换)

使用typedefs得到固定的大小 得到固定的大小 使用
- 根据编译器和系统而改变 - 移植到不同的机器代码不变 - 当值需要固定位时使用

Slide 56
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

函数里声明了3 在main函数里声明了 函数里声明了 种不同数据类型的变量

定义完整的数据类 型

Slide 57
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

仅最后面的位写入值; 仅最后面的位写入值 并且使用了一 个寄存器 每个变量的其余位被清零 clr ,X

变量在堆栈里有一个地址
Slide 58
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

在main函数里声明了 函数里声明了3 函数里声明了 种不同数据类型的变量

Slide 59
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

编译器仅仅为使用到的变量 保留存储空间, 保留存储空间,这个例子中 只有VarA被使用到了 只有 被使用到了

Slide 60
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

所有声明的全局变量均 被使用。 被使用。

Slide 61
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

在这种情况下, 在这种情况下,编译器 为所有变量保留了内存

Slide 62
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

根据变量大小的不同, 根据变量大小的不同, 每个加操作用不同的方 法完成

变量声明的内存区,每个变量有不同的大小( 变量声明的内存区,每个变量有不同的大小(1 Slide 63 字节) 、2和4字节) 和 字节
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

修饰符
以下关键字用于声明变量,以指定特定需要或内存中变量 存贮的相关条件。 Static volatile const 这三个关键字,一起让我们不仅可写出好的代码,而且可 写出紧凑的代码

Slide 64
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

静态变量
使用静态变量有二个主要功能: ? 第一个最常用的用法是定义一个变量,在函数连续调用期 间,变量不会消失。 ? 第二个使用静态的用法是限制变量的范围。在模块级定义 时,能被整个模块中所有函数访问,不能被其它模块中的 函数访问
这些变量不 会存贮在堆 栈中

Slide 65
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

静态变量示例
在第一次进入 MyFunction 函数之 前, myVar = 0

FILE1.c

FILE2.c void MyFunction (void){ //Definition of MyFunction in FILE2.C static char myVar = 0; //local variable declared static myVar = myVar + 1; }

#include <FILE2.h> //includes functions contained in file //FILE2.c void main (void){ MyFunction(); //included in FILE2.c MyFunction(); //included in FILE2.c }

在第二次进入 MyFunction之前: myVar = 1

静态变量会保持它的 值,尽管 myVar 是 局部变量

Slide 66
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

静态函数
? 静态函数只能被其所在模块中的其它函数调用 ? 使用静态函数是结构化编程的好习惯 ? 静态函数能产生小而快的代码 ? 编译器在编译时确切地知道什么函数能调用一个给
定的静态函数。因此,函数的相关内存区域能被调 整,以致使用调用的一个短版本或跳转指令

Slide 67
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

Volatile变量 Volatile变量
Volatile变量 变量其值在正常程序流程以外可能改变的变量 变量 在嵌入式系统中,这种情况通过两种主要途径发生: ? 通过一个中断服务程序 ? 硬件动作的结果 例如,通过一个串口接收到一个字符,结果串口状态寄存 器更新,这完全在程序流程之外发生。很多程序员知道编 译器不会试图优化一个volatile寄存器,而宁可每次重载它
在嵌入式设备中,将所 有外设寄存器声明为 volatile是一个好习惯

Slide 68
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

volatile的变量从不会被编译器优化 的变量从不会被编译器优化
访问定义为volatile的变量从不会被编译器优化 的变量从不会被编译器优化 访问定义为

volatile unsigned char PORTA @0x00; volatile unsigned char SCS1 @0x16; unsigned char value; void main(void){ PORTA = 0x05; */ PORTA = 0x05; */ SCS1; value = 10; } /* PORTA = 00000101 /* PORTA = 00000101

不用Volatile 关键字 不用
MOV LDA STA #5,PORTA #10 @value

用Volatile 关键字
MOV MOV LDA LDX STX #5,PORTA #5,PORTA SCS1 #10 @value

Slide 69
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

Volatile 变量示例

/* MC68HC908GP20/32 volatile volatile volatile volatile volatile volatile volatile volatile volatile volatile unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned unsigned

Official Peripheral Register Names */ PORTA PORTB PORTC PORTD PORTE DDRA DDRB DDRC DDRD DDRE @0x0000; /* Ports and data direction */ @0x0001; @0x0002; @0x0003; @0x0008; @0x0004; /* Data Direction Registers */ @0x0005; @0x0006; @0x0007; @0x000C; @0x000D; /* Port pull-up enables */ @0x000E; @0x000F;

char char char char char char char char char char

volatile unsigned char PTAPUE volatile unsigned char PTCPUE volatile unsigned char PTDPUE

Slide 70
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

Const 变量
? Const声明可用于任何变量,它告诉编译器将其存贮在 声明可用于任何变量, 声明可用于任何变量 ROM区中 区中 ? 编译器保留了那个位置程序存贮器地址。由于位于 编译器保留了那个位置程序存贮器地址。由于位于ROM 中,其值不能改变 ? Const变量必须初始化 变量必须初始化 比如: 比如 const double PI = 3.14159265;

Slide 71
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

Const修饰符 修饰符
Const 变量与明显的常数相对,很多文章要求用const变量代替明显的常数。 例如: 用const unsigned char channels = 8;代替#define CHANNELS 8 。 本方法的基本原理是在调试器内部,你能检查一个const变量,然而一个明 显的常数不可访问。不幸的是,在很多8位机上你将为这一好处付出极大的 代价。这两个主要代价是: ? 一些编译器在RAM中创建一个真实的变量来支持cost变量,这是一个极大 的惩罚。 ? 一些编译器如CodeWarrior,知道变量为const,将把变量存贮在ROM中。 无论怎样,变量仍作为变量处理和访问,典型地用某些变址寻址(16位)的 方式。与直接寻址(8位)方式相比,这种方法通常很慢。

Slide 72
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

Const volatile 变量
一个变量既能是常量,又能是可变量吗? 一个变量既能是常量,又能是可变量吗? 答案是“能 。 答案是 能”。 这个修饰符应该用于能出乎意料地改变的任何存贮器位置, 这个修饰符应该用于能出乎意料地改变的任何存贮器位置,因此 需要volatile限定语,由于 限定语, 该变量是只读的。 需要 限定语 由于const该变量是只读的。 该变量是只读的 最明显的例子是硬件状态寄存器, 状态寄存器SCS1。这 最明显的例子是硬件状态寄存器,象SCI状态寄存器 状态寄存器 。 个寄存器包含信号状态标志,如发送空、发送完成、 个寄存器包含信号状态标志,如发送空、发送完成、接收满以及 其它。 其它。这是一个可变寄存器由于这些标志的改变依赖于串行通信 的状态,这也是只读,由于标志不能被程序直接改写,它们只对 的状态,这也是只读,由于标志不能被程序直接改写, 模块的状态作出响应。这个状态寄存器最佳声明方法是: 模块的状态作出响应。这个状态寄存器最佳声明方法是: /* SCI Status Register */ const volatile unsigned char SCS1 @0x0016
Slide 73
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

? 利用向导创建一个新工程项目 ? 在新项目中加入或删除文件 ? 编译 ? 调试 ? 启动程序 ? PRM文件设置 ? 如何对IO及寄存器进行操作 ? 如何写中断程序 ?嵌入式编程注意事项 ?Codewarrior 定购信息

TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

Special Edition
Special Edition Features:
? ? ? CodeWarrior IDE with Project Wizard Project management for up to 32 files Unrestricted macro assembler/absolute addressing assembler and source level debugger Emulator-like complex debug capability Highly optimized ANSI C compiler and C source level debugger for Freescale’s HC(S)08 derivatives (16K of code) Fast Flash programming: ? HC08: Via MON08 ? HC(S)08: Via serial monitor or BDM ? ? Full-chip Simulator Auto assembly or C code generation of peripheral initialization code with Device Initialization from Unis Auto C code generation for most HC(S)08 peripherals with Processor Expert from Unis Supports parallel, USB and serial monitor solutions
Slide 75
TM

Licensing Procedure:
? Key is permanent, free of charge and automatically installed with the software

Support:
? 1 year support included

? ?

C-Compiler Upgrades:
? ? 32K C upgrade 64K C upgrade

?

Availability:
? On WEB–NOW ? From LDC (CWX-HXX-SE) – NOW

?

?

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

Standard and Professional Editions
Standard Edition
All Features of Special Edition Plus: ? Unlimited C Compiler and Debugger ? Unlimited Data Visualization ? No limit on the number of files in projects and subprojects ? Access to Unis’ software and external peripheral beans Add-On Options: ? C++/EC++/cC++ compiler/debugger Technical Support: ? One year support included Licensing: ? Registration on the Web for a permanent license key

Professional Edition
All the Features of the Standard Edition Plus: ? C++/EC++/cC++ compiler/debugger ? Code coverage ? Profile analysis ? Encryption support ? Bean Wizard to build a software library that can retarget to any HC(S)08, HC(S)12 or DSC derivative ? Advanced Processor Expert beans ? OSEK kernel awareness ? Decoder ? Session record and replay ? PC-lint plug-in Technical Support: ? One year support included Licensing: ? Registration on the Web for a permanent license key

Slide 76
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

How to Get Started?
? Go to: freescale.com/cw5 ? Download the Software:
? Fill in the short questionnaire ? Immediately, you can download the .exe file containing the CodeWarrior software

? Install CodeWarrior
Use Quick Start to create first project Run the tutorials
? ? ? ? ? C Tutorial Assembly Tutorial Processor Expert C with Device Initialization Assembly with Device Initialization
Slide 77
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

Part Numbers for Everyone
Special Edition
? ? ? ? ? ? ? ? ? CWX-HXX-SE CWS-H08-C32K-CX CWS-H08-C64K-CX CWS-H08-C32K-LX CWS-H08-C64K-LX CWT-H08-C32K-UX CWT-H08-C64K-UX CWT-H08-C32K-LX CWT-H08-C64K-LX

Standard Edition
? ? ? ? ? ? ? CWS-H08-STDED-CX CWS-H08-STDED-UX CWS-H08-STDED-LX CWT-H08-STDED-TX CWT-H08-STDED-UX CWT-H08-STDED-LX CWX-H08-ENHNC-KX

Professional Edition
? ? ? ? CWS-H08-PROED-CX CWS-H08-PROED-LX CWT-H08-PROED-TX CWT-H08-PROED-LX

Others
? CWS-H08-CC-CX ? CWS-H08-CC-LX ? CWS-H08-DBG-CX

Slide 78
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

Pricing and Upgrades
? v5.1 Manufacturer Suggested Resale Price (MSRP)
32K Compiler: $495 64K Compiler: $995 Standard Edition: $2,394 Professional Edition: $4,794

? Upgrade Policy
If you have HC(S)08 v3.1 WITH current annual support, you can purchase v5.1 at 30 percent of MSRP If you have HC(S)08 v3.1 WITHOUT current annual support, you must purchase v5.1 at MSRP If you have HC(S)08 v5.0, there is NO cost to upgrade to V5.1

? Annual Support and Maintenance (after first year)
32K Compiler: $199 64K Compiler : $199 Standard Edition: $399 Professional Edition: $799

Slide 79
TM

Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005.

Slide 80
Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2005. Freescale Semiconductor Confidential Proprietary. Freescale? and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ? Freescale Semiconductor, Inc. 2004
TM


相关文章:
##_##'freescale codewarrior的PE中生成的宏定义
之后,我结合,芯片的 header file 一起看,发现'##'的作用就像是连接符号一样...codewarrior使用指南 214页 免费 Freescale Codewarrior ... 80页 1下载券 Codewar...
PPC烧写文件制作及烧写下载操作说明书
Freescale Codewarrior ... 80页 1下载券 Linux系统命令及其使用详... 39页 ...提示已经找到可烧写芯片,双击芯片信息,在器件信息项( Device Information)中...
CodeWarrior软件与编程的讲解(完整版)
CodeWarrior软件与编程的讲解(完整版)_计算机软件及应用_IT/计算机_专业资料。...硬连接发生于连接过程中,说明代码的时候。换句话说,如果一个函数被使用了,在...
飞思卡尔第四章
AVR Studio,Keil uVision, Freescale CodeWarrior 等...编程器的作用就是将单片机程序的机器码烧写到单片机...芯片引脚 请结合附录 III 详细了解开发板的基本结构...
CodeWarrior设置
CodeWarrior设置_计算机硬件及网络_IT/计算机_专业资料。CodeWarrior设置Browser 的地址: D:\Program Files\Freescale\CodeWarrior V8.8\PowerPC_EABI_Support\Initializatio...
Freescale S19文件格式
S19 文件格式介绍 ESE 实验室 S-record 格式文件是 Freescale CodeWarrior 编译器生成的后缀名为.S19 的程序文件, 是一段直接烧写进 MCU 的 ASCII 码,英文全称...
codewarrior5.1之64位安装说明
codewarrior5.1之64位安装说明_计算机软件及应用_IT/计算机_专业资料。codewarrior...\Program Files\Freescale\CodeWarrior for MicrocontrollersV6.2\Prog\gdi" 安装...
CodeWarrior 8.3 For DSC 使用方法 用PE来生成代码
CodeWarrior 8.3 For DSC 使用方法 用PE来生成代码_IT/计算机_专业资料。 今日...《Freescale8位单片机入... 22页 免费 codewarrior使用指南 219页 2下载券 Codew...
Codewarrior IDE使用指南
Codewarrior IDE使用指南_信息与通信_工程科技_专业资料。Freescale 调试环境CODEWARRIOR简介 Codewarrior IDE 使用指南 第一章 Codewarrior IDE 概述在软件开发过程中,...
CodeWarrior 开发环境快速入门-工程创建 for 9S12DG128B
Freescale Codewarrior 芯... 80页 2财富值 CodeWarrior使用指南 73页 免费如要投诉违规内容,请到百度文库投诉中心;如要提出功能问题或意见建议,请点击此处进行反馈。...
更多相关标签:
codewarrior烧写程序 | freescale 烧写 | codewarrior使用指南 | freescale芯片 | 芯片烧写培训教材 | 芯片烧写 | 芯片批量烧写 | 东芝芯片 烧写电路 |