富士通微电子 ( 上海 ) 有限公司应用笔记 MCU-AN-500002-Z-10 F²MC-8FX 家族 8 位微控制器 MB95200H/210H 系列 基本 FW 设置 应用笔记
变更履历 基本 FW 设置 V1.0 变更履历 日期作者修正记录 2008-03-26 Lori.Li V1.0, 第一版 本文档由 40 页构成 1. 本文档记载的产品信息及规格说明如有变动, 恕不预先通知 如需最新产品信息和 / 或规格说明, 联系富士通销售代表或富士通授权经销商 2. 基于本文档记载信息或示意图的使用引起的对著作权 工业产权或第三方的其他权利的侵害, 富士通不承担任何责任 3. 未经富士通明文批准, 不得对本文档的记载内容进行转让 拷贝 4. 本文档所介绍的产品并不旨在以下用途 : 需要极高可靠性的设备, 诸如航空航天装置 海底中继器 核控制系统或维系生命的医用设施 5. 本文档介绍的部分产品可能是 外汇及外贸管理法 规定的战略物资 ( 或专门技术 ), 出口该产品或其中部分元件前, 应根据该法获得正式批准 版权 2008 富士通微电子 ( 上海 ) 有限公司版权所有 MCU-AN-500002-Z-10 第 2 页
目录 目录 变更履历目录 1 概要 2 初始化程序 变更履历... 2 目录... 2 概要... 2 初始化程序... 2 2.1 初始化堆栈... 2 2.2 SP 和 DP 设置... 2 中断向量... 2 3 中断向量 3.1 中断级... 2 3.2 中断处理函数原型... 2 3.3 向量定义... 2 3.4 默认中断处理... 2 3.5 示例... 2 时钟控制器... 2 4 时钟控制器 4.1 时钟控制器的概要... 2 4.2 时钟控制器的框图... 2 4.3 寄存器... 2 时钟模式选择... 2 5 时钟模式选择 5.1 介绍... 2 5.2 主要特征... 2 5.3 主时钟... 2 5.4 副时钟... 2 5.5 主 CR 时钟... 2 5.6 副 CR 时钟... 2 5.7 时钟分频比... 2 待机模式选择... 2 6 待机模式选择 6.1 主要特征... 2 6.2 待机模式和时钟供给状态... 2 6.3 时钟模式和待机模式的组合... 2 6.4 休眠模式... 2 6.4.1 介绍... 2 MCU-AN-500002-Z-10 第 3 页
目录 6.4.2 休眠模式下的操作... 2 6.4.3 转换和解除... 2 6.5 停止模式... 2 6.5.1 介绍... 2 6.5.2 停止模式下的操作... 2 6.5.3 转换和解除... 2 6.6 时基定时器模式... 2 6.6.1 介绍... 2 6.6.2 时基定时器模式下的操作... 2 6.6.3 转换和解除... 2 6.7 计时模式... 2 6.7.1 介绍... 2 6.7.2 计时模式下的操作... 2 6.7.3 转换和解除... 2 6.8 待机模式转换代码... 2 附加信息... 2 附录... 2 7 附加信息 8 附录 8.1 图一览... 2 8.2 样本代码... 2 8.2.1 工程 1 名称 : Basic_Initialization... 2 8.2.2 工程 2 名称 : Clock_Change... 2 8.2.3 工程 3 名称 : Mode_Change... 2 MCU-AN-500002-Z-10 第 4 页
1 概要 基本 FW 设置 V1.0 第 1 章概要 本应用笔记介绍如何启动富士通 F 2 MC-8FX 家族 MB95200H/210H 系列的基本 FW 设置 本应用笔记介绍初始化程序 堆栈指针 (SP) 和直接寄存器组指针 (DP) 设置 时钟控制和待机控制 MCU-AN-500002-Z-10 第 5 页
2 初始化程序 基本 FW 设置 V1.0 第 2 章初始化程序 启动文件 startup.asm 是复位执行后的进入点 该文件包含编译器和器件操作的多个设置, 并且初始化堆栈和变量初始值 2.1 初始化堆栈 启动 MCU 时, 必须初始化堆栈, 并在堆栈区设置堆栈容量和区域 初始化样本代码 : //Sample code for initialization //definition to stack area.section STACK, STACK, ALIGN=1.RES.B 128-2 STACK_TOP:.RES.B 2 注 : 以上代码从 start.asm 截取 详情参照附录 2.2 SP 和 DP 设置 SP 和 DP 是专用寄存器 堆栈指针 (SP) 是 16 位寄存器 该堆栈指针保持中断 / 子程序调用 入栈 / 出栈指令等的参考地址 复位后的初始值是 "0000H" DP 代表直接组指针 程序状态 (PS) 寄存器的 10~8 位的直接组指针 (DP) 用于指定直接寻址访问的地址区 初始化样本程序 : // set the stack pointer MOVW MOVW A, #STACK_TOP SP, A // Set Register bank Pointer 0 / set Direct bank Pointer 0 (0x80...0xFF) // The PS register consists of the register bank pointer (RP), direct // pointer (DP), and condition code register (CCR). MOVW A, PS MOVW A, #0x07FF // RP=0, DP=0, I=0 ANDW MOVW A PS, A 注 : 以上代码从 start.asm 截取 详情参照附录 MCU-AN-500002-Z-10 第 6 页
3 中断向量 基本 FW 设置 V1.0 第 3 章中断向量 启动基本 FW 设置时, 必须初始化中断向量 vector.c 是给用户提供的 C 文件 该 C 文件包含中断级和中断号声明及其默认中断处理程序, 也可初始化对应的中断控制寄存器 3.1 中断级 在文件 vector.c 中, 首先定义了中断级函数 void InitIrqLevels (void): void InitIrqLevels (void) ILR0 = 0Xff // IRQ0: external interrupt ch.4 --> 01 // IRQ1: external interrupt ch.5 --> 01 // IRQ2: external interrupt ch.2/ch.6 --> 01 // IRQ3: external interrupt ch.3/ch.7 --> 01... 注 : 以上代码从 vector.c 截取 详情参照附录 该函数的功能是初始化中断控制寄存器 中断控制寄存器定义各中断通道的中断级 FF 代表最低的优先级 3.2 中断处理函数原型 中断处理程序的函数原型在中断级初始化后声明 : interrupt void DefaultIRQHandler (void) // Add your own prototypes here like above. 注 : 以上代码从 vector.c 截取 详情参照附录 3.3 中断向量定义 中断向量表与中断处理函数相对应 对于未使用的中断, 请使用默认中断处理程序 : #pragma intvect DefaultIRQHandler 0 //IRQ0: external interrupt ch.4 #pragma intvect DefaultIRQHandler 1 //IRQ1: external interrupt ch.5 #pragma intvect DefaultIRQHandler 2 //IRQ2: external interrupt ch.2/ch.6 #pragma intvect DefaultIRQHandler 3 //IRQ3: external interrupt ch.3/ch.7 注 : 以上代码从 vector.c 截取 详情参照附录 MCU-AN-500002-Z-10 第 7 页
3.4 默认中断处理程序 基本 FW 设置 V1.0 第 3 章中断向量 默认中断处理函数在 vector.c 文件的最后列出 该函数停止系统的运行 为了方便程序调试, 在此设置断点以检测未初始化的中断 默认中断处理程序的样本代码 : //default interrupt handler interrupt void DefaultIRQHandler (void) 注 : 以上代码从 vector.c 截取 详情参照附录 3.5 示例 DI (); While (1) wait_nop (); 在使用中断时需要修改中断向量表, 例如, 将外部中断 ch4 设置为 key_in, 请修改 vector.c 中的代码 #pragma intvect Key_in 1 // IRQ0: external interrupt ch4 注 : 以上代码从 vector.c 截取 详情参照附录 中断级定义 : // defines the interrupt levels void InitIrqLevels (void) ILR0=0xFC // IRQ0: external interrupt ch.4 --> Level 00 // IRQ1: external interrupt ch.5 --> 01 // IRQ2: external interrupt ch.2 ch.6 --> 01 // IRQ3: external interrupt ch.3 ch.7 --> 01... // elide the following code 注 : 以上代码从 vector.c 截取 详情参照附录 在文件 main.c 中, 添加中断处理函数为 interrupt void Key_Int (void) //interrupt response function _interrupt void Key_int (void) // key_int external interrupt ch.4 // enter your interrupt handler function(s) here 注 : 以上代码从 vector.c 截取 详情参照附录 // disable interrupts // halt system MCU-AN-500002-Z-10 第 8 页
第 4 章时钟控制器 4 时钟控制器 本节介绍时钟控制器的功能和操作 4.1 时钟控制器的概要 F 2 MC-8FX 家族产品内置降低功耗的时钟控制器 该家族产品既有支持外部主时钟和外部副时钟的双外部时钟产品又有支持外部主时钟的单外部时钟产品 时钟控制器具有以下功能 : 使能 / 禁止时钟振荡 使能 / 禁止内部电路的时钟信号供给 选择时钟源 控制内部 CR 振荡器和分频电路 4.2 时钟控制器的框图 图 4.2-1 时钟控制器的框图 MCU-AN-500002-Z-10 第 9 页
4.3 寄存器 基本 FW 设置 V1.0 第 4 章时钟控制器 时钟控制器由 4 个寄存器构成 : 系统时钟控制寄存器 (SYCC) 待机控制寄存器 (STBC) 系统时钟控制寄存器 2 (SYCC2) 和振荡稳定等待时间设置寄存器 (WATR) 详情参照 MCU MB95200H/210H 系列硬件手册的第 6 章 图 4.3-1 显示的是系统时钟控制寄存器 (SYCC) 的配置 该寄存器用于控制机器时钟分频比选择 Address bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 Initial value 0007 H - - - - SRDY - DIV1 DIV0 0000X011 B R0/WX R0/WX R0/WX R0/WX R/WX R0/WX R/W R/W 图 4.3-1 系统时钟控制寄存器 (SYCC) 的配置 图 4.3-2 显示的是振荡稳定等待时间设置寄存器 (WATR) 的配置 该寄存器用于设置振荡稳定等待时间 Address bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 Initial value 0005 H SWT3 SWT2 SWT1 SWT0 MWT3 MWT2 MWT1 MWT0 11111111 B R/W R/W R/W R/W R/W R/W R/W R/W 图 4.3-2 振荡稳定等待时间设置寄存器 (WATR) 的配置 图 4.3-3 显示待机控制寄存器 (STBC) 的配置 该寄存器用于控制从运行状态到休眠模式 停止模式 时基定时器模式或计时模式的转换 该寄存器还设置停止 时基定时器和计时模式下的引脚状态, 并控制软件复位的发生 Address bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 Initial value 0008 H STP SLP SPL SRST TMD SCRDY MCRDY MRDY 00000XXX B R0/W R0/W R/W R0/W R0/W R/WX R/WX R/WX 图 4.3-3 待机控制寄存器 (STBC) 图 4.3-4 显示的是系统时钟控制寄存器 2 (SYCC2) 的配置 该寄存器用于显示和切换当前时钟模式, 控制副时钟 主时钟 副 CR 时钟 主 CR 时钟和主时钟振荡 Address bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 Initial value 000D H RCM1 RCM0 RCS1 RCS0 SOSCE MOSCE SCRE MCRE 10100011 B R/WX R/WX R/W R/W R/W R/W R/W R/W 图 4.3-4 系统时钟控制寄存器 2 (SYCC2) 的配置 R/W: 可读 / 可写 ( 读值与写值相同 ) R/WX: 只读 ( 可读, 写操作无效 ) R0/WX: 未定义位 ( 读值为 0, 写值无效 ) R0/W: 只写 ( 可写, 读 0 ) MCU-AN-500002-Z-10 第 10 页
第 5 章时钟模式选择 5 时钟模式选择 5.1 介绍 可使用 4 个时钟 ( 主时钟 副时钟 主 CR 时钟和副 CR 时钟 ) 进行各种分频选择 ( 外部单时钟产品仅有 3 个时钟 ) 5.2 主要特征 5.3 主时钟 可选主时钟源 外部主时钟 ( 频率高达 32.5 MHz 且最大机器时钟频率为 16.25 MHz) 内部主 CR 时钟 (1/8/10/12.5 MHz) 可选副时钟源 外部副时钟 (32.768 khz) 副 OSC 时钟 (32.768 khz) 内部副 CR 时钟 ( 典型 100 khz, 最小 50 khz, 最大 200 khz) 内部时钟是主 CR 时钟 (8 MHz) 主时钟是外部主时钟 外部时钟的最大频率为 32.5 MHz, 最大机器时钟频率为 16.25 MHz 可修改 SYCC2_MOSCE 以使能主时钟 修改 SYCC2_RCS 以选择主时钟模式 修改 WATR 以改变振荡稳定等待时间并检测 STBC_MRDY 以表明主时钟振荡是否稳定 若将 WATR 设置为 0x0F, 振荡稳定等待时间则为 (2 14-2)/F CH, 约 4.10 ms 以下代码显示如何操作主时钟, 具体包括使能主时钟 转换为主时钟模式 更新振荡稳定等待时间 等待振荡稳定 // enable the Main clock oscillation SYCC2_MOSCE = 1; // Clock Mode Selection, select the main clock mode SYCC2_RCS0 = 0x01; SYCC2_RCS1 = 0x01; //update Oscillation Stabilization Wait Time //when Main Oscillation Clock F CH =4MHz WATR = 0X0F; // Oscillation Stabilization Wait Time mean // (2 14-2)/F CH About 4.10 ms While (!STBC_MRDY);//Indicates main clock oscillation being stable 注 : 以上代码从工程 Clock_Change 截取 详情参照附录 MCU-AN-500002-Z-10 第 11 页
5.4 副时钟 基本 FW 设置 V1.0 第 5 章时钟模式选择 副时钟是外部副时钟 外部副时钟的最大频率为 32.768 khz, 相应地副时钟频率为 32.768 khz 可更新 SYCC2_SOSCE 以使能副时钟 更新 SYCC2_RCS 以选择副时钟模式 更新 WATR 以改变振荡稳定等待时间 检测 SYCC_SRDY 以表明副时钟振荡是否稳定 若将 WATR 设置为 0xF0, 则振荡稳定等待时间为 (2 15-2)/F CL, 约 1.00 s 以下代码显示如何操作副时钟, 具体包括如何使能副时钟 转换到副时钟模式 修改振荡稳定等待时间和等待振荡稳定 // enable the sub-clock oscillation SYCC2_ SOSCE = 1; // Clock Mode Selection, select the sub-clock mode SYCC2_RCS0 = 0x01; SYCC2_RCS1 = 0x00; //Update the Oscillation Stabilization Wait Time // when sub Oscillation Clock F CL =32.768 khz WATR = 0xF0; //(2 15-2)/F CL About 1.00s while (!SYCC_SRDY); //Indicates sub-clock oscillation being stable 注 : 以上代码从工程 Clock_Change 截取 详情参照附录 MCU-AN-500002-Z-10 第 12 页
5.5 主 CR 时钟 基本 FW 设置 V1.0 第 5 章时钟模式选择 主 CR 时钟有 4 种内部主时钟频率选择 : 1 MHz 8 MHz 10 MHz 和 12.5 MHz 更新 NVR 可改变主 CR 时钟 可更新 SYCC2_MCRE 以使能主 CR 时钟 更新 SYCC2_RCS 以选择主 CR 时钟模式 检测 STBC_MCRDY 以表明主 CR 时钟振荡是否稳定 以下代码显示如何操作主 CR 时钟, 具体包含如何使能主 CR 时钟 转换到主 CR 时钟模式 更新振荡稳定等待时间和等待振荡稳定的 //change the main CR clock frequency MOV A, 0x0FE4; //READ CRTH for NVR trimming value protect AND A, #0x9F; //Just CLEAR CRTH [6:5] OR A, #0x60; //Main CR clock update to 8MHz //Can update the Main CR clock as below setting //0x00: 1MHz; 0x20: 12.5MHz; 0x40: 10MHz; 0x60: 8MHz MOV 0x0FE4, A; //WRITE CRTH to enable the update // enable the main CR clock oscillation SYCC2_ MCRE = 1; // Clock Mode Selection, select the main CR clock mode SYCC2_RCS0 = 0x00; SYCC2_RCS1 = 0x01; //update the Oscillation Stabilization Wait Time //F CRHS represents the main clock frequency //2 8 /F CRHS = Main CR oscillation Stabilization Wait Time while(!stbc_mcrdy);//indicates main CR clock oscillation being stable 注 : 以上代码是从 project1 start.asm 和工程 Clock_Change 截取的 详情参照附录 振荡稳定等待时间根据 CR 启动时序变化 主 CR 振荡稳定等待时间 = 2 8 /F CRHS. F CRHS 代表主 CR 时钟频率 MCU-AN-500002-Z-10 第 13 页
5.6 副 CR 时钟 基本 FW 设置 V1.0 第 5 章时钟模式选择 副 CR 时钟是内部单时钟 该时钟的典型时钟频率为 100 khz 最小频率为 50 khz 最大频率为 200 khz 可更新 SYCC2_SCRE 以使能副 CR 时钟 更新 SYCC2_RCS 以选择副 CR 时钟模式 检测 STBC_SCRDY 以表明副 CR 时钟振荡是否稳定 以下代码显示如何操作副 CR 时钟, 具体包含如何使能副 CR 时钟 改变副 CR 时钟模式 更新振荡稳定等待时间和等待振荡稳定 // enable the Sub-CR Clock oscillation SYCC2_ SCRE = 1; // Clock Mode Selection, select the Sub-CR Clock mode SYCC2_RCS0 = 0x00; SYCC2_RCS1 = 0x00; //update the Oscillation Stabilization Wait Time //F CRHS represents the main clock frequency //2 4 /F CRL = Sub-CR oscillation Stabilization Wait Time while (!STBC_SCRDY); //Indicates sub-cr clock oscillation being stable 注 : 上记代码从工程 Clock_Change 中截取 详情参照附录 振荡稳定等待时间根据 CR 启动时序变化 主 CR 振荡稳定等待时间 = 2 4 /F CRL. F CRL 代表副 CR 时钟频率 5.7 时钟分频比 机器时钟由源时钟根据分频比生成 可通过设置 SYCC_DIV 分频源时钟 若设置 SYCC_DIV 为 0x11, 则 16 分频源时钟 以下代码显示如何设置时钟分频比 : //source clock can be main clock divided by 2, sub-clock divided by 2, //sub-cr clock divided by 2 or main CR clock no div SYCC_DIV = 0x00; // Source clock (No division) // SYCC_DIV = 0x01 mean Source clock/4 // SYCC_DIV = 0x02 mean Source clock/8 // SYCC_DIV = 0x03 mean Source clock/16 注 : 以上代码从工程 Clock_Change 截取 详情参照附录 MCU-AN-500002-Z-10 第 14 页
6 待机模式选择 基本 FW 设置 V1.0 第 6 章待机模式选择 待机模式包含 4 种模式 : 休眠模式 时基定时器模式 计时模式和停止模式 时钟控制器选择允许或禁止时钟振荡和根据待机模式为内部电路供给时钟 除时基定时器模式和计时模式以外, 待机模式的设置可与时钟模式无关 6.1 主要特征 低功耗模式 ( 待机模式 ) 停止模式 休眠模式 计时模式 时基定时器模式 初始模式 正常工作状态 6.2 待机模式和时钟供给状态 待机模式休眠模式时基定时器模式 计时模式 停止模式 时钟供给状态 停止为 CPU 供给时钟 其结果是 CPU 停止运行但其他外设功能继续运行 停止为其他电路提供时钟, 仅为时基定时器和计时预分频器提供时钟信号 其结果为除时基定时器 计时预分频器 外部中断和低压检测复位 ( 选项 ) 以外的其他功能都停止运行 时基定时器模式是主时钟模式和主 CR 时钟模式的唯一待机模式 停止主时钟振荡, 停止为其他电路提供时钟但为计时预分频器提供时钟信号 其结果为除计时预分频器 外部中断和低压检测复位 ( 选项 ) 以外的功能都停止运行 计时模式是副时钟模式和副 CR 时钟模式的唯一待机模式 停止主时钟振荡 副时钟振荡和全部时钟信号的供给 其结果为除外部中断和低压检测复位 ( 选项 ) 以外的全部功能都停止 图 6.2-1 待机模式和时钟供给状态 MCU-AN-500002-Z-10 第 15 页
6.3 时钟模式和待机模式的组合 基本 FW 设置 V1.0 第 6 章待机模式选择 图 6.3-1 列出了时钟模式和待机模式组合及其相应的内部电路工作状态 详情参照 MCU MB95200H/210H 系列硬件手册的第 6 章 图 6.3-1 待机模式和时钟模式的组合和内部工作状态注 : 到时钟模式的转换完成后再设置待机模式 MCU-AN-500002-Z-10 第 16 页
第 6 章待机模式选择 6.4 休眠模式 6.4.1 介绍 休眠模式下,CPU 和软件监视定时器停止工作 6.4.2 休眠模式下的操作 休眠模式下,CPU 和软件监视定时器的工作时钟停止运行 在该模式下,CPU 停止但转换到休眠模式前的寄存器和 RAM 的内容将被保留 除监视定时器以外的外设资源继续运行 6.4.3 转换和解除 在待机控制寄存器的休眠位 (STBC: SLP) 写 "1" 可使器件进入休眠模式 以下代码是从运行状态转换到休眠模式时 STBC 的设置 : STBC_SLP = 1; // Causes transition to sleep mode 注 : 上记代码从工程 Mode_Change 截取 请参照附录 器件因复位或外设功能的中断而解除休眠模式 6.5 停止模式 6.5.1 介绍 停止模式下, 主时钟停止工作 6.5.2 停止模式下的操作 停止模式下, 主时钟 主 CR 时钟和副时钟停止工作 在该模式下, 器件停止除外部中断和低压检测复位以外的全部功能, 但转换到停止模式前的寄存器和 RAM 的内容将被保留 6.5.3 转换和解除 在待机控制寄存器的停止位 (STBC: STP) 写 "1" 可使器件进入停止模式 此时, 待机控制寄存器的引脚状态设置位 (STBC: SPL) 为 "0" 时, 外部引脚的状态被保留 ; 该位为 "1" 时, 外部引脚的状态变为高阻状态 以下代码显示如何转换到停止模式 : STBC_STP = 1; //Causes transition to stop mode 注 : 上记代码从工程 Mode_Change 截取 请参照附录 复位或外部中断使器件退出停止模式 退出停止模式后, 若有必要, 初始化各外设资源 MCU-AN-500002-Z-10 第 17 页
第 6 章待机模式选择 6.6 时基定时器模式 6.6.1 介绍 时基定时器模式下, 仅主时钟振荡 副时钟振荡 时基定时器和计时预分频器运行 在该模式下,CPU 和外设资源的工作时钟停止运行 6.6.2 时基定时器模式下的操作 在时基定时器模式下, 主时钟仅供给时基定时器 器件停止除时基定时器 外部振荡和电压检测复位以外的全部功能, 但转换到时基定时器模式前的寄存器和 RAM 的内容将被保留 6.6.3 转换和解除 转换到时基定时器模式 : 将 SYCC2_RCS 设置为 0x02 或 0x03 并在待机控制寄存器的计时位 (STBC: TMD) 写 "1" 以下代码显示如何转换到时基定时器模式 : SYCC2_RCS0 = 0x00; SYCC2_RCS1 = 0x01; STBC_TMD = 1; // Causes the device to enter timebase timer mode 注 : 以上代码从工程 Clock_Change 截取 详情参照附录 退出时基定时器模式 : 复位 时基定时器中断或外部中断可使器件退出时基定时器模式 退出时基定时器模式后, 若有必要, 初始化各外设资源 MCU-AN-500002-Z-10 第 18 页
第 6 章待机模式选择 6.7 计时模式 6.7.1 介绍 计时模式下, 仅副时钟 副 CR 时钟和计时预分频器工作 在该模式下,CPU 和外设资源的工作时钟停止运行 6.7.2 计时模式下的操作 在计时模式下,CPU 和外设资源的工作时钟停止运行 器件停止除计时预分频器 外部中断和低压检测复位以外的全部功能, 但转换到计时模式前的寄存器和 RAM 的内容将被保留 6.7.3 转换和解除 转换到计时模式 : 将 SYCC2_RCS 设置为 0x00 或 0x01 并在待机控制寄存器的计时位 (STBC: TMD) 写 "1" 时钟模式为副时钟模式或副 CR 时钟模式时, 器件才可进入计时模式 SYCC2_RCS0 = 0x00; SYCC2_RCS1 = 0x00; STBC_TMD = 1; // Causes the device to enter watch mode 注 : 以上代码从工程 Mode_Change 截取 详情参照附录 退出计时模式 : 复位 计时中断或外部中断可使器件退出计时模式 退出计时模式后, 若有必要, 初始化各外设资源 MCU-AN-500002-Z-10 第 19 页
6.8 待机模式转换代码 基本 FW 设置 V1.0 第 6 章待机模式选择 以下代码可实现待机模式间的转换, 例如停止模式 计时模式 可将切换模式更新为所希望的模式 //The following code can realize the transition of the standby mode from //one to another mode, such as a stop mode, a watch mode //The following software is for demonstration purpose only #define switchmode normal //set transition to some standby modes // Can define the switchmode to Stop, Sleep, Watch or Timebase void main (void) MCU_initialization(); while(1) // choice standby mode what you want transition to switch (switchmode) case normal: case stop: STBC_STP = 1; case sleep: STBC_SLP = 1; 注 : 以上代码从工程 Mode_Change 截取 详情参照附录 //normal to stop mode //normal to sleep mode case watch: SYCC2_SOSCE = 1; //Enable Sub Clock SYCC2_RCS0 = 0x01; //Select Sub Clock SYCC2_RCS1 = 0x00; //Select Sub Clock WATR = 0xF0; //About 1.00s Wait Time while (!SYCC_SRDY); //Wait Clock stable STBC_TMD = 1; //normal to watch mode case Timebase: SYCC2_MOSCE = 1; //Enable Main Clock default: SYCC2_RCS0 = 0x01; //Select Main Clock SYCC2_RCS1 = 0x01; //Select Main Clock WATR = 0X0F; // About 4.10ms Wait Time while (!STBC_MRDY); //Wait Clock stable STBC_TMD = 1; //normal to timebase time mode MCU-AN-500002-Z-10 第 20 页
第 7 章附加信息 7 附加信息 关于富士通微电子更多的产品信息, 请访问以下网站 : MCU-AN-500002-Z-10 第 21 页
第 8 章附录 8 附录 8.1 图一览 图 4.2-1 时钟控制器的框图... 2 图 4.3-1 系统时钟控制寄存器 (SYCC) 的配置... 2 图 4.3-2 振荡稳定等待时间设置寄存器 (WATR) 的配置... 2 图 4.3-3 待机控制寄存器 (STBC)... 2 图 4.3-4 系统时钟控制寄存器 2 (SYCC2) 的配置... 2 图 6.2-1 待机模式和时钟供给状态... 2 图 6.3-1 待机模式和时钟模式的组合和内部工作状态... 2 MCU-AN-500002-Z-10 第 22 页
第 8 章附录 8.2 样本代码 8.2.1 工程 1 名称 : Basic_Initialization 名称 : 功能 : 初始化 MCU Start.asm ;========================================================================== ; F 2 MC-8FX Family SOFTUNE C Compiler sample startup routine, ; ALL RIGHTS RESERVED, COPYRIGHT (C) FUJITSU LIMITED 2008 ; LICENSED MATERIAL - PROGRAM PROPERTY OF FUJITSU LIMITED ;========================================================================== ; Sample code for initialization.program start.title start ; variable define declaration ; #define HWD_DISABLE ; if define this, Hard Watchdog will disable. ; external declaration of symbols.export start.import _main.import LMEMTOMEM.IMPORT LMEMCLEAR.IMPORT _RAM_INIT.IMPORT _ROM_INIT.IMPORT _RAM_DIRINIT.IMPORT _ROM_DIRINIT ; definition to stack area.section STACK, STACK, ALIGN=1.RES.B 128-2 STACK_TOP:.RES.B 2 ; definition to start address of data, const and code section MCU-AN-500002-Z-10 第 23 页
第 8 章附录.SECTION DIRDATA, DIR, ALIGN=1.SECTION DIRINIT, DIR, ALIGN=1.SECTION DATA, DATA, ALIGN=1.SECTION INIT, DATA, ALIGN=1 ; The Mode Byte is defined at the beginning of the start.asm.section RESVECT, CONST, LOCATE=H'FFFD.DATA.B 0.DATA.W start //code area.section CODE, CODE, ALIGN=1 start: ; set stack pointer MOVW A, #STACK_TOP MOVW SP, A ; Set Register bank Pointer 0 MOVW A, PS MOVW A, #0x07FF // RP=0, DP=0, I=0 ANDW A MOVW PS, A ; Set ILM to the lowest level (3) MOVW A, PS MOVW A, #0x0030 ORW A MOVW PS, A ; copy initial value *CONST (ROM) section to *INIT(RAM) section #macro ICOPY src_addr, dest_addr, src_section MOVW EP, #\src_addr MOVW A, #\dest_addr MCU-AN-500002-Z-10 第 24 页
第 8 章附录 MOVW A, #SIZEOF(\src_section) CALL LMEMTOMEM #endm ICOPY _ROM_INIT, _RAM_INIT, INIT ICOPY _ROM_DIRINIT, _RAM_DIRINIT, DIRINIT ; zero clear of *VAR section #macro FILL0 src_section MOVW A, #\src_section MOVW A, #SIZEOF (\src_section) CALL LMEMCLEAR #endm FILL0 DIRDATA FILL0 DATA ; call main routine CALL _main End: JMP end ; Hard Watchdog #ifdef HWD_DISABLE.SECTION WDT, CONST, LOCATE=H'FFBE.DATA.W 0xA596 #endif ; reset vector.section RESET, CONST, LOCATE=0xFFFC.DATA.B 0xFF.DATA.B 0.DATA.H start.end start MCU-AN-500002-Z-10 第 25 页
名称 : vector.c 功能 : 中断级 ( 优先级 ) 设置和中断向量定义 基本 FW 设置 V1.0 第 8 章附录 ;************************************************************************* ; ALL RIGHTS RESERVED, COPYRIGHT (C) FUJITSU LIMITED 2008 ; LICENSED MATERIAL - PROGRAM PROPERTY OF FUJITSU LIMITED /************************************************************************* NAME: vector.c FUNCTION: Interrupt level (priority) setting Interrupt vector definition *************************************************************************/ #include "mb95200.h" ;----------------------------------------------------------------------- //This function pre-sets all interrupt control registers. It can be used //to set all interrupt priorities in static applications. If this file // contains assignments to dedicated resources, verify that the appropriate //controller is used. //----------------------------------------------------------------------- void InitIrqLevels (void) ILR0 = 0xFC; // IRQ0: external interrupt ch.4 --> Level 00 // IRQ1: external interrupt ch.5 --> 01 // IRQ2: external interrupt ch.2/ch.6 --> 01 // IRQ3: external interrupt ch.3/ ch.7--> 01 ILR1 = 0xFF; // IRQ4: UART/SIO ch.0 // IRQ5: 8/16-bit timer ch.0 (lower) // IRQ6: 8/16-bit timer ch.0 (upper) // IRQ7: LIN-UART (reception) ILR2 = 0xFF; // IRQ8: LIN-UART (transmission) // IRQ9: 8/16-bit PPG ch.1 (lower) / UART/SIO ch.1 // IRQ10: 8/16-bit PPG ch.1 (upper) / I 2 C ch.1 // IRQ11: 16-bit reload timer ch.0 ILR3 = 0xFF; // IRQ12: 8/16-bit PPG ch.0 (upper) // IRQ13: 8/16-bit PPG ch.0 (lower) // IRQ14: 8/16-bit timer ch1 (upper) // IRQ15: 16-bit PPG ch.0 + ch.2 ILR4 = 0xFF; // IRQ16: 16-bit reload timer ch.1 / I 2 C ch.0 // IRQ17: 16-bit PPG ch.1 // IRQ18: 10-biat A/D-converter // IRQ19: Timebase timer ILR5 = 0xFF; // IRQ20: Watch timer / counter MCU-AN-500002-Z-10 第 26 页
基本 FW 设置 V1.0 第 8 章附录 // IRQ21: external interrupt ch 8-11 // IRQ22: 8/16-bit timer ch1 (lower) / external //interrupt ch.12-15 // IRQ23: Flash Custom ch.1 //----------------------------------------------------------------------- // Prototypes // Add your own prototypes here. Each vector definition needed is a //prototype. Either do it here or include a header file containing them. //----------------------------------------------------------------------- //extern unsigned int delay_timer; interrupt void DefaultIRQHandler (void); interrupt void Key_int (void); //----------------------------------------------------------------------- //Vector definition //Use the following statements to define vectors. //All resources related to the vectors are predefined. //Remaining software interrupts can be added here as well. //----------------------------------------------------------------------- #pragma intvect Key_int 0 //IRQ0: external interrupt ch.4 #pragma intvect DefaultIRQHandler 1 //IRQ1: external interrupt ch.5 #pragma intvect DefaultIRQHandler 2 //IRQ2: external interrupt ch.2 ch.6 #pragma intvect DefaultIRQHandler 3 //IRQ3: external interrupt ch.3 ch.7 #pragma intvect DefaultIRQHandler 5 //IRQ5: 8/16-bit timer ch.0 (lower) #pragma intvect DefaultIRQHandler 6 //IRQ6: 8/16-bit timer ch.0 (upper) #pragma intvect DefaultIRQHandler 7 //IRQ7: LIN-UART (reception) #pragma intvect DefaultIRQHandler 8 //IRQ8: LIN-UART (transmission) #pragma intvect DefaultIRQHandler 14 //IRQ14: 8/16-bit timer ch1 (upper) #pragma intvect DefaultIRQHandler 18 //IRQ18: 10-biat A/D-converter #pragma intvect DefaultIRQHandler 19 //IRQ19: Timebase timer #pragma intvect DefaultIRQHandler 20 //IRQ20:Watchtimer/ counter #pragma intvect DefaultIRQHandler 22 //IRQ22: 8/16-bit timer ch.1 //(lower)/interrupt ch.12-15 #pragma intvect DefaultIRQHandler 23 //IRQ23: Flash / Custom ch.1 interrupt void DefaultIRQHandler (void) DI (); While (1) wait_nop (); // disable interrupts // halt the system MCU-AN-500002-Z-10 第 27 页
名称 : Main.c 功能 : 用按键作为外部中断的输入 基本 FW 设置 V1.0 第 8 章附录 /* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS.*/ /*FUJITSU MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY*/ /*ERRORS OR ELIGIBILITY FOR ANY PURPOSES. */ /* (C) Fujitsu Microelectronics (Shanghai) Co., LTD. */ /* Date: 20080320 Version: 1V0 Author: Lori */ /* -------------------------------------------------------------------- -- /************************************************************************* NAME: MAIN.C FUNCTION: The following code can realize initialization the MCU The following software is for demonstration purpose only *************************************************************************/ #include "mb95200.h" #define switchmode stop void vsysinit (void) //elide code InitIrqLevels (); EI (); interrupt void Key_int (void) //elide key functions //set transition to some standby modes //include vsysinit(), interrupt and other functions void main (void) vsysinit (); while (1) //enter other test codes MCU-AN-500002-Z-10 第 28 页
第 8 章附录 8.2.2 工程 2 名称 : Clock_Change 名称 : Main.c 功能 : 选择时钟 时钟模式和时钟分频率 /* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS.*/ /*FUJITSU MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY*/ /*ERRORS OR ELIGIBILITY FOR ANY PURPOSES. */ /* (C) Fujitsu Microelectronics (Shanghai) Co., LTD. */ /* Date: 20080320 Version: 1V0 Author: Lori */ /* -------------------------------------------------------------------- -- /************************************************************************* //The following code can realize choose the clock and clock mode //The following software is for demonstration purposes only /************************************************************************** NAME: MAIN.C FUNCTION: Change the system clock and lighten three LED LED flicker frequency different in different clock **************************************************************************/ #include "mb95200.h" #define MAIN #define SUB #define MAIN_CR #define SUB_CR 0x00 0x01 0x02 0x03 unsigned char switchclock = MAIN; unsigned char toggle_status = 0; unsigned char i; //select the start clock //LED change bit /************************************************************************* NAME: FUNCTION: MCU initialization Initialization the IO port, system clock, interrupt level *************************************************************************/ void MCU_initialization() DI(); SYSC = 0x03; /*IO port*/ PDR0_P05=1; DDR0_P05=1; PDR6_P63=1; PDR6_P64=1; DDR6_P63=1; DDR6_P64=1; //Enable output //Enable output //Enable output MCU-AN-500002-Z-10 第 29 页
第 8 章附录 /*external interrupt*/ EIC30=0x55; //INT06 INT07 enable falling edge MCU-AN-500002-Z-10 第 30 页
第 8 章附录 /* initialise Interrupt level register and IRQ vector table*/ InitIrqLevels(); EI(); /************************************************************************* NAME: led_display() FUNCTION: Set three LED light cycle one by one *************************************************************************/ void led_display() switch(toggle_status) case 0: //lighten the PDR0_P05 (LED2) PDR0_P05=0; PDR6_P64=1; PDR6_P63=1; toggle_status=1; case 1: //lighten the PDR6_P64 (LED3) PDR0_P05=1; PDR6_P64=0; PDR6_P63=1; toggle_status=2; case 2: //lighten the PDR6_P63 (LED4) PDR0_P05=1; PDR6_P64=1; PDR6_P63=0; toggle_status=0; MCU-AN-500002-Z-10 第 31 页
第 8 章附录 /************************************************************************* NAME: FUNCTION: vdelay Delay the fix time *************************************************************************/ void vdelay (unsigned int uicount) while(uicount--) asm ("\tnop"); /************************************************************************* NAME: FUNCTION: interrupt void external_int06(void) Change the clock *************************************************************************/ interrupt void external_int06 (void) EIC30_EIR0=0; switch (++switchclock) case MAIN: case SUB: SYCC2=0x34; //update Oscillation Stabilization Wait Time WATR = 0x03; //Indicates main-clock oscillation being stable while (!STBC_MRDY); SYCC2=0x18; //Update the Oscillation Stabilization Wait Time WATR = 0x30; //Indicates sub-clock oscillation being stable while (!SYCC_SRDY); case MAIN_CR: SYCC2=0x21; //Indicates main CR clock oscillation being stable while (!STBC_MCRDY); MCU-AN-500002-Z-10 第 32 页
case SUB_CR: default: SYCC2=0x02; 基本 FW 设置 V1.0 第 8 章附录 //Indicates sub-cr clock oscillation being stable while (!STBC_SCRDY); switchclock = MAIN; SYCC2=0x34; //update Oscillation Stabilization Wait Time WATR = 0X03; //Indicates main-clock oscillation being stable while (!STBC_MRDY); /************************************************************************* NAME: main () FUNCTION: lighten three LED *************************************************************************/ void main() MCU_initialization(); while(1) vdelay(10); led_display(); //delay the time //lighten three LED MCU-AN-500002-Z-10 第 33 页
名称 : vector.c 功能 : 中断级设置和中断向量定义 基本 FW 设置 V1.0 第 8 章附录 //======================================================================== //ALL RIGHTS RESERVED, COPYRIGHT (C) FUJITSU LIMITED 2008 // LICENSED MATERIAL - PROGRAM PROPERTY OF FUJITSU LIMITED /************************************************************************** NAME: vector.c FUNCTION: Interrupt level (priority) setting Interrupt vector definition **************************************************************************/ #include "mb95200.h" //------------------------------------------------------------------------ //This function pre-sets all interrupt control registers. It can be used //to set all interrupt priorities in static applications. If this file //contains assignments to dedicated resources, verify that the appropriate //controller is used. //------------------------------------------------------------------------ void InitIrqLevels (void) ILR0 = 0x1F; //...... // IRQ0: external interrupt ch.4 // IRQ1: external interrupt ch.5 // IRQ2: external interrupt ch.2/ch.6 // IRQ3: external interrupt ch.3/ch.7 //------------------------------------------------------------------------ // Prototypes //Add your own prototypes here. Each vector definition needed is a //prototype. Either do it here or include a header file containing them. //------------------------------------------------------------------------ interrupt void DefaultIRQHandler (void); interrupt void external_int06 (void); //------------------------------------------------------------------------ //Vector definition //Use the following statements to define vectors. //All resources related to the vectors are predefined. //Remaining software interrupts can be added here as well. //------------------------------------------------------------------------ #pragma intvect DefaultIRQHandler 0 //IRQ0: external interrupt ch.4 #pragma intvect DefaultIRQHandler 1 //IRQ1: external interrupt ch.5 #pragma intvect external_int06 2 //...... //IRQ2: external interrupt ch.2 ch.6 MCU-AN-500002-Z-10 第 34 页
第 8 章附录 interrupt void DefaultIRQHandler (void) DI (); // disable interrupts while (1) wait_nop (); // halt the system MCU-AN-500002-Z-10 第 35 页
第 8 章附录 8.2.3 工程 3 名称 : Mode_Change 名称 : Main.c 功能 : 待机模式转换 /* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS.*/ /*FUJITSU MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY*/ /*ERRORS OR ELIGIBILITY FOR ANY PURPOSES. */ /* (C) Fujitsu Microelectronics (Shanghai) Co., LTD. */ /* Date: 20080320 Version: 1V0 Author: Lori */ /* -------------------------------------------------------------------- -- /************************************************************************* //The following code can realization transition from normal mode to other //mode, such as stop mode, watch mode //The following software is for demonstration purposes only //You can update the switchmode to the mode what you want /************************************************************************** NAME: FUNCTION: MAIN.C Change the mode and lighten three LED to one fix light Change the mode and LED light fixed **************************************************************************/ #include "mb95200.h" #define normal #define stop #define sleep 0x00 0x01 0x02 #define Timebase 0x03 #define watch 0x04 unsigned char switchmode = normal; unsigned char toggle_status = 0; unsigned char i; //Select the start mode //LED change bit /************************************************************************* NAME: FUNCTION: MCU initialization Initialization the IO port, system clock, interrupt level *************************************************************************/ void MCU_initialization() DI(); /*system clock*/ SYSC = 0x03; SYCC2 = 0x34; /*IO port*/ PDR0_P05=1; DDR0_P05=1; PDR6_P63=1; PDR6_P64=1; DDR6_P63=1; DDR6_P64=1; //Enable output //Enable output //Enable output MCU-AN-500002-Z-10 第 36 页
第 8 章附录 /*external interrupt*/ EIC30=0x55; //INT06 enable falling edge /*initialise Interrupt level register and IRQ vector table*/ InitIrqLevels(); EI(); /************************************************************************* NAME: led_display() FUNCTION: Set three LED light cycle one by one *************************************************************************/ void led_display() switch(toggle_status) case 0: //Lighten the PDR0_P05 (LED2) PDR0_P05=0; PDR6_P64=1; PDR6_P63=1; toggle_status=1; case 1: //Lighten the PDR6_P64 (LED3) PDR0_P05=1; PDR6_P64=0; PDR6_P63=1; toggle_status=2; case 2: //Lighten the PDR6_P63 (LED4) PDR0_P05=1; PDR6_P64=1; PDR6_P63=0; toggle_status=0; MCU-AN-500002-Z-10 第 37 页
第 8 章附录 /************************************************************************* NAME: vdelay FUNCTION: Delay the fix time *************************************************************************/ void vdelay (unsigned int uicount) while(uicount--) asm ("\tnop"); /************************************************************************* NAME: interrupt void external_int06(void) FUNCTION: Change the mode *************************************************************************/ interrupt void external_int06(void) EIC30_EIR0=0; if(switchmode <= 3) switchmode++; if(switchmode >= 4) switchmode = 1; /************************************************************************* NAME: interrupt void external_int07(void) FUNCTION: Reset the mode to normal *************************************************************************/ interrupt void external_int07(void) EIC30_EIR1 = 0; switchmode = normal; MCU-AN-500002-Z-10 第 38 页
第 8 章附录 /************************************************************************* NAME: main () FUNCTION: Lighten three LED, when change the mode, only one LED light *************************************************************************/ void main() MCU_initialization(); while(1) switch (switchmode) case normal: case stop: STBC_STP = 1; case sleep: STBC_SLP = 1; //Normal to stop mode //Normal to sleep mode case watch: SYCC2_SOSCE = 1; //Enable Sub Clock SYCC2_RCS0 = 0x01; //Select Sub Clock SYCC2_RCS1 = 0x00; WATR = 0xF0; //About 1.00s Wait Time while (!SYCC_SRDY); //Wait Clock stable STBC_TMD = 1; //normal to watch mode case Timebase:SYCC2_MOSCE = 1; //Enable Main Clock default: vdelay(2000); led_display(); SYCC2_RCS0 = 0x01; //Select Main Clock SYCC2_RCS1 = 0x01; WATR = 0X0F; // About 4.10 ms Wait Time while (!STBC_MRDY); //Wait Clock stable STBC_TMD = 1; //normal to timebase time mode //delay the time //lighten three LED MCU-AN-500002-Z-10 第 39 页
名称 : 功能 : vector.c 中断级设置和中断向量定义 基本 FW 设置 V1.0 第 8 章附录 //======================================================================== //ALL RIGHTS RESERVED, COPYRIGHT (C) FUJITSU LIMITED 2008 // LICENSED MATERIAL - PROGRAM PROPERTY OF FUJITSU LIMITED /************************************************************************** NAME: vector.c FUNCTION: Interrupt level (priority) setting Interrupt vector definition **************************************************************************/ #include "mb95200.h" //------------------------------------------------------------------ //This function pre-sets all interrupt control registers. It can be used //to set all interrupt priorities in static applications. If this file //contains assignments to dedicated resources, verify that the appropriate //controller is used. //------------------------------------------------------------------ void InitIrqLevels (void) ILR0 = 0x1F; //...... // IRQ0: external interrupt ch.4 // IRQ1: external interrupt ch.5 // IRQ2: external interrupt ch.2/ch.6 // IRQ3: external interrupt ch.3/ch.7 //------------------------------------------------------------------ //Prototypes //Add your own prototypes here. Each vector definition needed is a //prototype. Either do it here or include a header file containing them. //------------------------------------------------------------------ interrupt void DefaultIRQHandler (void); interrupt void external_int06 (void); interrupt void external_int07 (void); //------------------------------------------------------------------ //Vector definition //Use the following statements to define vectors. //All resources related to the vectors are predefined. //Remaining software interrupts can be added here as well. //------------------------------------------------------------------ #pragma intvect DefaultIRQHandler 0 //IRQ0: external interrupt ch.4 #pragma intvect DefaultIRQHandler 1 //IRQ1: external interrupt ch.5 MCU-AN-500002-Z-10 第 40 页
第 8 章附录 #pragma intvect external_int06 2 //IRQ2: external interrupt ch.2/ch.6 #pragma intvect external_int07 3 //IRQ3: external interrupt ch.3/ch.7 //...... interrupt void DefaultIRQHandler (void) DI (); // disable interrupts while (1) wait_nop (); // halt the system -- END -- MCU-AN-500002-Z-10 第 41 页