合泰单片机ht46x65v220使用手册
合泰单片机智能充电器主程序HT46R47_main
![合泰单片机智能充电器主程序HT46R47_main](https://img.taocdn.com/s3/m/614a110ca300a6c30c229f37.png)
#include "HT46R47-H.h"//---------------def-----------------------//pa#define _pac0 _13_0#define _pac1 _13_1#define _pac2 _13_2#define _pac3 _13_3#define _pac4 _13_4#define _pac5 _13_5#define _pac6 _13_6#define _pac7 _13_7//pb#define _pbc0 _15_0#define _pbc1 _15_1#define _pbc2 _15_2#define _pbc3 _15_3//pd#define _pdc0 _19_0#define CN_DOWN _pa1#define JM _pa4#define LED_GREEN _pa5#define LED_RED _pa6#define FAN _pa7#define PWM_IO _pd0#define C_SAMP 0x00#define BT_SAMP 0x01#define V_SAMP 0x02#define TIM_PRE 7200 //pre 2H-7200#define TIM_NOML 43920 //CC/CV 12.2H=13H#define OVER_VOLTAGE 0x0c5 //43.57V#define LOW_VOLTAGE 0x068 //24V 0x06b//#define OVER_CURRENT 0x0062 //3.9A 10.5A #define PRE_CHARGER 0x088 //30V#define FULL_DOWN_V 0x0b5 //40V#define FULL_CURRENT 0x05f //0.2A#define N20C_NTC 0x0ec //-20度#define _0C_NTC 0x0d7 //0度#define _45C_NTC 0x089 //45度0x07e//---------------var-----------------------unsigned int adcvalue;unsigned int I_by;unsigned char chargermode;unsigned char T_Mode; //T mode unsigned int ChargingTimeValue; //bit StartTimeFlg;bit ChargingT_OverFlg;unsigned char Tcount;unsigned char SecondCnt;bit UnLoad;bit Start_5S;bit Flg_5S;unsigned char Cnt5s; //5 seconds//---------------ex fuction----------------extern unsigned int ADCStart(unsigned char chanl);//delay 1ms Fsys=4Mhz 实测1msvoid Delay1ms(void){unsigned int va;for(va=0;va<60;va++){;}}//delay N msvoid DelayNms(unsigned int ms){unsigned int vb;for(vb=0;vb<ms;vb++){Delay1ms();}}//----------------------------------------------// 上电自校准电压IV// 自校电压是否在空载范围内void s1_VI(void)while(1){adcvalue = ADCStart(V_SAMP); //voltageif(((adcvalue<0x01ff)||(adcvalue==0x01ff))&&((adcvalue>0x0000)||(adcvalue==0x0000))) {break;}}}//------------------------------------------------// 校正OP电流否正常,条件打开0.05A校正电流// 实测I-V OP放大电压,0x0074 4.2A=0X0141 【0X0141-0X0074=D205,// 4200/205=20.5mA/位ADvoid s1_VI1(void){while(1){adcvalue = ADCStart(C_SAMP); //currentif(((adcvalue<0x01ff)||(adcvalue==0x01ff))&&((adcvalue>0x0000)||(adcvalue==0x0000))) {I_by = adcvalue;break;}}}//system initialvoid SYS_Inital(void){//IOport --------------CN_DOWN = 0;JM = 0;FAN = 0;PWM_IO = 0;LED_GREEN = 0;LED_RED = 1;_pb3 = 0;_pac1 = 0;_pac4 = 0;_pac7 = 0;_pdc0 = 0;_pac5 = 0;_pac6 = 0;_pbc0 = 1;_pbc1 = 1;_pbc2 = 1;_pbc3 = 0;//var ----------------------chargermode = 0x01;Tcount = 0;SecondCnt = 0;//Timer -------------------_tmrc = 0x87; //timer mode Ftimer=Fsys/128 Fsys=4M Ttimer=32us _tmr = (256-250); //32*250=8ms//PWM ---------------------_pwm = 0xfc; //set pwm duty cycle//voltage current just self-----s1_VI();DelayNms(1000);s1_VI1();}//---------------------相关保护void ToPretect(void){//---------------短路保护//---------------低压保护/*adcvalue = ADCStart(V_SAMP); //voltageif(adcvalue<=LOW_VOLTAGE) //Low voltage{adcvalue = ADCStart(C_SAMP); //currentif(adcvalue>20){PWM_IO = 0;JM = 0;chargermode = 0x05; //errorreturn;}}*///---------------过压保护if(adcvalue>=OVER_VOLTAGE) //over voltage {PWM_IO = 0;JM = 0;chargermode = 0x05; //errorreturn;}//---------------过流保护/*adcvalue = ADCStart(C_SAMP); //currentif(adcvalue>=OVER_CURRENT) //over current {PWM_IO = 0;JM = 0;chargermode = 0x05; //errorreturn;}*/}//------------------main-----------void main(){SYS_Inital();_intc=0x05; // EMI ETI enable _ton = 1; //start timerwhile(1){switch(chargermode){case 0x01://startT_Mode = chargermode;ChargingTimeValue = 0;StartTimeFlg = 0;ChargingT_OverFlg = 0;FAN = 0;LED_GREEN = 0;LED_RED = 1;DelayNms(1000);adcvalue = ADCStart(V_SAMP); //voltageif((adcvalue>=OVER_VOLTAGE)) //&&(adcvalue>=LOW_VOLTAGE)//over or low voltage{JM = 0;chargermode = 0x05; //errorbreak;}else{//adcvalue = ADCStart(BT_SAMP); //B temp//if(adcvalue<=N20C_NTC)//if(adcvalue>=LOW_VOLTAGE)//{PWM_IO = 0;JM = 1;DelayNms(1000);adcvalue = ADCStart(C_SAMP); //Currentif(adcvalue>=0x50){//UnLoad = 0;//Start_5S = 0;//Cnt5s = 0;//Flg_5S = 0;//adcvalue = ADCStart(V_SAMP); //voltage//if(adcvalue<=PRE_CHARGER) //24<V<30V-pre//{PWM_IO = 0;chargermode = 0x02; //prebreak;//}//else //V>30V-nor//{// PWM_IO = 1;// chargermode = 0x03; //normal// break;//}}//}}break;case 0x02://PRE_CHARGERPWM_IO = 0;JM = 1;FAN = 0;LED_GREEN = 1;LED_RED = 1;//----------------------------------------- //over timeif(T_Mode!=chargermode){T_Mode = chargermode;ChargingTimeValue = TIM_PRE;StartTimeFlg = 1;ChargingT_OverFlg = 0;}if(ChargingT_OverFlg==1){PWM_IO = 0;JM = 0;chargermode = 0x05; //errorbreak;}//----------低压,过压,过流,短路ToPretect();//----------BMS over tempadcvalue = ADCStart(BT_SAMP); //B tempif(((adcvalue>0xd7)||(adcvalue==0xd7))||((adcvalue<0x7f)||(adcvalue==0x7f))) {PWM_IO = 0;JM = 0;chargermode = 0x05; //errorbreak;}//----------pre to Normaladcvalue = ADCStart(V_SAMP); //voltageif(adcvalue>PRE_CHARGER) //>30V{PWM_IO = 1;chargermode = 0x03; //normal}//------------------------------battery removeadcvalue = ADCStart(BT_SAMP); //battery NTCif(adcvalue>=N20C_NTC) //no ntc{PWM_IO = 0;JM = 0;chargermode = 0x05; //standbybreak;}//---------------adcvalue = ADCStart(V_SAMP); //voltageif(adcvalue<=0x16) //5V{adcvalue = ADCStart(C_SAMP); //currentif(adcvalue>20){JM = 0;PWM_IO = 0;chargermode = 0x05; //errorbreak;}}break;case 0x03://CC+CVPWM_IO = 1;JM = 1;FAN = 1;LED_GREEN = 1;LED_RED = 1;//---------------------timerif(T_Mode!=chargermode){T_Mode = chargermode;ChargingTimeValue = TIM_NOML;StartTimeFlg = 1;ChargingT_OverFlg = 0;}if(ChargingT_OverFlg==1){PWM_IO = 0;chargermode = 0x05; //errorbreak;}//----------低压,过压,过流,短路ToPretect();//-----------------------------normal to FULLadcvalue = ADCStart(V_SAMP); //voltageif(adcvalue>=FULL_DOWN_V) //>40V{adcvalue = ADCStart(C_SAMP); //currentif(adcvalue<=(FULL_CURRENT)) //get FULL{chargermode = 0x04; //fullbreak;}}//----------BMS over tempadcvalue = ADCStart(BT_SAMP); //B temp//0度-0xc2 45度-0x6bif(((adcvalue>0xdb)||(adcvalue==0xdb))||((adcvalue<0x82)||(adcvalue==0x82))) {PWM_IO = 0;JM = 0;chargermode = 0x05; //errorbreak;}//------------------normal to preadcvalue = ADCStart(V_SAMP); //voltageif(adcvalue<(PRE_CHARGER-10)) //PRE{chargermode = 0x02; //prebreak;}//------------------------------battery removeadcvalue = ADCStart(BT_SAMP); //battery NTCif(adcvalue>=N20C_NTC) //no ntc{PWM_IO = 0;JM = 0;chargermode = 0x05; //standby}//---------------adcvalue = ADCStart(V_SAMP); //voltageif(adcvalue<=0x16) //5V{adcvalue = ADCStart(C_SAMP); //currentif(adcvalue>20){JM = 0;PWM_IO = 0;chargermode = 0x05; //errorbreak;}}break;case 0x04://FULL_DOWNT_Mode = chargermode;ChargingTimeValue = 0; //StartTimeFlg = 0;ChargingT_OverFlg = 0;PWM_IO = 0;JM = 0;FAN = 0;LED_GREEN = 1;LED_RED = 0;DelayNms(1000);adcvalue = ADCStart(V_SAMP); //voltageif(adcvalue>OVER_VOLTAGE) //{PWM_IO = 0;JM = 0;chargermode = 0x05; //errorbreak;}else{if(adcvalue<(LOW_VOLTAGE-20)){PWM_IO = 0;JM = 0;chargermode = 0x01; //standbybreak;}}break;case 0x05://errorT_Mode = chargermode;ChargingTimeValue = 0; //StartTimeFlg = 0;ChargingT_OverFlg = 0;PWM_IO = 0;JM = 0;FAN = 0;LED_GREEN = 0;LED_RED = 1;DelayNms(1000);LED_GREEN = 0;LED_RED = 0;DelayNms(1000);break;default:break;}}}。
HT46实时定时使用
![HT46实时定时使用](https://img.taocdn.com/s3/m/23a4031a6bd97f192279e9aa.png)
HT47R20A-1定时/计数器(Timer/Event counter)使用介绍文件编码:HA0031s本文主要介绍HT47R20A-1定时/计数器(Timer/Event counter)的使用及注意事项。
介绍HT47R20A-1有一个16位向上计数的定时/计数器,由TMRAH、TMRAL和TMRBH、TMRBL 组成。
其中TMRAH、TMRAL用来计数;TMRBH、TMRBL是加载寄存器,用来存放定时/计数器的初值。
定时/计数器赋初值时要先写入低字节,再写入高字节,即先写入TMRAL、TMRBL,再写入TMRAH、TMRBH;定时/计数器的时钟来源可以是系统时钟、指令时钟(系统时钟/4)、RTC超TMRC为定时/计数器的控制寄存器,用来定义定时/计数器的运行模式、计数允许/禁止以及触发方式,如下表所示:名称位功能—0~2 未定义,读取时为“0”TE 3定义定时/计数器TMR作用沿(0=上升沿作用,1=下降沿作用)TON 4允许/禁止定时器计数(0=禁止,1=允许)TM0 TM1 TM2 567定义操作方式(TM2,TM1,TM0)000=定时器模式(系统时钟)001=定时器模式(系统时钟/4)010=定时器模式(RTC输出)011=A/D计数模式(由ADCR寄存器决定RC振荡)100=计数器模式(外部时钟)101=脉冲宽度测量模式(系统时钟/4)110=未定义111=未定义TMRC寄存器TM0、TM1和TM2用来定义计数模式。
其中定时器模式用来计数内部时钟,其时钟来源为内部时钟;计数器模式用来计数外部事件,其时钟来源为外部TMR引脚的输入;A/D计数模式是用来计数外部A/D输入(关于A/D转换的使用在此不做详细介绍);脉冲宽度测量模式能够对外部引脚TMR的高电平或低电平的持续时间进行计数,计数的时钟来源为指令时钟。
在定时器模式、A/D计数模式或计数器模式下,一旦定时/计数器开始计数即从定时/计数器的现有值(TMRAH和TMRAL)开始计数至FFFFH。
合泰C语言用户手册
![合泰C语言用户手册](https://img.taocdn.com/s3/m/3a14a86b7e21af45b307a852.png)
函数 ....................................................................................................27
数组 ....................................................................................................28
位数据类型 ........................................................................................25
内嵌式汇编语言 ................................................................................26
指针与数组 ................................................................................................17
指针 ....................................................................................................17
数组 ....................................................................................................17
结构体与共用体(Structures and Unions) ..................................................18
HOLTEK HT46R53A HT46R54A A D型八位 OTP单片机 说明书
![HOLTEK HT46R53A HT46R54A A D型八位 OTP单片机 说明书](https://img.taocdn.com/s3/m/f7ae7b62f56527d3240c844769eae009581ba20b.png)
HT46R53A/HT46R54A A/D 型八位OTP 单片机盛群知识产权政策专利权盛群半导体公司在全球各地区已核准和申请中之专利权至少有160件以上,享有绝对之合法权益。
与盛群公司MCU 或其它产品有关的专利权并未被同意授权使用,任何经由不当手段侵害盛群公司专利权之公司、组织或个人,盛群将采取一切可能的法律行动,遏止侵权者不当的侵权行为,并追讨盛群公司因侵权行为所受之损失、或侵权者所得之不法利益。
商标商标权权盛群之名称和标识、Holtek 标识、HT-IDE 、HT-ICE 、Marvel Speech 、 Music Micro 、 Adlib Micro 、 Magic V oice 、 Green Dialer 、 PagerPro 、 Q-V oice 、 Turbo V oice 、 EasyV oice 和 HandyWriter 都是盛群半导体公司在台湾地区和其它国家的注册商标。
著作权Copyright © 2006 by HOLTEK SEMICONDUCTOR INC.规格书中所出现的信息在出版当时相信是正确的,然而盛群对于规格内容的使用不负责任。
文中提到的应用其目的仅仅是用来做说明,盛群不保证或不表示这些应用没有更深入的修改就能适用,也不推荐它的产品使用在会由于故障或其它原因可能会对人身造成危害的地方。
盛群产品不授权使用于救生、维生器件或系统中做为关键器件。
盛群拥有不事先通知而修改产品的权利,对于最新的信息,请参考我们的网址; HT46R53A/HT46R54A技术相关信息· 工具信息· FAQs· 应用范例− HA0003S HT48 & HT46 MCU 与HT93LC46 EEPROM 的通信− HA0004S HT48 & HT46 MCU UART 的软件实现方法− HA0084S HT46R52 之应用-镍氢电池充电器展示板特性• 低功耗的全静态CMOS设计• 工作电压:• f SYS =4MHz:2.2V~5.5V• f SYS =8MHz:3.3V~5.5V• 程序存储器:2K×15 OTP(HT46R53A)4K×15 OTP(HT46R54A)• 数据存储器:192×8 RAM(HT46R53A)280×8 RAM(HT46R54A)• A/D转换器:12bits×8通道具有外部的A/D转换器的参考电压输入引脚• 有22个双向输入/输出口• 1个与输入/输出口共用引脚的外部中断输入• 8位可编程定时/计数器,具有溢出中断和7级预分频器• 内置晶体和RC振荡电路• 6层硬件堆栈• 看门狗定时器• 低电压复位功能• HALT和唤醒功能可降低功耗• 在VDD=5V,系统频率为8MHz时,指令周期为0.5µs• 1通道8位的PWM输出,与输入/输出口共用引脚• PFD功能• 位操作指令• 查表指令• 63条指令• 指令执行时间为1或2个指令周期• 28-pinSKDIP/SOP封装概述HT46R53A/ HT46R54A是8位高性能精简指令集单片机,专门为需要A/D转换的产品而设计,例如传感器信号输入。
合泰单片机基础
![合泰单片机基础](https://img.taocdn.com/s3/m/1e1750f3770bf78a6529543e.png)
�
图1-6 数据存储器
1FH 20H
特殊功能寄 存器
通用数据 存储器 不同芯片 容量不 同 7FH/FFH
RAM的特点: 掉电数据丟失.
16
2011-6-23
通用数据存储器
�
图1-7通用数据存储器的结构
-1 HT48R10A HT48R10A-1 HT48C10 HT48C1020H 40H 60H 7FH 7FH 通用数据存储 器 20H -1 HT48R30A HT48R30A-1 HT48C30 HT48C3020H -1 HT48R50A HT48R50A-1 HT48C50 HT48C5020H -1 HT48R70A HT48R70A-1 HT48C70 HT48C70-
H T48R 30 A -1 AH T48C 30 -1 30IAR MP
H T48R 50 A -1 AH T48C 50 -1 50IAR 0 MP0 IAR 1 MP1 AC C PC L TBLP TBLH W D TS STA TU S IN TC TMR 0 TMR 0C TMR 1H TMR 1L TMR 1C PA PAC PB PBC PC PC C PD PD C
I/O 端口
设备编程 电路
9
2011-6-23
时序和流水线结构
�
图1-2系统时序和流水线
振荡时钟 (系统时钟 ) 时钟相位 T1 时钟相位 T2 时钟相位 T3 时钟相位 T4 程序计数器 PC PC+1 PC+2
运行流程
取指令 (PC) 执行指令 (PC -1) 取指令 (PC+1) 执行指令 (PC) 取指令 执行指令 (PC+2) (PC+1)
合泰(HT)入门攻略
![合泰(HT)入门攻略](https://img.taocdn.com/s3/m/a16aa3e3998fcc22bcd10d54.png)
合泰(HT)入门攻略同V100版本相比,多出了如下红色内容目录一、网址链接 (2)1. 芯片选型 (2)2. 工具主页 (2)3. 工具的使用视频 (3)二、HT基本常识 (4)1. Flash/OTP (4)2. 编译器 (4)3. 软件仿真 (4)4. 资料更新 (4)三、HT价格 (5)1. 芯片价格 (5)2. 仿真器价格 (5)3. 烧录器价格 (6)四、HT培训 (7)1. 可以建议购买如下书籍 (7)2. 仿真器购买M1001D+D1003C (7)3. HT官方网站上有应用范例 (7)4. 如果想有人手把手教 (7)五、使用手册 (8)一、网址链接官网1.芯片选型⏹选型系统/ecatalog_mvc_trunk/parametricSearchController.do?compNo=H&groupNo=01⏹简易选型PDF文档/pdf/guide.pdf2.工具主页⏹上位机软体下载/China/tech/tool/MainPage1.htm⏹仿真器/烧录器硬件/China/tech/tool/MainPage1.htm⏹工具搭配组合查询/China/tech/tool/MainPage2.aspx?L=CN○1○2○3⏹IC烧录引脚需知如果不使用HT的专用e-Socket转接座,可考虑使用如下ICP方式:/english/literature/Holtek_MCU_In-Circuit_Programming_Guidelines.pdf3.工具的使用视频/HoltekC500二、HT基本常识1.Flash/OTPFlash:可重复擦写,一般名称带有F字母HT46FXX\HT66FXX系列带AD,HT48FXX\HT68FXX系列不带ADHT46FXX\HT48FXX为较早期Flash,仿真器使用HT-ICEHT66FXX\HT68FXX为近期开发的Flash功能更强,仿真器使用e-ICE/e-Link烧录档后缀为.MTP(Multi Time Program,重复烧录)OTP:不可擦写,一般名称带有R字母即:芯片ROM中的0可以写为1,但1不能再写为0HT46R06X系列带AD,HT48R06X系列不带AD烧录档后缀为.OTP(One Time Program,只烧录1次)2.编译器HT可同时支持“C语言和汇编”编程。
HT46R22单片机在电磁炉功率控制中的应用
![HT46R22单片机在电磁炉功率控制中的应用](https://img.taocdn.com/s3/m/f287c14369eae009581bec95.png)
HT46R22单片机在电磁炉功率控制中的应用摘要:介绍了电磁炉的基本工作原理,并提出了一种采用HT46R22单片机实现电磁炉功率稳定输出的功率控制方法,最后简单介绍了该方法的软硬件设计过程。
关键词:电磁炉;HT46R22;功率控制引言近年来,随着环保和节能意识的逐步提高,一种新兴的"绿色的厨具"--电磁炉正在家庭中普及。
它改变了传统的明火烹调方式,利用电磁感应原理,使电流通过内置的线圈时产生磁场,磁场内的磁力线感应到铁制器皿,产生无数高速运动的小涡流,涡流产生的巨大循环能量转换为有效热能,使锅具自行高速加热,最终直接加热食物。
电磁炉的热效率达到90%以上,同时它无烟无灰,无污染,不升高室温,不产生一氧化碳等有害物质,安全环保。
电磁炉还采用了微电脑控制,能够随意控制温度。
正是由于上述种种优点,电磁炉在发达国家的家庭普及率已经达到80%以上。
为了提高电热转换率,家用电磁炉一般采用的是高频电磁炉,须将工频电整流成直流电后再逆变成20kHz以上的高频振荡电流,在高频下,稳定功率输出和实时检测就成了设计的难点和关键所在。
采用Holtek公司产的A/D型单片机HT46R22可以方便地实现定温控制、实时检测、报警检测和功率控制,本文着重介绍功率控制的实现。
1 功率控制设计原理1.1 电磁炉的工作原理电磁炉的工作原理如图1所示,由主电路和控制电路构成。
主电路中220V交流电经整流滤波后加在由电容C1及C2和电感L1与IGBT管S组成的电压谐振变换器上。
变换器主要起两个作用,一是将工频转换为20~40kHz的高频交流电,二是将电能转换为磁能。
高频交流电加在励磁线圈上,通过电磁感应,直接作用于锅具底部,产生涡流,使锅具迅速加热。
控制电路采用单片机HT46R22作为主控制芯片,它能实现许多必要的检测和保护,同时由它产生控制所需的PWM信号,控制电磁炉的输出功率。
1.2 电磁炉的功率控制原理功率控制,就是当工频交流电稳定的情况下,电磁炉能按设定的功率稳定地输出,以使电磁炉能稳定地工作。
合泰单片机基础教程
![合泰单片机基础教程](https://img.taocdn.com/s3/m/8e9cbbd78ad63186bceb19e8b8f67c1cfad6ee3d.png)
合泰单⽚机基础教程第⼀章⼀、概念与分类单⽚机⼜称微控制器(M icro C ontroller U nit),包含:中央处理单元、程序存储器、数据存储器、输⼊/输出端⼝1、按算术逻辑单元的位长度:4位机、8位机、 16位机、 32位机、64位机2、按内部结构(1)精简指令集RISC:提供较少的基本指令,执⾏效率较⾼(2)复杂指令集CISC :提供较多的指令,包括功能强⼤的指令(如乘除法),执⾏效率较低3、按编址⽅式(1)普林斯顿结构:指令与数据共⽤同⼀块存储器,共⽤地址/数据总线,同⼀时间只能对指令或数据操作(2)哈佛结构:指令与数据是分开的,各⾃独⽴的地址/数据总线,可同时对指令与数据操作⼆、单⽚机结构概述1、中央处理单元(CPU):(1)指令解码单元(IU)通过解码硬件电路去解析⼀连串⼆进制码以作为控制器的决策核⼼(2)执⾏控制单元(EU)接受IU所发出的指⽰,将各单元中的数据进⾏互换、传送、运算、判断,再依汇编指令所指定的动作或运算进⾏输⼊、输出、存储等⼯作(3)算术逻辑单元(ALU)可从指令集中实现算术和逻辑操作,ALU在接收相关的指令码后执⾏需要的算术与逻辑操作,并将结果存储在指定的存储位置2、程序存储器(ROM)内容⼀般不可更改的,⽤于存放⽤户代码的存储器,不同型号不同容量3、数据存储器(RAM)内容可更改的,⽤于存放单⽚机状态或⽤户变量的存储器,不同型号不同容量4、总线(BUS)⽤于内部各单元间信息互通,⼀般有3种总线:数据总线、控制总线、地址总线(1)数据总线:传送各单元间数据的硬件(2)控制总线: 控制单⽚机数据的读或写,使、除能某单元以接收或传送数据(3)地址总线: 主要⽤来寻址,指⽰数据存取的位置,即⽤地址总线寻址三、 HT合泰单⽚机结构分析(以HT48系列为例)1、时序和流⽔线结构(1)系统时钟由晶体/陶瓷震荡器或RC震荡器提供(2)指令周期由T1~T4 4个内部时钟组成,流⽔线结构保证指令在⼀个指令周期内被有效执⾏T1:程序计数器⾃动加1并抓取新指令T2~T4:完成解码、算术逻辑并执⾏功能(3)当程序计数器的内容改变时,如call调⽤或jmp跳转时,指令需要多⼀个指令周期取出当前指令地址的下⼀条指令,并清除流程,再⽤另⼀个周期去执⾏下⼀动作2、程序计数器(PC)(1)程序指令码的读取是由于内部有⼀程序计数器来寻址,在指令码被读取后程序执⾏期间,程序计数器指向下⼀条要执⾏的指令地址(2)复位起始地址是0000h,在每条指令执⾏后⾃动加1(jmp、call等除外) 3、堆栈(Strack)是存储器特殊的部分,在⼦程序调⽤或中断响应时,程序指针压⼊堆栈,返回指令(RET或RETI)使程序指针返回到上次⼦程序调⽤位置四、程序存储器(ROM)存放⽤户代码,内容为⼆进制机器码1、分类:掩模 \ OTP \ EEPROM \ FLASH2、⼀般为14Bit~16Bit,除了存放程序外也包含中断⼊⼝和数据表3、特殊向量地址(以HT48R50A-1为例):(1)复位向量地址: 000H(2)外部中断向量地址: 004H(3)定时/计数器0中断向量地址: 008H(4)定时/计数器1中断向量地址: 00CH五、数据存储器(RAM)1、可更改的8位内部存储器,⽤来存放临时数据,分为“专⽤寄存器”和“通⽤数据存储器”2、通⽤数据存储器(⽩⾊部分)3、专⽤寄存器六、专⽤寄存器1、间接寻址寄存器IAR0/IAR1在间接寻址寄存器上的任何动作,将对间接寻址指针(MP0/MP1)所指定的数据存储地址产⽣的读/写操作2、间接寻址指针MP0/MP1与IAR0/IAR1组成间接寻址操作功能3、累加器ACC所有ALU得到的运算结果都会暂时存储在累加器,数据传送也需要累加器4、程序计数器低字节寄存器PCL直接给PCL赋值将导致直接跳转到本页范围的某⼀地址。
合泰单片机总结
![合泰单片机总结](https://img.taocdn.com/s3/m/57fe1e1abb4cf7ec4bfed0a9.png)
--测试环境C 编译器V2Step Step over Step OutPov 痢 on Resrt也他我条1Reset ItemPower-On R^sctTarget Board ResetSoftware ResetConunandSoftwarePtJweT'On ResetCommandClciir Reaisiets (*) (*)(*)(*)Clem 7 (Options Yes NoNaNoClear PD. TO Yes Nc No Yes PCValut?(**) 0 0 0Bmulation Stop (**) No(***) Yes Yes Chetk Stand-AloneYesNo NaNo5-1拄意:(*):缓存器征不同舐克下所覺的影响』请奪雷备徹控制器的Df 曲BoM.(怜FC 值为伽同时停止醍件仿真.(杠*);假如虫戌来口 F •应用电舒板「则系统会在直鈕亢应后自动丿F 始谨件的肪戌。
2. Data TypeData type Size (bit) C compiler VISize (bit) C compiler V2Size (bit) C COMPILER V3Size (bit) ANSI Cbit 11N N char Q 3 8 0signed char 0 a 8nunsigned char 8a 8short816 16 诟unsigned sliolt a 16 16 16 | lot816 16 16unsigned ini 816 16 12Long16 32 32 32 unsigned long 16 32 3232 long longN N 32 64 unsigned long long N N 32 64 float N32 2432 double N32 32 64 long doubleNNN128:3..数组,支持一维/二维数组(大小小于1bank );4. 使用 const 关键字,变量将存储于程序存储区,如,const uint8_t tab[] =“1,2,3”;合泰单片机总结1. DebugToggie Bf^ak Port Qear All Bveat Poirt Ootoursor Stop5.中断服务函数:#pragma vector ISR_tmr0 @ 0x0c //定义中断入口地址void ISR_tmr0(void){tick++ ;}6.中断函数中调用普通函数(1)方法 1#pragma vector ISR_tmr0 @ 0x0c#pragma nolocal funfun(){}void ISR_tmr0(void){fun() ;}(2)方法 2#pragma vector ISR_tmr0 @ 0x0cfun(){}void ISR_tmr0(void){#asmcall _fun;#endasm}7.宏定义#define _pa0 _12_0 //bit 0 of RAM address 0x128. 位变量定义对于有多个bank 的MCU ,位变量只能定义在bank0 ,使用如下方式#pragma rambank0 bit flag ;#pragma norambank9.指针(1) 不支持指向“字符串数组”char *rain bow[] = { "red", "ora nge", "yellow" };// not supported (2) 只支持全局的静态函数指针,且所指函数不能带有参数 fun() {return 1; }in t (*c onst p)() =fun; // global and in itializati on required void mai n() { int a; a=(*p)(); }(3) 不支持取得con st 常量的地址 const int ldc = 0; void mai n(){ int *a;a = &ldc; // cannot pass }10.内嵌汇编■內嵌懒褊4怕他睨在鹵式內■内嵌集編只能撰寫描节・平能用来定義姿敷action 等一■內嵌駅菊中胸煥數,貼阳f 更用相血旳集編名.而逮敎何怕編名宇必冏的關保如h':• 總鴨煙Wft :V8r —»_var{超過•個糾:_var._ var[1J^ var(2],_ var(3]) 例:char a;long b; M.WJ ASM 名:日T_a, 圍」>罔 •同邯變1ft : CRTRR^CRS …C 超過'■' ^1: CR1. CR1[1)n CR1[2], CR1[3]),捷屮「吸位足按編譯阴疔:来冊列的.所以.如卑改醱厂迅我的怕序.仃可能帯編岔 就薯改噓T .而且貼吊建數嚏柯熾用過干會口相應的備編伞.Ltill r 上例屮的r 划畢沒有先賦帕r=0;刖會找不到CR4而報皓. 例:void fun{) <char aJong b; a = 0;b=0;打时祸 ASM r t - a -CR1, t)^CR2h CR2[ 1 ],CR2[2J,CR 2(3]}« 自:i 數 :ramefa, b) t^name( 跌十:獸科:named .name 1 ,name2--) 例:void fun{ctiar a .char b)會晒的 ASM 名:fun — fun, s-KfunO. b^furl• static 出現在内底整編内.冈勇它的烷編色址曲機的.«如果不知道鳞裁所對應的輩編勒H 可坦看廉出的asm 悄屮叭#pragma debug variable 8 2 CR1 d1其中d1 色數.CR1d 1冋打瞰削-翔昌名,當擂.要先彌鞍0跖才會產出asm fS.Eg: char a; int b; voidfun(char p1,int p2)#asm[label:] opcode [opera nds]#endasm{a = p1;#asm // b = p2;MOV A,fun1MOV _b,AMOV A,fun1[1]mov _b[1],A#endasm}void main(){int d1;char d2;unsigned char q, r;r = 0;q = d1 / d2; // get quotient #asm // r = q;MOV A, CR3 ; CR3 qMOV CR4,A ; CR4 r#endasm#asm // fun(d2,d1)MOV A,CR2MOV fun0,A ; p1 = d2MOV A,CR1MOV fun1,AMOV A,CR1[1]MOV fun1[1],A ; p2 = d1CALL _fun#endasm}11.预编译指令12.编译器特殊选项格式^pragma keyword [ options )臬垒keyword 卩丁肓options,長格列出pragma keywords①ROM bank HT4U6②凡具備多個RAM bank及只有-個ROM bank記憶體的黴控制器(例如HT82M99AE )此功能”有效3凡具備禺個RAM bank記悝閒的微控制器(例如HT46R63)此功能F有效•#pragma bp free#pragma bp nofree對於這兩個亦眩處埋指令所包含前麒述式(staternents),編譯器會將產出之指令碼中所有會改弊BP暫存器的指命11除,也就罡MOV BP T A指令不會產出-主要是牆減編譯產出的拾令码大小一前題是必須確罡變數所在的記憶缠皆是固定的RAMbank.從pragma bp_free之後的救述開始.直到#pragma bp_noltee盘iL可特兩個前置處理指會加在丽式中的任何敘述的册黴•#pragma function fiinctjon_name @rom_address権定祇ftincton_name安置於ROM記憶耐rom_address竝址處.rom_address可価用卜六進制,例如0x100代哀棍扁式放於ROM記憶證的256桂址處. 述果哪牧在RCM bank 1的256廿址.則將rom_address設:爲0x2100•#pngma nobp□對中謝服務涮武有或-指示鶴澤髀个夏TF中斷贸務函式中保存BP暫存務前內春-逼個拒命會對星-程式愴案內所口的中斷服務函式有效-#pragmo ncl0»l functk)n_name針對…般的函式一對於想定的蘭式” hindion_name在鵜澤時將函式使用到的厨部费敕與內『暫存髀皆謎成•纓型匪英變數,而和會與荔他變數4£^RAM記憶空間的共用型態(commontype). 口里中詬般務爲式會呼其也函式時,這些被呼叫为函式中便用旳石部或內部耋數若與共他函式共用RAM空間.苜有宾料披礦壇的乐瞼•逗個前置處理指命將排除逗極風瞼.-#pngma nompO#pngma nompl只對中詬服務函式有效.指示編譯SS不變在中斷服務函式中保存MP0或MP1暫存痔的內容.這個播书會對軍-程式粽案內所百的中斷服務函式有效舉譯番會根據議控制器的袈情決定卮否在中斷服務函式內保存BP r MP0r MP1暫存器的內容•#pragma nmbankO#pragma norambsnk慨童數存放在RAM bank 0的空閭內.所有宦義在這兩個前匿堪理指令內的蚩數皆被安S卡秤RAM bank 0空間.E畏悄控制器只昱僑個RAM bank,則不需夏頑用須個捐塔.如杲黴控制器具有一WTX上酌RAM hank時•可以使用.若釁數足bit資料型態時,則貼須要將變數定義在RAM bank 0之中-#pragma roimbankO#pr^gnna noromb^nk將函式般许蓟ROM bankO內.所有定義於运兩厢丽竇电理描命中的函式皆被安賈ROM bank □的空間內flinction_name2 [, ..J-#pragma roimbank banknum function namel [r适個忙直喘埋橫令首將所卷走菟函叢安蚩?F描定的ROM bank寺中一怕nknum是ROM gnK的肩睨,叫依據微控制器叭ROM Z桶〕殳定广.ftjnction_name 1 ,function_nanne2层两式名‘可以同特指定-個IX I■的兩式--#pragma vector isr name ©vector address宣告中斷眼務函式晞字及中斷向五-樹冲畑務施式MSB先宜告一isr_name是葩名稱.vector_address星中謝向量數伯•#pragma novectomest指示中斷服務函式中,保留曹存暮的記憶空間只有一組.當微控制譽的中斷事件不允許重!ft 囊生,磁須處理完成前一個广緩才能Bfi理卜個時丫使用此前置處理指令可以IB眷資料記憶空111] (RAM space),避鬼RAM bank 0 的空間滿龍(overflow)旃辱閹47節中斷锲務函式昂說明13.内嵌函数■ n接組譯成組合藉诗指令的內建碉式C函式組合語吕带令碼(assembly instruction)void _clrwdt{) CLR WDTvoid_clrwdt1( )CLR WDT1void _clrwdt2() CLR WDT2void _halt() HALTvoid _nop() NOP■其他內建储迓void_ir(char*p)將抬橈p抬到的位元紐(1 byte)向右旋轉--個位元(bit) 例如’ ch = CxA5 ; _rr(&ch);則ch = 0xD2¥oid」「「(int *pl)將指標pl指到的字元組(2 byte)向右旋轉一個位元(bit) 例如T ent 匸0xA5A5; Jrr(&cnt);則ent = 0xD2D2void_i1 (char *p) 指標p指到的位元組(1 byte} I旬左旋轉一個位元(bit) 例如,ch = OxAS ; i_rl (&ch);則ch ■ 0x4Bvoidjrl (int *pl)將拒權"pl指到的字元組(2 byte)向九碇轉-個位元(bit) 例如.ent = 0xA5A5 : _lrl (&cnt);則ent = 0x4B4Bvoid _swap(char *p)將帛標p扌旨创的位元組(1 byte}四個低位元與叫個馮位元互換例如(ch = 0xA5 ; swap (&ch);則ch = 0x5Avoid _dela.y(unsigned long tick)延時tick 個指令週期(instruction cycle)tick <= 263690,若tick = 0,則表示無限延時(infinite loop)14.刃外.标头档(h)屮宦义的符号口旺._pdf与to皆不婴便用. 例如r iflf c ) a - ah + bh + ];就是不好的耳法°。
合泰单片机C语言教程讲解
![合泰单片机C语言教程讲解](https://img.taocdn.com/s3/m/0f8293a1168884868662d671.png)
Holtek 微控制器應用範例–使用Holtek C 語言目錄第一章內容簡介第二章選定Holtek C 語言的使用環境2.1 進入HT-IDE3000 建立新的專案時, 選定Holtek C 編譯器2.2 已開啟專案後, 選用Holtek C 編譯器第三章微控制器C 語言程式的速成3.1 定義主函式main()3.2定義副函式(sub-function)3.3定義全域變數(global variable)3.4定義中斷服務函式(Interrupt Service Routine : ISR)3.5 其他第四章 C 語言程式4.1 C 程式架構4.2 開始用C 語言設計一個程式4.2.1 定義主函式main4.2.2 將標頭檔引入(include a header file)4.2.3 定義文字符號及變數4.2.4 設定微控制器及裝置的初始狀態4.2.5 設計子函式4.2.6 設計中斷服務函式4.3變數(variable) 及資料型態(data type)4.3.1 變數名4.3.2 資料型態4.3.3 變數的有效範圍(scope)4.3.4 變數的資料型態(data type)整數型(integer)浮點型(floating point)4.3.5 bit 資料型態4.3.6儲存類別(storage class) 與修飾詞(qualifier)儲存類別(storage class)修飾詞(qualifier)4.3.7絕對變數(absolute variable)4.3.8常數(constant)4.3.9指標(pointer) 與陣列(array)指標的運算子& 與*陣列(array)4.3.10結構(struct) 與等位(union)結構的運算子-> 與.4.4運算子(Operators)運算前的型態轉換4.5程式流程控制(program flow control)4.5.1if-else 敘述4.5.2switch 敘述4.5.3for 敘述4.5.4while 敘述4.5.5do-while 敘述4.5.6goto 敘述4.5.7break 與continue 敘述4.6函式(Functions)4.6.1參數(arguments)4.6.2返回值(return values)4.7中斷服務函式(Interrupt Service Routines)4.8在C 語言程式中嵌入組合語言(in-line assembly code)從組合語言的程式去存取 C 語言的物件(變數)4.9前置處理指令(Preprocessor)4.9.1 定義文字符號(#define)4.9.2引入檔案(#include)4.9.3內嵌組合語言(inline assembly)4.9.4 條件式編譯(#if/#endif)4.9.5 編譯器的特殊選項pragma4.10Holtek C 編譯器的內建函式(built-in functions)第五章基本 C 語言程式5.1 語法觀念5.2 迴圈的應用(loop)5.3 撰寫MCU 應用程式的注意事項5.4 可供微控制器應用程式使用的範本5.5 設計微控制器應用程式的小技巧第六章程式範例–初級6.1LED 跑馬燈6.2LED 霹靂燈6.3 單顆七段顯示器6.4 5*5 點矩陣LED 顯示6.5 HT48 微控制器控制HT1621 LCD 的顯示6.6 HT48 微控制器控制LCD 模組的顯示6.7 具LCD 驅動功能的微控制器之顯示應用程式– HT46R636.8 顯示器的通用函式– HT44780 LCM6.9 鍵盤掃描程式第七章程式範例–中斷函式7.1 用時鐘控制LED 的亮與滅7.2 類比/數位轉換(ADC) 的應用第八章HT46R52A 應用於鎳氫電池充電器(HA0084T)第九章程式範例– HT46R74D-1 胎壓計(HA0105T)第一章內容簡介盛群半導體公司(Holtek)開發一系列的八位元微控制器(micro-controller, MCU). 當開發微控制器的應用程式時, 除了可使用盛群提供的組合語言(assembly language),也可使用標準的C 語言編譯器(C compiler).由於八位元微控制器的記憶體空間, 不論是程式記憶體(program memory space)或是資料記憶體(ram memory space), 皆是有限制的, 通常會使用組合語言開發應用程式. 但是越來越多的微控制器支援更多的記憶體以及更多的功能, 使得程式也相對的擴大. 如果仍然使用組合語言開發程式, 不但費時費力, 未來在維護及擴增功能的工作上也相當困難.因此, 使用高階程式語言, 例如C 語言, 來開發應用程式就是一種可行的趨勢.C 語言是高階程式語言中的一種, 它具有高度的的可讀性及可移植性(portability),除了能夠快速地完成應用程式的開發與偵錯, 也很容易移植到其他的微控制器上. 當程式需要縮減或擴充功能時, 也很容易的完成, 因此很適合於微控制器的程式開發.本書主要是以Holtek C 語言為主, 說明如何使用Holtek C 語言撰寫盛群微控制器的應用程式, 包括 C 的程式架構, C 語言的一般用法, 特殊用法及應用範例書中將說明在開發微控制器的應用程式時需要注意的地方及如何撰寫會比較恰當, 並配以實例解釋.讀者可以參考修改或直接採用到自己的程式中, 再用發展工具HT-ICE, HT-IDE3000 驗證之.第二章介紹選用Holtek C 編譯器的步驟, 指引HT-IDE3000 呼叫Holtek C 編譯器去編譯C 語言的原始程式.第三章提供一種快速撰寫 C 程式的方法, 對ANSI C 語言熟悉的用者, 可於閱讀本章之後即開始撰寫微控制器的 C 語言程式第四章介紹C 語言, 未曾使用過 C 語言的讀者應仔細閱讀本章以了解 C 語言的用法第五章介紹使用 C 語言寫程式的基本觀念, 注意事項及建議的寫作方法第六章到第九章則是應用範例, 針對盛群各系列的微控制器, 以 C 語言撰寫的應用程式. 包含有功能說明, 應用電路及程式說明.文件編號版別 1.20日期2008/5/26 第5 頁共189 頁第二章選定Holtek C 編譯器的使用環境2.1 進入HT-IDE3000, 建立新的專案時, 選定Holtek C 編譯器進入HT-IDE3000 開發環境後, 依照下列方法建立一個新的專案(project)→ 移動滑鼠游標到Project 選單, 按左鍵→ 移動滑鼠游標到New 命令, 按左鍵→ 出現如下的視窗, 在Language Tool 之處勾選Enhanced Holtek C compiler/Assembler文件編號版別 1.20日期2008/5/26 第6 頁共189 頁2.2 已開啟專案後, 如何選用Holtek C 編譯器若專案(project) 已開啟之後, 可以點選(click) Option 選單下的Project Setting 命令,在Language Tool 中點選Enhanced Holtek C Compiler/Assembler 以設定使用Holtek C 的Enhance 版編譯器Enhance 版的C compiler 包括ehcc32srsc.exe , ehcc32mrsc.exe 與ehcc32mrmc.exe 三個執行檔此版本必須在HT-IDE3000 V7.0 或以上的系統才能執行第三章微控制器 C 語言程式的速成本章介紹如何快速撰寫微控制器的 C 語言應用程式. 已熟悉ANSI C 標準語言的用法或有撰寫的經驗者, 在閱讀此章後即可開始設計撰寫微控制器的 C 應用程式, 以下各節是基本的C 程式成員, 某些是必須要有的, 如3.1, 其他的則視微控制器的功能及應用來決定是否需要3.1 定義主函式main()#include “ht46r63.h”void main(void){int Flag ;……TurnOn_LCD() ;Flag = LCD_display(cstr) ;TurnOff_LCD() ;……}主函式的返回資料型態(return type)必須是void, 而且不能有參數檔案ht46r63.h 定義與微控制器有關的常數, 例如暫存器的位址定義, 將之引入(include) 可增加程式的可讀性.3.2定義副函式(sub-function)視程式的大小及功能決定是否需要定義副函式. 基本上, 主函式應將應用程式的架構做成模組化, 不需要將所有的程式皆放在主函式中. 為了能很快的完成及了解應用程式, 主函式中只需要包含(呼叫) 定義各功能的副函式即可, 無論在設計或維護程式時皆能很快的進入與完成.例如, 關於LCD 的開啟, 顯示及關閉等功能就可分別定義為單獨的副函式, 如下例. 任何其他的函式或其他的應用專案都可去呼叫這些副函式. 若設計成通用型的, 也可藉由程式館管理器(Library Manager) 將之建入程式館檔案, 以供其他應用專案使用.void TurnOn_LCD(void){}int LCD_display(char *cstr){}void TurnOff_LCD(void){}3.3定義全域變數(global variable)程式在運行中會需要一些變數做為資料存放的地方, 由於微控制器資料記憶體大小的限制及C 編譯器的設計, 最好將常需使用的變數定義為全域型的變數, 在編譯程式的大小與執行上皆較佳. 例如定義常數型指標變數cstr 指到字串“Hello!”, 則可如下const char *cstr = “Hello!” ;3.4定義中斷服務函式(Interrupt Service Routine : ISR) 若微控制器的周邊裝置具有中斷功能,程式也需要此中斷機能以完成工作時, 則必須定義此周邊裝置的中斷服務函式(Interrupt Service Routine, ISR), 如下的格式#pragma vector ISR_tmr0 @ 0x0cvoid ISR_tmr0(void){tick++ ;}中斷服務函式必須遵守下列規定→ 返回的資料型態必須是void→ 不能有參數(必須為void)→ 必須使用前置處理指令#pragma vector 設定中斷向量值(interrupt vector), 在函式名稱(本例子是ISR_tmr0) 之後加上@ 及中斷向量值(本例是0x0c). 也可使用先前定義好的常數, 例如#define VECTOR_TMR0 0x0c#pragma vector ISR_tmr0 @ VECTOR_TMR0void ISR_tmr0(void){}3.5 其他上述的主函式, 副函式及中斷服務函式不需要定義在同一個原始程式檔案內. 為縮短編譯的時間, 最好是分別定義在不同的檔案中, 並使用有意義的檔名, 方便日後找尋所要的函式.第四章 C 程式語言基本上, Holtek C 是仿ANSI (美國國家標準局) 標準的 C 語言, 為配合盛群八位元微控制器的架構, 將提供一些特殊的語法去存取或控制微控制器的資源. 另外, 本章會從八位元微控制器的角度, 說明如何使用 C 語言設計及撰寫微控制器的應用程式4.1 C 程式架構C 語言的程式是由敘述(statements) 所組成, 每個敘述的最後必須有分號‘;’ 做為結束符號.敘述分為四類:→ 宣告(declaration), 宣告變數及資料型態, 資料結構.例如char flag, tick_cnt ; // 宣告變數flag 與tick_cnt 為char 型態→ 定義(definition), 定義變數數值及位址例如int total = 10 ; // 定義變數total, 設定值為10→ 描述式(expression), 執行數學及邏輯運算, 控制程式的流程例如count = ( input > 10) ? 10 : input ;→ 函式呼叫(function), 執行函式的功能例如putchar(ch) ; // 寫出一個字元到輸出口每個敘述可以附加註解做說明. C 編譯器不會對註解做編譯, 下列為兩種可被接受的註解→ 介於符號/* 與符號*/ 之間的數據及文字, 包括換行字‘\n’如果/* 與*/ 不在同一行, 則其間所有的行皆會被視為註解例如/* this is a comment 1 */→ 從符號// 開始到本行的結束皆被視為註解例如// 這是註解的新寫法在 C 語言中, 程式執行區(program block)是以函式的格式定義, 因此, 所有要執行的敘述皆需定義(包含)於某個函式(function) 中, 例如描述式.4.2 開始用C 語言設計一個程式依照下列步驟¸使用 C 語言實作一個簡單的應用程式4.2.1 定義主函式main範例void main(void){}在 C 語言中, 主函式main 是程式執行的起點, 有如組合語言程式中的startORG 00jmp startstart :void 是資料型態, main 與void 皆是保留字, 必須用此字, 小寫字母4.2.2 將標頭檔引入(include a header file)範例#include “ht46r63.h”// 引入標頭檔ht46r63.hvoid main(void){}標頭檔ht46r63.h 中定義許多與微控制器有關的變數及文字符號(symbol). 接下來寫程式時可以使用這些變數與文字符號(symbol), 好處是寫程式或維護程式時會很容易了解程式的功能, 增加程式的易讀性. 例如unsigned char _pa @0x12 ;定義_pa 是一個unsigned char 型態的變數, 它的位址在RAM 的0x12 (就是A埠, port A). 所以程式中如下的敘述_pa = 0 ;則與組合語言的CLR PA ; (PA=[12H]) 有相同的功能4.2.3 定義文字符號及變數在程式中使用文字符號能夠更容易的讀懂程式及修改, 例如定義文字符號_pa0 如下#define _pa0 _12_0表示_pa0 是RAM 位址12H 的位元0 (bit 0), 就是 A 埠的位元0. 下列敘述_pa0 = 1 ;表示將 A 埠的位元0 設為1, 與組合語言程式的SET [12H].0 有相同的功能前置處理指令#define 是定義一個文字符號代表數值, 或是文字串, 或是巨集指令.C 編譯器的前置處理器(preprocessor) 在編譯前, 會先替換這些定義的文字符號.前置處理指令#undef 是將先前定義過的文字符號取消, 變成無效. 詳細的說明請參閱第 4.9 節微控制器中其他暫存器的變數或文字符號, 皆定義於對應之微控制器的標頭檔案內, 在設計程式時可參考之. 可以定義一些程式需要, 但是在標頭檔案中沒有定義的變數或文字符號, 方便程式的開發及維護, 例如#include #define “ht48R50A-1.h”scl _pa3 // SCL (時鐘線) 接到MCU 的A 埠的第3 位元#define scl_c _13_3 // A 埠之控制暫存器的第3 位元(bit 型變數)#define sda _pa1 // SDA (資料線) 接到MCU 的A 埠的第1 位元#define sda_c _13_1 // A 埠之控制暫存器的第1 位元void main(void){}定義四個文字符號scl, scl_c, sda, sda_c 分別代表不同的輸出/輸入埠定義變數會佔用RAM/ROM 的空間, 如果又指定位址, 則此變數佔用此位址, 否則Linker 在做連結時才會分派位址給變數. 其效果有如組合語言的_pa DB ?定義文字符號的效果則與組合語言的EQU 相同, 例如#define scl _pa3 與scl EQU _pa3有相同的效果4.2.4 設定微控制器及裝置的初始狀態根據程式的功能, 設定微控制器中各裝置的初始值, 例如周邊設備的初始狀態, 暫存器的型態等.scl_c = 0 ; // 設定SCL (= PAC) 的狀態為輸出sda_c = 0 ; // 設定SDA (=PA) 的狀態為輸出4.2.5 設計子函式獨立之功能可分別用子函式完成, 在程式的偵錯, 維護及重複使用上皆有好處. 在設計時需要注意函式的參數,返回值等. 通常會將主函式main() 放在程式檔的最後, 各個子函式定義在前面或其他的程式檔案內. 下列範例只是部份, 詳細的說明可參閱4.6 節.#include “ht48r50a-1.h”// 引入標頭檔#define scl _pa3 // SCL (時鐘線) 接到MCU 的A 埠的第 3 位元#define scl_c _13_3 // A 埠(位址0x13)之控制暫存器的第3 位元(bit 型變數) #define sda _pa1 // SDA (資料線) 接到MCU 的A 埠的第1 位元#define sda_c _13_1 // A 埠(位址0x13)之控制暫存器的第1 位元// 函式: StartCondition() 子函式// 功能: 開始一個命令// 輸入: 無// 輸出: 無void StartCondition(void){sda = 1 ; // SDA 輸出highscl = 1 ; // SCL 拉highsda = 0 ; // SDA 輸出lowscl = 0 ; // 完成Start of command}// 函式: StopCondition()// 功能: 結束先前的命令// 輸入: 無// 輸出: 無void StopCondition(void){}// 函式: main()// 功能: 主函式// 輸入: 無// 輸出: 無void main (void){unsigned char Rdata, type ;// 暫存器的初始設定scl_c = sda_c = 0 ; // 將A 埠的位元1, 3 設為輸出型態(SCL, SDA 為輸出)StartCondition() ; // 呼叫子函式……}4.2.6 設計中斷服務函式針對有硬體中斷的微控制器, 需要設計中斷服務函式以處理中斷事件定義周邊裝置的中斷服務函式(Interrupt Service Routine, ISR) 如下格式#pragma vector ISR_tmr0 @ 0x0cvoid ISR_tmr0(void){tick++ ;}中斷服務函式必須遵守下列規定→ 返回的資料型態必須是void→ 不能有參數→ 必須設定中斷向量值(interrupt vector), 在函式名稱(本例子是ISR_tmr0之後加上@ 及中斷向量值(本例是0x0c). 也可使用先前定義好的常數, 例如#define VECTOR_TMR0 0x0c#pragma vector ISR_tmr0 @ VECTOR_TMR0void ISR_tmr0(void){}4.3變數(variable) 及資料型態(data type)程式執行過程中, 可能會需要暫存一些資料, 例如旗標, 執行次數, 延遲秒數等, 因此就必須定義變數以儲存這些資料. 由於變數要佔用程式記憶體(PROM) 或資料記憶體(RAM), 因此在使用變數之前, 定義變數的資料型態, 以便讓編譯器正確的編譯程式及配置記憶體空間.除了資料型態之外, 還可加入儲存類別(storage class) 及修飾詞(qualifier), 對變數做更詳細的安置.4.3.1 變數名變數名的規則→ 第一個字元必須是英文字母或底線符號(underscore), 之後可緊接著字母或數字→ 變數名的前32 個字元有效→ 變數名內不可有+, - , *, / , ……等符號字元→ 英文字母的大小寫是有區別的(case-sensitive), 例如count 與Count 是不同的變數名範例, number, total_tick, _tick 是合法的變數名, 而2num, $dot, line\n 是非法的變數名4.3.2 資料型態* float, double 皆使用IEEE754 32 位元的格式4.3.3 變數的有效範圍(scope)根據變數定義的所在¸決定此變數的有效範圍. 可分為→ 區域變數(local variable)定義在程式區塊內(program block, 例如函式)的變數皆是區域變數. 只有當此程式區塊被執行時, 區域變數才會有效, 而在執行完畢並離開此程式區塊後, 這些區域變數將無效. 程式區塊是指包含在左右大括號‘{‘ 及‘}’ 之間的敘述行定義在函式中的static 變數則是全域變數, 參考 4.3.2 說明→ 全域變數(global variable)定義在所有函式之外的變數為全域變數. 當程式在執行時, 此變數皆有效, 任何函式都可以存取或修改這個變數範例#include “ht48r50a-1.h”unsigned char flag ; // 全域變數void main(void){ char type ; // 區域變數, 只有在此函式被執行時才有效static status = 0 ; // static 變數, 只在第一次執行時設為0……}4.3.4 變數的資料型態(data type)當宣告變數時,必須指定它的資料型態, 以告知編譯器此變數所需記憶體的大小. 資料型態分為整數型(integer type)及浮點數型(floating point type). 整數型又可區分為有正負號(signed) 及無正負號(unsigned).整數型(integer)→ char佔用一個位元組(byte) 的記憶體空間. 如加上signed 則表示有正負號, 其大小範圍是–128 到127. 若加上unsigned, 則表示沒有正負號, 其大小範圍是0到255. 如果沒有signed 或unsigned, 則被視為signed. 可用此型態定義字元,如‘A’, ‘d’, ‘$’, ‘3’等→ short佔用兩個位元組(2 bytes) 的記憶體空間, 如加上signed 則表示有正負號, 其大小範圍是–32768 到32767. 若加上unsigned, 則表示沒有正負號, 其大小範圍是0 到65535. 如果沒有signed 或unsigned, 則被視為signed.Holtek C 採用little-endian 格式, 就是變數的低位元組(least significant byte) 存放在記憶體的低位址. 例如變數count = 0x1234 是存放於記憶體40H 的位址, 則低位元組的數值0x34 存放於位址40H, 高位元數值0x12 存放於位址41H.→ int與short 型態相同→ long佔用四個位元組(4 bytes) 的記憶體空間, 如加上signed 則表示有正負號, 其大小範圍是–2147483648 到2147483647. 若加上unsigned, 則表示沒有正負號, 其大小範圍是0 到4294967295. 如果沒有signed 或unsigned, 則被視為signed在little-endian 格式中, 32位元的變數, 則是先存低字元(least significant word) 的低位元組(least significant byte)到記憶體的低位址, 再存放低字元的高位元組(high byte), 再存放高字元(high word)的低位元組, 最後才是高字元的高位元組浮點型(floating point)Holtek C 支援IEEE 754 32 位元的格式. 包括float 及double 兩個資料型態, 浮點數值是以下表的格式儲存在記憶體與浮點數值的關係式為number = (-1)sign x 2(exponent – 127) x 1.mantissa例如, 浮點數為 2.77000e+37 在儲存到記憶體時換成7DA6B69B 共佔32 位元4.3.5 bit 資料型態類似整數型, 但是只有0 或 1 兩個值, 所以只會取整數的最低位值(LSB:least significant bit) 需要注意下列用法→ bit 型態不可與auto 一起使用, bit 型態的變數不可當函式的參數, 不可用於指標(pointer) 的數據型態, 不可設定靜態初始值(static)→ bit 型態可以設為函式的返回型態, 它是存於累加器(accumulator) 的相對位置→ 程式開始執行時, 不會設定bit 型變數的初始值, 因此程式必須自行設定初始值→ 以下是合法的使用方式static bit init_flag ; // 定義於函式內則被視為區域變數bit toggle_flag ;→ 範例int data = 0x54 ;bit flag ;flag = data ;則flag = 0 (取data 的LSB)如果微控制器具有一個以上的RAM bank, 例如HT46R63, 在定義bit 型態的變數時需要使用前置處理指令#pragma rambank0 指定在RAM bank 0, 如下#pragma rambank0bit flag ;#pragma norambank4.3.6儲存類別(storage class) 與修飾詞(qualifier)變數於宣告或定義時必須指定其資料型態, 但是儲存類別及修飾詞是可選擇的, 可根據應用時的需要去設定或不使用.儲存類別(storage class)儲存類別與區域變數(local variable)及全域變數(global variable)有關.→ 儲存類別autoauto 是給區域變數使用的, 沒有指定儲存類別的區域變數皆是auto寫與不寫auto 都是相同效力. 區域變數是存放在RAM bank 0 的空間→ 儲存類別registerregister 與auto 類似, 是給區域變數用的, 當變數的存取很頻繁時, 可將之設為register, C 編譯器會使用暫存器而非資料記憶體空間來存放此變數, 如此可增加存取的速度及減少編碼. 目前並未實做此功能.→ 儲存類別staticstatic 的變數會一直有效到整個程式結束後才失效. 它的初始值只會在程式開始執行時被設定一次. 雖然static 的變數在程式結束前皆有效, 但是定義在函式內的static 變數仍然是區域變數, 必須要在它所定義的函式中才可以讀寫→ 儲存類別externextern 通知C 編譯器此變數是定義在其他的程式檔內, 需要經由連結器(Linker)連結定義此變數的檔案後, 才知道變數的所在.以目前在微控制器的應用程式上, 比較需要使用extern, 其他三種不具特別的優勢可用定義全域變數(global variabl)的方式即可達到相同效果. 建議不要使用.修飾詞(qualifier)→ 修飾詞constC 編譯器會將const 的變數放置於程式記憶體(PROM). 在定義const 變數時, 必須要設定其值, 而程式在執行中不能修改此變數的值→ 修飾詞constant這個修飾詞是Holtek C 編譯器特別提供的. 它會將constant 的變數放置於程式記憶體(PROM) 的最後一頁(last page). 定義constant 變數時,必須要設定其值, 而程式在執行中不能修改此變數的值. 使用此修飾詞要注意下列三點●只能使用在int 或unsigned int 的資料型態●設定值必須配合微控制器程式記憶體的寬度, 例如, 若使用在 HT48R50A-1 時,因為此微控制器的寬度為 15 個位元, 最高位元是無效的, 所以 0x9A 會被 C編譯器改成 0x1A. 最高位元, 位元 15 被清除為 0● 所有設定此修飾詞的變數或陣列, 總共佔用的字位元組 (word) 不可超過 256 個指定詞(specifier)→ 指定詞typedeftypedef 是針對資料型態做新名稱的宣告, 不是宣告資料型態的新變數, 而是宣告一個新的名字. 例如將UCHAR (新名字) 宣告為unsigned char 的資料型態, 可使用typedef unsigned char UCHAR ; // UCHAR 為unsigned char 的新名字UCHAR count ; // 變數count 的資料型態為unsigned char// 等同於unsigned char count ;使用typedef 宣告資料型態的新名字可以讓程式的可讀性更高, 更易了解. 例如,typedef unsigned int WORD ; // 使用WORD 代表unsigned int, 16 bitstypedef unsigned long DWORD ; // DWORD 代表32 bit 的double word4.3.7絕對變數(absolute variable)可以將全域變數或static 變數指定一個固定的記憶體的位址, 例如unsigned char PortA @ 0x12 ;在變數名的後面再加上‘@’及位址C 編譯器在編譯時會將程式中出現絕對變數的程式改為此位址, 但並未在記憶體中保留位置給此變數, 所以從連結器(Linker) 產出的對映檔(map file)中找不到此變數 C 編譯器會將之翻成組合語言的EQU 指令,如下_PortA EQU 12h此種用法主要是對微控制器內的暫存器做定義, 方便閱讀程式4.3.8常數(constant)整數型常數(integral constant) 可使用基底(radix)格式表示之.若常數的最後一字為l 或L, 則表示它使用signed long 或unsigned long 的型態. 字尾是u 或U, 則表示常數為unsigned 型態.浮點型(floating point)常數的型態是double, 若它的字尾是 f 或F, 則是float.字元常數(character constant)必須以單引號‘ ‘ 框住, 例如‘a’字串常數(string constant) 必須以雙引號“ “ 框起, 例如“Hello!”. 字串常數的定義會影響它所儲存的記憶體位址, 如下char *cp = “one” ; // C 編譯器會發出錯誤const char *sptr = “Hello” ; // “Hello” 儲存在程式記憶體(PROM) 常數型的變數或陣列(array)必須要設定其值, 否則C 編譯器會發出錯誤訊息,如上例4.3.9指標(pointer) 與陣列(array)指標本身是一個變數, 它的內容是另一個變數存放的位址, 類似組合語言的間接定址.在使用上, 指標必須要指到一個已定義(存放於記憶體) 的變數, 否則在程式執行時會發生錯誤. 指標的宣告格式資料型態*指標名[, *指標名,….] ; 資料型態是這個指標所指的變數的資料型態, 例如char. 指標名類似變數名, 可以在一行中, 宣告指向相同資料型態的不同指標名, 例如char *tptr, *array_ptr ;int *line_ptr ;以上只是宣告指標變數, 必須要將這些指標指向已定義的變數才能使用指標的運算子& 與*運算子& 如果緊鄰在變數的前面, 例如&line, 則是代表取得此變數的記憶體位址例如,int line ; // 定義變數int *line_ptr ; // 宣告指標line = 12 ;line_ptr = &line ;若變數line 被安置於RAM 的位址64, 則指標line_ptr 等於64運算子* 緊鄰指標變數之前是表示取得這個指標指到的變數的內容, 承上例, int total ; // 定義變數total = *line_ptr ; // 取得指標line_ptr 所指到的變數line 的內容則變數total 等於12指標的大小會根據微控制器具有之記憶體空間大小而定, 如果微控制器具有一個以上的RAM bank, 則指標本身會使用兩個位元組來儲存被指到的變數的位址如果變數有const 或constant 修飾詞, 則是指向程式記憶體(PROM), 而且此變數的內容不能被修改. 如果所指向的變數不具有const 或constant, 則指標會指向資料記憶體(data memory, RAM) 內的變數.陣列(array)陣列是由相同資料型態的元素組成的, 例如char array_name[32] ;是由32 個char 型態的元素組成的, 這些元素的名字是以陣列名array_name 為準, 而以索引(index) 區分各個元素, 例如array_name[3] 是第 4 個元素. 陣列的索引是正整數, 從0 開始直到元素的總個數減一, 上例中, 最後一個元素是array_name[31]. 這種資料型態在建表格(table) 時非常有用陣列也可當做指標的一種, 只是使用時格式不同, 下列範例說明指標與陣列之間的使用方法char *nptr, *fptr ; // 宣告指標char ch, tbl ; // 定義變數char table[5] = { ‘a’, ‘b’, ‘c’, ‘d’, ‘e’ } ; // 定義陣列nptr = table ; // 指標nptr 指到陣列table 的第一個元素table[0]ch = *nptr ; // 將字元‘a’ 存入變數chtbl = table[0] ; // 將字元‘a’ 存入變數tbl , 所以變數ch 與變數tbl 的內容相同fptr = &table[4] ; // 指標fptr 指到陣列table 的第5 個元素, table[4]ch = *fptr ; // 將字元‘e’ (第5 個元素) 存入變數ch 內tbl = *(nptr+4) ; // nptr 指到陣列table 的第一個元素, 加4, 所以tbl = ‘e’4.3.10結構(struct) 與等位(union)結構是一個或多個成員的集合, 每個成員的資料型態可以不同, 並且使用結構的名字去讀寫這些成員. 結構的宣告是等同於定義一個新的資料型態, 當變數宣告為一個結構的型態時, 便可用結構的名字去讀寫各成員的內容.成員的資料型態不可以使用bit 型態, 但是可以用bit-field 方式宣告成員的型態, 例如struct str_name {unsigned flag : 1 ; // 此成員放於最低位元least significant bitunsigned no_used : 7 ;unsigned stack : 5 ; // 此成員置於最高位元high bits} usage ;每個bit field 會置放於16 位元的單位內, 不會橫跨兩個16位元的單位等位(union) 的格式與結構相同, 唯一不同的是記憶體空間的分配方式. 等位是安排共用的空間來存放不同資料型態的成員. 每個成員必須要宣告其資料型態, 而等位的大小則是所有成員中佔用最大位元組(bytes)的型態大小. 每個成員的開始位址皆相同, 就是等位的位址.union union_name {char num_byte ; // 佔用1 個位元組。
中文手册
![中文手册](https://img.taocdn.com/s3/m/c4e0d5300b4c2e3f56276300.png)
下表所列为命令模式 ID 和数据模式 ID 名称
模式命令应当在发送数据或命令之前执行 如果执行连续的命令 命令模式 ID 可以省略 当系统执行 非连续命令或非连续地址数据模式时 CS 脚应当置高电平 前一个操作模式将同时复位 当 CS 脚返回到 低电平时 接口 和 HT1620 接口只需 4 条线 CS 线用于初始化串行接口电路并终止主控器与 HT1620 之间的通信 如 DATA 线是串行数据输入/输出线 读写的数据和执行 RAM 中的数据在 RD 信号的下降沿输出 输出的数据 WR 线是 果 CS 脚置为 1 主控器与 HT1620 之间的通信先被禁止 然后初始化 在执行模式命令或进行模式切换时 需要一个高电平的脉冲初始化 HT1620 的串行接口 的命令都必须通过 DATA 线 RD 线是读时钟输入 将会出现在 DATA 线上 应当首先执行新的操作模式 ID
极限参数
电源电压 ......................................... -0.3V~3.6V 输入电压 ......................................... VSS-0.3V~VDD+0.3V 保存温度 ......................................... -50 工作温度 ......................................... -25 ~125 ~75
DC 特性
符号 VDD IDD ISTB VIL VIH IOL1 IOH1 IOL2 IOH2 IOL3 IOH3 RPH * 空载 参数 操作电压 操作电流 待机电流 低电平输入电压 高电平输入电压 DATA,BZ,BZ,IRQ DATA,BZ,BZ LCD 公共端灌电流 LCD 公共端拉电流 LCD 段灌电流 LCD 段拉电流 上拉电阻 3V 3V 3V 3V 3V 3V 3V 3V 3V 3V 3V 空载* 空载* DATA,WR,CS,RD DATA,WR,CS,RD VOL=0.3V VOH=2.7V VOL=0.3V VOH=2.7V VOL=0.3V VOH=2.7V DATA,WR,CS,RD CS=WR=RD=高电平 2.4 0.8 -0.6 80 -70 70 -30 40 1.6 -1.2 150 -120 140 -60 80 150 测试条件 VDD 条件 最小 2.4 2 1 典型值 最大 3.3 3 5 1 3.0 单位 V uA uA V V mA mA uA uA uA uA kΩ
合泰“配置选项”攻略_V100
![合泰“配置选项”攻略_V100](https://img.taocdn.com/s3/m/dada1bafcd22bcd126fff705cc17552707225e01.png)
合泰“配置选项”攻略_V100合泰“配置选项”攻略以HT66F50进行讲解QQ: 272987922目录一、什么是“配置选项” (2)二、系统电压SysVolt (2)三、系统频率SysFreq (2)四、Vdd(for selections of Internal RC) (3)五、系统高频High Speed System Oscillator (3)六、系统低频Low Speed System Oscillator (3)七、WDT时钟源 (4)八、HIRC频率选择 (4)九、低电压复位LVR (4)十、WDT使能 (5)十一、复位脚和IO共用 (5)十二、其它 (6)一、什么是“配置选项”“配置选项”英文名称Option,用户应根据实际应用情况,对MCU资源进行选择这些“基本配置”因后期不能通过“控制寄存器”来切换,因此在使用前,需根据实际应用环境来设定。
下图为HT66F50的掩膜配置二、系统电压SysVolt此处请输入您MCU的额定工作电压对于e-ICE,此处输入可让仿真器提供出对应的电压,省去您外接电压但对于HT-ICE,此处输入并不能使仿真器提供出您要的电压,HT-ICE只能固定5V(部分HT-ICE是3.3V)三、系统频率SysFreq此处请输入您MCU的额定工作频率当勾选“内部频率”时,仿真器变可为您提供出相对应的频率,省去您外接晶振四、Vdd(for selections of Internal RC)此处请选择同您MCU而定工作电压邻近的值!这个主要是为了告诉“烧录器”,看要在5V下校正内部HIRC,或者是在3V下校正如果您是使用芯片内部的HIRC,请务必正确选择如果您不使用HIRC,可忽略此选项PS:合泰已有着手优化了此步骤,通过自动解析“SysVolt”,自动选择此处的选项五、系统高频High Speed System Oscillator此处请选择您的系统“高频”来源HXT:代表您会外挂“晶振”,利用晶振来提供准确的系统频率ERC:代表您会外挂“RC”电路,来作为系统频率HIRC:代表您会使用MCU内部的RC振荡器来作为系统频率,误差精度为±2%如果您的系统高频精度要求不高,建议选择HIRC这样可以多出2个IO口,也节约成本六、系统低频Low Speed System Oscillator此次用来选择您的系统“低频”来源LIRC:代表您会使用MCU内部的32KHz来作为低频,有一定精度误差LXT:代表您会外接“RTC”低频晶振,一般式32.768KHz如果您的系统低频精度要求不高,建议选择LIRC这样可以多出2个IO口,也节约成本如果您不需要使用低频,可忽略此选项七、WDT时钟源此处用于选择看门狗的时钟源,如果您不使用WDT,可忽略此选项fsub:代表来自系统低频fsys/4:代表来自当前系统频率的4分频八、HIRC频率选择如果您高频是选用了HIRC了,那么此处是用于选择相对应的频率如果不使用HIRC,则可忽略此选项九、低电压复位LVR如果您要使用低电压复位,请选择Enable并选择对应的低电压点十、WDT使能如果要使用WDT,就选Enable如果不使用WDT,请记得要Disable,否则你的程序会不断复位十一、复位脚和IO共用如果你要使用外部复位电路,请选择RES Pin,同时记得要接复位电路!如果你不想接外部复位电路,请选择I/0 Pin,这样就可以不接复位电路,同时多出一根IO脚十二、其它1.可以看出合泰的这些配置排序不合理,有待改进比如:都是和WDT有关的东西,并没有排在一起,如下图2.使用配置的方式并不灵活,因此很多新开发的MCU,慢慢都取消了“配置选项”而改为可以直接用“寄存器”来控制比如可以透过WDTC控制寄存器,来控制WDT Enable or Disable。
HT-Writer 说明书
![HT-Writer 说明书](https://img.taocdn.com/s3/m/bf5f7455a9956bec0975f46527d3240c8447a1ef.png)
5
HT-Writer 使用手册
OTP 芯片脚位名称 PA0 PA1 PA2 PA3 PA4 PA5 PA6 OSC1 OSC2 VDD RESB VSS
烧录信息
AD0 AD1 AD2 AD3 CLK CSB RWB Ground (direct connection) Ground (direct connection) VDD VPP Ground (direct connection)
附加功能
→ Setting
此菜单包含 4 个命令用来设定 HT-Writer 烧录器的状态 这些状态将决定烧录 器的操作行为 以下为各命令的说明
• Detect Connect
此命令将侦测 HT-Writer 烧录器与 PC 间的连接状况 并且将结果显示于窗口中
• MCU
此命令指定目前的 MCU 型号 当做之后所有操作的依据 如果烧录器已经连上 PC 并且 开启电源 则此 MCU 的驱动资料将会被加载烧录器的闪存
HT-Writer 使用手册
本使用手册版权为盛群半导体股份有限公司所有 非经盛群半导体股份有限公司书面授权同意 不得透过任 何形式复制 储存或传输
目录
目录
简介 ........................................................................................ 1 安装 ........................................................................................ 1 硬件配备 ......................................................................... 5 使用 HT-Writer 烧录 OTP 芯片 .............................................. 6
HT46R 47R 48R 49R 系列OTP 单片机
![HT46R 47R 48R 49R 系列OTP 单片机](https://img.taocdn.com/s3/m/22956adfd15abe23482f4d18.png)
HT46R/47R/48R/49R 系列OTP 单片机选型指南HT46R22 OTP 单片机特点? 工作电压? fSYS=4MHz 3.3~5.5V? fSYS=8MHz 4.5~5.5V? 19 位双向输入/输出口? 1 个与输入/输出口线共用的外部输入? 16 位具有7 级预分频带溢出中断的可编程定时/计数器? 内置石英晶体或RC 振荡器? 看门狗定时器? 2048 14 位的程序存储器PROM? 64 8 位的数据存储器RAM? 支持发声的PFD? 具有暂停和唤醒功能来降低功耗? 在VDD=5V 且系统时钟为8MHz时指令时钟最快为0.5 μs? 6 层堆栈? 8 通道9 位分辨率8 位精度的A/D 转换器? 两通道6+2 或(7+1)位的PWM 脉宽可调输出通道与输入/输出口共用两个引脚? 位操作指令? 15 位查表指令? 63 条功能强大的指令? 指令执行时间皆为1 或2 个指令周期? 低电压复位功能? I2C BUS 总线(从模式下)? 24 脚SKDIP/SOP 封装概要该芯片为八位高性能精简指令集单片机专门为多输入/输出口的产品而设计的特别适合应用于像洗衣机控制器和家用电器类产品具有HALT模式可降低功耗程序区和掩膜选项区是可电编程烧录的使其适于产品应用开发HT46R23 OTP TP 单片机特点? 工作电压? fSYS=4MHz 3.3~5.5V? fSYS=8MHz 4.5~5.5V? 23 位双向输入/输出口? 1 个与输入/输出口线共用的外部输入? 16 位具有7 级预分频带溢出中断的可编程定时/计数器? 内置石英晶体或RC 振荡器? 看门狗定时器? 4096 15 位的程序存储器PROM? 192 8 位的数据存储器RAM? 支持发声的PFD? 具有暂停和唤醒功能来降低功耗? 在VDD=5V 且系统时钟为8MHz 时指令时钟最快为0.5 us? 8 层堆栈? 8 通道10 位分辨率9 位精度的A/D 转换器? 两通道6+2 或(7+1)位的PWM 脉宽可调输出通道与输入/输出口共用两个引脚? 位操作指令? 15 位查表指令? 63 条功能强大的指令? 指令执行时间皆为1 或2 个指令周期? 低电压复位功能? H-BUS 总线(从模式下)? 28 脚SKDIP/SOP 封装概要该芯片为八位高性能精简指令集单片机专门为多输入/输出口的产品而设计的特别适合应用于像洗衣机控制器和家用电器类产品具有HALT模式可降低功耗程序区和掩膜选项区是可电擦写的使其适于产品应用开发。
HT46C65资料
![HT46C65资料](https://img.taocdn.com/s3/m/f8f8382aaaea998fcc220e29.png)
HT46R65/HT46C65A/D with LCD Type 8-Bit MCURev.1.801July 14,2005Features·Operating voltage:f SYS =4MHz:2.2V~5.5V f SYS =8MHz:3.3V~5.5V·24bidirectional I/O lines ·Two external interrupt input·Two 16-bit programmable timer/event counter withPFD (programmable frequency divider)function·LCD driver with 41´3or 40´4segments(logical output option for SEG0~SEG23)·8K ´16program memory ·384´8data memory RAM·Supports PFD for sound generation ·Real Time Clock (RTC)·8-bit prescaler for RTC ·Watchdog Timer·Buzzer output·On-chip crystal,RC and 32768Hz crystal oscillator ·HALT function and wake-up feature reduce powerconsumption·16-level subroutine nesting·8channels 10-bit resolution A/D converter ·4-channel 8-bit PWM output shared with 4I/O lines ·Bit manipulation instruction ·16-bit table read instruction·Up to 0.5m s instruction cycle with 8MHz system clock ·63powerful instructions·All instructions in 1or 2machine cycles ·Low voltage reset/detector function·52-pin QFP,56-pin SSOP,100-pin QFP packagesGeneral DescriptionThe HT46R65/HT46C65are 8-bit,high performance,RISC architecture microcontroller devices specifically designed for A/D product applications that interface di-rectly to analog signals and which require LCD Inter-face.The mask version HT46C65is fully pin and functionally compatible with the OTP version HT46R65device.The advantages of low power consumption,I/O flexibil-ity,timer functions,oscillator options,multi-channel A/DConverter,Pulse Width Modulation function,HALT and wake-up functions,in addition to a flexible and configurable LCD interface enhance the versatility of these devices to control a wide range of applications re-quiring analog signal processing and LCD interfacing,such as electronic metering,environmental monitoring,handheld measurement tools,motor driving,etc.,for both industrial and home appliance applicationareas.Technical Document·Tools Information ·FAQs·Application Note-HA0003E Communicating between the HT48&HT46Series MCUs and the HT93LC46EEPROM -HA0004E HT48&HT46MCU UART Software Implementation Method -HA0005E Controlling the I2C bus with the HT48&HT46MCU Series -HA0047E An PWM application example using the HT46series of MCUsBlock DiagramRev.1.802July14,2005Pin AssignmentNote:The52-pin QFP package does not support the charge pump(C type bias)of the LCD.The LCD bias type must select the R type by option.Rev.1.803July14,2005Pin DescriptionPin Name I/O Options Description PA0/BZPA1/BZPA2PA3/PFD PA4~PA7I/OWake-upPull-highBuzzerPFDBidirectional8-bit input/output port.Each bit can be configured as wake-up in-put by ROM code option.Software instructions determine the CMOS outputor Schmitt trigger input with or without pull-high resistor(determined bypull-high options:bit option).The BZ,BZ and PFD are pin-shared with PA0,PA1and PA3,respectively.PB0/AN0 PB1/AN1 PB2/AN2PB3/AN3 PB4/AN4 PB5/AN5 PB6/AN6 PB7/AN7I/O Pull-highBidirectional8-bit input/output port.Software instructions determine theCMOS output,Schmitt trigger input with or without pull-high resistor(deter-mined by pull-high option:bit option)or A/D input.Once a PB line is selectedas an A/D input(by using software control),the I/O function and pull-high re-sistor are disabled automatically.PD0/PWM0PD1/PWM1 PD2/PWM2 PD3/PWM3I/OPull-highPWMBidirectional4-bit input/output port.Software instructions determine theCMOS output,Schmitt trigger input with or without a pull-high resistor(deter-mined by pull-high option:bit option).The PWM0/PWM1/PWM2/PWM3out-put function are pin-shared with PD0/PD1/PD2/PD3(dependent on PWMoptions).PD4/INT0PD5/INT1 PD6/TMR0 PD7/TMR1I/O Pull-highBidirectional4-bit input/output port.Software instructions determine theCMOS output,Schmitt trigger input with or without a pull-high resistor(deter-mined by pull-high option:bit option).The INT0,INT1,TMR0and TMR1arepin-shared with PD4/PD5/PD6/PD7.VSS¾¾Negative power supply,groundVLCD I¾LCD power supplyVMAX I¾IC maximum voltage connect to VDD,VLCD or V1 V1,V2,C1,C2I¾Voltage pumpCOM0~COM2 COM3/SEG40O1/3or1/4DutySEG40can be set as a segment or as a common output driver for LCD panelby 0~COM2are outputs for LCD panel plate.SEG0~SEG39O Logical Output LCD driver outputs for LCD panel segments.SEG0~SEG23can be optioned as logical outputs.OSC1 OSC2IOCrystal or RCOSC1and OSC2are connected to an RC network or a crystal(by options)forthe internal system clock.In the case of RC operation,OSC2is the output ter-minal for1/4system clock.The system clock may come from the RTC oscilla-tor.If the system clock comes from RTCOSC,these two pins can be floating.OSC3 OSC4IORTC orSystem ClockReal time clock oscillators.OSC3and OSC4are connected to a32768Hzcrystal oscillator for timing purposes or to a system clock source(dependingon the options).No built-in capacitorVDD¾¾Positive power supplyRES I¾Schmitt trigger reset input,active lowAbsolute Maximum RatingsSupply Voltage...........................V SS-0.3V to V SS+6.0V Storage Temperature............................-50°C to125°C Input Voltage..............................V SS-0.3V to V DD+0.3V Operating Temperature...........................-40°C to85°C Note:These are stress ratings only.Stresses exceeding the range specified under²Absolute Maximum Ratings²may cause substantial damage to the device.Functional operation of this device at other conditions beyond those listed in the specification is not implied and prolonged exposure to extreme conditions may affect device reliabil-ity.Rev.1.804July14,2005D.C.Characteristics Ta=25°CSymbol ParameterTest ConditionsMin.Typ.Max.Unit V DD ConditionsV DD Operating Voltage ¾f SYS=4MHz 2.2¾ 5.5V ¾f SYS=8MHz 3.3¾ 5.5VI DD1Operating Current(Crystal OSC,RC OSC)3V No load,ADC Off,f SYS=4MHz¾12mA 5V¾35mAI DD2Operating Current(Crystal OSC,RC OSC)5VNo load,ADC Off,f SYS=8MHz¾48mAI DD3Operating Current(f SYS=32768Hz)3VNo load,ADC Off¾0.30.6mA5V¾0.61mAI STB1Standby Current(*f S=T1)3V No load,system HALT,LCD Off at HALT¾¾1m A5V¾¾2m AI STB2Standby Current(*f S=RTC OSC)3V No load,system HALT,LCD On at HALT,C type¾ 2.55m A5V¾1020m AI STB3Standby Current(*f S=WDT OSC)3V No load,system HALT,LCD On at HALT,C type¾25m A5V¾610m AI STB4Standby Current(*f S=RTC OSC)3VNo load,system HALT,LCD On at HALT,R type,1/2bias,V LCD=V DD(Low bias current option)¾1730m A5V¾3460m AI STB5Standby Current(*f S=RTC OSC)3VNo load,system HALT,LCD On at HALT,R type,1/3bias,V LCD=V DD(Low bias current option)¾1325m A5V¾2850m AI STB6Standby Current(*f S=WDT OSC)3VNo load,system HALT,LCD On at HALT,R type,1/2bias,V LCD=V DD(Low bias current option)¾1425m A5V¾2650m AI STB7Standby Current(*f S=WDT OSC)3VNo load,system HALT,LCD On at HALT,R type,1/3bias,V LCD=V DD(Low bias current option)¾1020m A5V¾1940m AV IL1Input Low Voltage for I/O Ports,TMR0,TMR1,INT0and INT1¾¾0¾0.3V DD VV IH1Input High Voltage for I/O Ports,TMR0,TMR1,INT0and INT1¾¾0.7V DD¾V DD V V IL2Input Low Voltage(RES)¾¾0¾0.4V DD V V IH2Input High Voltage(RES)¾¾0.9V DD¾V DD V V LVR Low Voltage Reset Voltage¾¾ 2.7 3.0 3.3V V LVD Low Voltage Detector Voltage¾¾ 3.0 3.3 3.6VI OL1I/O Port Segment Logic OutputSink Current 3VV OL=0.1V DD612¾mA 5V1025¾mAI OH1I/O Port Segment Logic OutputSource Current 3VV OH=0.9V DD-2-4¾mA 5V-5-8¾mARev.1.805July14,2005Symbol ParameterTest ConditionsMin.Typ.Max.Unit V DD ConditionsI OL2LCD Common and SegmentCurrent 3VV OL=0.1V DD210420¾m A 5V350700¾m AI OH2LCD Common and SegmentCurrent 3VV OH=0.9V DD-80-160¾m A 5V-180-360¾m AR PH Pull-high Resistance of I/O Ports and INT0,INT13V¾2060100k W 5V¾103050k WV AD A/D Input Voltage¾¾0¾V DD VE AD A/D Conversion IntegralNonlinearity Error¾¾¾±0.5±1LSBI ADC Additional Power Consumptionif A/D Converter is Used 3V¾¾0.51mA 5V¾ 1.53mANote:²*f S²please refer to clock option of Watchdog TimerA.C.Characteristics Ta=25°CSymbol ParameterTest ConditionsMin.Typ.Max.Unit V DD Conditionsf SYS1System Clock ¾ 2.2V~5.5V400¾4000kHz ¾ 3.3V~5.5V400¾8000kHzf SYS2System Clock(32768Hz Crystal OSC)¾ 2.2V~5.5V¾32768¾Hz f RTCOSC RTC Frequency¾¾¾32768¾Hzf TIMER Timer I/P Frequency(TMR0/TMR1)¾ 2.2V~5.5V0¾4000kHz ¾ 3.3V~5.5V0¾8000kHzt WDTOSC Watchdog Oscillator Period3V¾4590180m s5V¾3265130m st RES External Reset Low Pulse Width¾¾1¾¾m st SST System Start-up Timer Period¾Power-up or wake-up fromHALT¾1024¾t SYS t LVR Low Voltage Width to Reset¾¾1¾¾mst INT Interrupt Pulse Width¾¾1¾¾m st AD A/D Clock Period¾¾1¾¾m st ADC A/D Conversion Time¾¾¾76¾t ADt ADCS A/D Sampling Time¾¾¾32¾t AD Note:t SYS=1/f SYSRev.1.806July14,2005Functional DescriptionExecution FlowThe system clock is derived from either a crystal or an RC oscillator or a32768Hz crystal oscillator.It is inter-nally divided into four non-overlapping clocks.One in-struction cycle consists of four system clock cycles.Instruction fetching and execution are pipelined in such a way that a fetch takes one instruction cycle while de-coding and execution takes the next instruction cycle. The pipelining scheme makes it possible for each in-struction to be effectively executed in a cycle.If an in-struction changes the value of the program counter,two cycles are required to complete the instruction.Program Counter-PCThe program counter(PC)is13bits wide and it controls the sequence in which the instructions stored in the pro-gram ROM are executed.The contents of the PC can specify a maximum of8192addresses.After accessing a program memory word to fetch an in-struction code,the value of the PC is incremented by1. The PC then points to the memory word containing the next instruction code.When executing a jump instruction,conditional skip ex-ecution,loading a PCL register,a subroutine call,an ini-tial reset,an internal interrupt,an external interrupt,or returning from a subroutine,the PC manipulates the program transfer by loading the address corresponding to each instruction.The conditional skip is activated by instructions.Once the condition is met,the next instruction,fetched during the current instruction execution,is discarded and a dummy cycle replaces it to get a proper instruction;oth-erwise proceed to the next instruction.Execution FlowModeProgram Counter*12*11*10*9*8*7*6*5*4*3*2*1*0Initial Reset0000000000000 External Interrupt00000000000100 External Interrupt10000000001000 Timer/Event Counter0Overflow0000000001100 Timer/Event Counter1Overflow0000000010000 Time Base Interrupt0000000010100 RTC Interrupt0000000011000 Skip Program Counter+2Loading PCL*12*11*10*9*8@7@6@5@4@3@2@1@0 Jump,Call Branch#12#11#10#9#8#7#6#5#4#3#2#1#0 Return from Subroutine S12S11S10S9S8S7S6S5S4S3S2S1S0Program CounterNote:*12~*0:Program counter bits S12~S0:Stack register bits#12~#0:Instruction code bits@7~@0:PCL bitsRev.1.807July14,2005The lower byte of the PC(PCL)is a readable and writeable register(06H).Moving data into the PCL per-forms a short jump.The destination is within256loca-tions.When a control transfer takes place,an additional dummy cycle is required.Program Memory-EPROMThe program memory(EPROM)is used to store the pro-gram instructions which are to be executed.It also con-tains data,table,and interrupt entries,and is organized into8192´16bits which are addressed by the program counter and table pointer.Certain locations in the ROM are reserved for special usage:·Location000HLocation000H is reserved for program initialization. After chip reset,the program always begins execution at this location.·Location004HLocation004H is reserved for the external interrupt service program.If the INT0input pin is activated,and the interrupt is enabled,and the stack is not full,the program begins execution at location004H.·Location008HLocation008H is reserved for the external interrupt service program also.If the INT1input pin is activated, and the interrupt is enabled,and the stack is not full, the program begins execution at location008H.·Location00CHLocation00CH is reserved for the Timer/Event Coun-ter0interrupt service program.If a timer interrupt re-sults from a Timer/Event Counter0overflow,and if the interrupt is enabled and the stack is not full,the pro-gram begins execution at location00CH.·Location010HLocation010H is reserved for the Timer/Event Coun-ter1interrupt service program.If a timer interrupt re-sults from a Timer/Event Counter1overflow,and if the interrupt is enabled and the stack is not full,the pro-gram begins execution at location010H.·Location014HLocation014H is reserved for the Time Base interrupt service program.If a Time Base interrupt occurs,and the interrupt is enabled,and the stack is not full,the program begins execution at location014H.·Location018HLocation018H is reserved for the real time clock inter-rupt service program.If a real time clock interrupt oc-curs,and the interrupt is enabled,and the stack is not full,the program begins execution at location018H.·Table locationAny location in the ROM can be used as a look-up ta-ble.The instructions²TABRDC[m]²(the current page, 1page=256words)and²TABRDL[m]²(the last page) transfer the contents of the lower-order byte to the specified data memory,and the contents of the higher-order byte to TBLH(Table Higher-order byte register)(08H).Only the destination of the lower-order byte in the table is well-defined;the other bits of the ta-ble word are all transferred to the lower portion of TBLH.The TBLH is read only,and the table pointer (TBLP)is a read/write register(07H),indicating the ta-ble location.Before accessing the table,the location should be placed in TBLP.All the table related instruc-tions require2cycles to complete the operation. These areas may function as a normal ROM depend-ing upon the user¢s requirements.Program MemoryInstruction(s)Table Location*12*11*10*9*8*7*6*5*4*3*2*1*0TABRDC[m]P12P11P10P9P8@7@6@5@4@3@2@1@0 TABRDL[m]11111@7@6@5@4@3@2@1@0Table LocationNote:*12~*0:Table location bits P12~P8:Current program counter bits @7~@0:Table pointer bitsRev.1.808July14,2005Stack Register-STACKThe stack register is a special part of the memory used to save the contents of the program counter.The stack is organized into16levels and is neither part of the data nor part of the program,and is neither readable nor writeable.Its activated level is indexed by a stack pointer(SP)and is neither readable nor writeable.At the start of a subroutine call or an interrupt acknowledg-ment,the contents of the program counter is pushed onto the stack.At the end of the subroutine or interrupt routine,signaled by a return instruction(RET or RETI), the contents of the program counter is restored to its previous value from the stack.After chip reset,the SP will point to the top of the stack.If the stack is full and a non-masked interrupt takes place,the interrupt request flag is recorded but the ac-knowledgment is still inhibited.Once the SP is decre-mented(by RET or RETI),the interrupt is serviced.This feature prevents stack overflow,allowing the program-mer to use the structure easily.Likewise,if the stack is full,and a²CALL²is subsequently executed,a stack overflow occurs and the first entry is lost(only the most recent sixteen return addresses are stored).Data Memory-RAMThe data memory(RAM)is designed with417´8bits, and is divided into two functional groups,namely;spe-cial function registers33´8bit and general purpose data memory,Bank0:192´8bit and Bank2:192´8bit most of which are readable/writeable,although some are read only.The special function register are overlapped in any banks.Of the two types of functional groups,the special func-tion registers consist of an Indirect addressing register0 (00H),a Memory pointer register0(MP0;01H),an Indi-rect addressing register1(02H),a Memory pointer reg-ister1(MP1;03H),a Bank pointer(BP;04H),an Accumulator(ACC;05H),a Program counter lower-order byte register(PCL;06H),a Table pointer (TBLP;07H),a Table higher-order byte register (TBLH;08H),a Real time clock control register (RTCC;09H),a Status register(STATUS;0AH),an Inter-rupt control register0(INTC0;0BH),a Timer/Event Counter0(TMR0H:0CH;TMR0L:0DH),a Timer/Event Counter0control register(TMR0C;0EH),a Timer/Event Counter1(TMR1H:0FH;TMR1L:10H),a Timer/Event Counter1control register(TMR1C;11H),Interrupt con-trol register1(INTC1;1EH),PWM data register(PWM0;1AH,PWM1;1BH,PWM2;1CH,PWM3;1DH), the A/D result lower-order byte register(ADRL;24H),the A/D result higher-order byte register(ADRH;25H),the A/D control register(ADCR;26H),the A/D clock setting register(ACSR;27H),I/O registers(PA;12H,PB;14H, PD;18H)and I/O control registers(PAC;13H,PBC;15H, PDC;19H).The remaining space before the40H is re-served for future expanded usage and reading these lo-cations will get²00H².The space before40H is overlapping in each bank.The general purpose data memory,addressed from40H to FFH(Bank0;BP=0or Bank2;BP=2),is used for data and control information under instruction commands.All of the data memory ar-eas can handle arithmetic,logic,increment,decrement and rotate operations directly.Except for some dedi-cated bits,each bit in the data memory can be set andRAM MappingRev.1.809July14,2005reset by²SET[m].i²and²CLR[m].i².They are also indi-rectly accessible through memory pointer registers (MP0;01H/MP1;03H).The space before40H is overlap-ping in each bank.After first setting up BP to the value of²01H²or²02H²to access either bank1or bank2respectively,these banks must then be accessed indirectly using the Memory Pointer MP1.With BP set to a value of either²01H²or ²02H²,using MP1to indirectly read or write to the data memory areas with addresses from40H~FFH will result in operations to either bank1or bank2.Directly ad-dressing the Data Memory will always result in Bank0 being accessed irrespective of the value of BP.Indirect Addressing RegisterLocation00H and02H are indirect addressing registers that are not physically implemented.Any read/write op-eration of[00H]and[02H]accesses the RAM pointed to by MP0(01H)and MP1(03H)respectively.Reading lo-cation00H or02H indirectly returns the result00H. While,writing it indirectly leads to no operation.The function of data movement between two indirect ad-dressing registers is not supported.The memory pointer registers,MP0and MP1,are both8-bit registers used to access the RAM by combining corresponding indirect addressing registers.MP0can only be applied to data memory,while MP1can be applied to data memory and LCD display memory.Accumulator-ACCThe accumulator(ACC)is related to the ALU opera-tions.It is also mapped to location05H of the RAM and is capable of operating with immediate data.The data movement between two data memory locations must pass through the ACC.Arithmetic and Logic Unit-ALUThis circuit performs8-bit arithmetic and logic opera-tions and provides the following functions:·Arithmetic operations(ADD,ADC,SUB,SBC,DAA)·Logic operations(AND,OR,XOR,CPL)·Rotation(RL,RR,RLC,RRC)·Increment and Decrement(INC,DEC)·Branch decision(SZ,SNZ,SIZ,SDZ etc.)The ALU not only saves the results of a data operation but also changes the status register.Status Register-STATUSThe status register(0AH)is8bits wide and contains,a carry flag(C),an auxiliary carry flag(AC),a zero flag(Z), an overflow flag(OV),a power down flag(PDF),and a watchdog time-out flag(TO).It also records the status information and controls the operation sequence.Except for the TO and PDF flags,bits in the status reg-ister can be altered by instructions similar to other reg-isters.Data written into the status register does not alter the TO or PDF flags.Operations related to the status register,however,may yield different results from those intended.The TO and PDF flags can only be changed by a Watchdog Timer overflow,chip power-up,or clear-ing the Watchdog Timer and executing the²HALT²in-struction.The Z,OV,AC,and C flags reflect the status of the latest operations.On entering the interrupt sequence or executing the subroutine call,the status register will not be automati-cally pushed onto the stack.If the contents of the status is important,and if the subroutine is likely to corrupt the status register,the programmer should take precautions and save it properly.Bit bel Function0C C is set if an operation results in a carry during an addition operation or if a borrow does not take place during a subtraction operation;otherwise C is cleared.C is also affected by a ro-tate through carry instruction.1AC AC is set if an operation results in a carry out of the low nibbles in addition or no borrow from the high nibble into the low nibble in subtraction;otherwise AC is cleared.2Z Z is set if the result of an arithmetic or logic operation is zero;otherwise Z is cleared.3OV OV is set if an operation results in a carry into the highest-order bit but not a carry out of the highest-order bit,or vice versa;otherwise OV is cleared.4PDF PDF is cleared by either a system power-up or executing the²CLR WDT²instruction.PDF is set by executing the²HALT²instruction.5TO TO is cleared by a system power-up or executing the²CLR WDT²or²HALT²instruction.TO is set by a WDT time-out.6,7¾Unused bit,read as²0²Status(0AH)RegisterRev.1.8010July14,2005InterruptsThe device provides two external interrupts,two internal timer/event counter interrupts,an internal time base in-terrupt,and an internal real time clock interrupt.The in-terrupt control register0(INTC0;0BH)and interrupt control register1(INTC1;1EH)both contain the interrupt control bits that are used to set the enable/disable status and interrupt request flags.Once an interrupt subroutine is serviced,other inter-rupts are all blocked(by clearing the EMI bit).This scheme may prevent any further interrupt nesting.Other interrupt requests may take place during this interval, but only the interrupt request flag will be recorded.If a certain interrupt requires servicing within the service routine,the EMI bit and the corresponding bit of the INTC0or of INTC1may be set in order to allow interrupt nesting.Once the stack is full,the interrupt request will not be acknowledged,even if the related interrupt is en-abled,until the SP is decremented.If immediate service is desired,the stack should be prevented from becom-ing full.All these interrupts can support a wake-up function.As an interrupt is serviced,a control transfer occurs by pushing the contents of the program counter onto the stack followed by a branch to a subroutine at the speci-fied location in the ROM.Only the contents of the pro-gram counter is pushed onto the stack.If the contents of the register or of the status register(STATUS)is altered by the interrupt service program which corrupts the de-sired control sequence,the contents should be saved in advance.External interrupts are triggered by a an edge transition of INT0or INT1(ROM code option:high to low,low to high,low to high or high to low),and the related interrupt request flag(EIF0;bit4of INTC0,EIF1;bit5of INTC0) is set as well.After the interrupt is enabled,the stack is not full,and the external interrupt is active,a subroutine call to location04H or08H occurs.The interrupt request flag(EIF0or EIF1)and EMI bits are all cleared to disable other maskable interrupts.The internal Timer/Event Counter0interrupt is initial-ized by setting the Timer/Event Counter0interrupt re-quest flag(T0F;bit6of INTC0),which is normally caused by a timer overflow.After the interrupt is en-abled,and the stack is not full,and the T0F bit is set,a subroutine call to location0CH occurs.The related inter-rupt request flag(T0F)is reset,and the EMI bit is cleared to disable other maskable interrupts. Timer/Event Counter1is operated in the same manner but its related interrupt request flag is T1F(bit4of INTC1)and its subroutine call location is10H.The time base interrupt is initialized by setting the time base interrupt request flag(TBF;bit5of INTC1),that is caused by a regular time base signal.After the interrupt is enabled,and the stack is not full,and the TBF bit is set,a subroutine call to location14H occurs.The related interrupt request flag(TBF)is reset and the EMI bit is cleared to disable further maskable interrupts.Bit bel Function 0EMI Control the master(global)interrupt(1=enabled;0=disabled)1EEI0Control the external interrupt0(1=enabled;0=disabled)2EEI1Control the external interrupt1(1=enabled;0=disabled)3ET0I Control the Timer/Event Counter0interrupt(1=enabled;0=disabled) 4EIF0External interrupt0request flag(1=active;0=inactive)5EIF1External interrupt1request flag(1=active;0=inactive)6T0F Internal Timer/Event Counter0request flag(1=active;0=inactive)7¾For test mode used only.Must be written as²0²;otherwise may result in unpredictable operation.INTC0(0BH)RegisterBit bel Function0ET1I Control the Timer/Event Counter1interrupt(1=enabled;0=disabled)1ETBI Control the time base interrupt(1=enabled;0:disabled)2ERTI Control the real time clock interrupt(1=enabled;0:disabled)3,7¾Unused bit,read as²0²4T1F Internal Timer/Event Counter1request flag(1=active;0=inactive)5TBF Time base request flag(1=active;0=inactive)6RTF Real time clock request flag(1=active;0=inactive)INTC1(1EH)RegisterRev.1.8011July14,2005The real time clock interrupt is initialized by setting the real time clock interrupt request flag(RTF;bit6of INTC1),that is caused by a regular real time clock sig-nal.After the interrupt is enabled,and the stack is not full,and the RTF bit is set,a subroutine call to location 18H occurs.The related interrupt request flag(RTF)is reset and the EMI bit is cleared to disable further maskable interrupts.During the execution of an interrupt subroutine,other maskable interrupt acknowledgments are all held until the²RETI²instruction is executed or the EMI bit and the related interrupt control bit are set both to1(if the stack is not full).To return from the interrupt subroutine,²RET²or²RETI²may be invoked.RETI sets the EMI bit and en-ables an interrupt service,but RET does not.Interrupts occurring in the interval between the rising edges of two consecutive T2pulses are serviced on the latter of the two T2pulses if the corresponding interrupts are enabled.In the case of simultaneous requests,the priorities in the following table apply.These can be masked by resetting the EMI bit.Interrupt Source Priority Vector External interrupt0104H External interrupt1208H Timer/Event Counter0overflow30CH Timer/Event Counter1overflow410H Time base interrupt514H Real time clock interrupt618HThe Timer/Event Counter0interrupt request flag(T0F), external interrupt1request flag(EIF1),external inter-rupt0request flag(EIF0),enable Timer/Event Counter 0interrupt bit(ET0I),enable external interrupt1bit (EEI1),enable external interrupt0bit(EEI0),and en-able master interrupt bit(EMI)make up of the Interrupt Control register0(INTC0)which is located at0BH in the RAM.The real time clock interrupt request flag(RTF), time base interrupt request flag(TBF),Timer/Event Counter1interrupt request flag(T1F),enable real time clock interrupt bit(ERTI),and enable time base interrupt bit(ETBI),enable Timer/Event Counter1interrupt bit (ET1I)on the other hand,constitute the Interrupt Control register1(INTC1)which is located at1EH in the RAM. EMI,EEI0,EEI1,ET0I,ET1I,ETBI,and ERTI are all used to control the enable/disable status of interrupts. These bits prevent the requested interrupt from being serviced.Once the interrupt request flags(RTF,TBF,T0F, T1F,EIF1,EIF0)are all set,they remain in the INTC1or INTC0respectively until the interrupts are serviced or cleared by a software instruction.It is recommended that a program should not use the ²CALL subroutine²within the interrupt subroutine.It¢s be-cause interrupts often occur in an unpredictable manner or require to be serviced immediately in some applica-tions.During that period,if only one stack is left,and en-abling the interrupt is not well controlled,operation of the ²call²in the interrupt subroutine may damage the origi-nal control sequence.Oscillator ConfigurationThe device provides three oscillator circuits for system clocks,i.e.,RC oscillator,crystal oscillator and32768Hz crystal oscillator,determined by options.No matter what type of oscillator is selected,the signal is used for the system clock.The HALT mode stops the system oscilla-tor(RC and crystal oscillator only)and ignores external signal in order to conserve power.The32768Hz crystal oscillator still runs at HALT mode.If the32768Hz crystal oscillator is selected as the system oscillator,the system oscillator is not stopped;but the instruction execution is stopped.Since the32768Hz oscillator is also designed for timing purposes,the internal timing(RTC,time base, WDT)operation still runs even if the system enters the HALT mode.Of the three oscillators,if the RC oscillator is used,an external resistor between OSC1and VSS is required, and the range of the resistance should be from30k W to 750k W.The system clock,divided by4,is available on OSC2with pull-high resistor,which can be used to syn-chronize external logic.The RC oscillator provides the most cost effective solution.However,the frequency of the oscillation may vary with VDD,temperature,and the chip itself due to process variations.It is therefore,not suitable for timing sensitive operations where accurate oscillator frequency is desired.System OscillatorNote:32768Hz crystal enable condition:For WDT clock source or for system clock source.The external resistor and capacitor components connected to the32768Hz crystal are not necessary to pro-vide oscillation.For applications where precise RTC frequencies are essential,these components may be re-quired to provide frequency compensation due to different crystal manufacturing tolerances.Rev.1.8012July14,2005。
HT46R47,HT46R22, HT46R23,HT46R24 A D 型单片机 说明书
![HT46R47,HT46R22, HT46R23,HT46R24 A D 型单片机 说明书](https://img.taocdn.com/s3/m/2d4c5b8602d276a200292e83.png)
二○○五年三月
Copyright 2005 by HOLTEK SEMICONDUCTOR INC.
本使用手册版权为盛群半导体股份有限公司所有,非经盛群半导体股份有限公司书面授权同意,不得通过任 何形式复制、储存或机概论 .................................................................. 1
第一章 硬件结构 ........................................................................................ 3 简介..............................................................................................................3 特性..............................................................................................................4 技术特性 ..............................................................................................4 内核特性 ..............................................................................................4 周边特性 ..............................................................................................5 选择表..........................................................................................................5 系统框线图..................................................................................................6 引脚分配......................................................................................................7 引脚说明......................................................................................................8 极限参数....................................................................................................12 直流电气特性............................................................................................13 交流电气特性............................................................................................14 系统结构....................................................................................................15 时序和流水线结构(Pipelining) .........................................................15 程序计数器 ........................................................................................17 堆栈 ....................................................................................................19 算术及逻辑单元 – ALU ...................................................................20 程序存储器................................................................................................21 结构 ....................................................................................................21 特殊向量 ............................................................................................22 查表 ....................................................................................................23 查表程序范例 ....................................................................................23 数据存储器................................................................................................25 结构 ....................................................................................................25 通用数据存储器 ................................................................................26 专用数据存储器 ................................................................................27
合泰单片机编写遥控器程序PPT课件
![合泰单片机编写遥控器程序PPT课件](https://img.taocdn.com/s3/m/a8b82e0b770bf78a64295489.png)
附图一 试验板电路 图
第15页/共17页
Q&A
第16页/共17页
感谢您的观看!
第17页/共17页
1111111100000000
ADDRH= FFH ADDRL= 00H
第6页/共17页
❖ 红外线遥控接收
4)HT6221的按键码 如表8
表8 HT6221按键编码
第7页/共17页
❖ 红外线遥控接收
HT6221的发码格式,如图39
图39
第8页/共17页
特别说明: 红外信号经 过三极管反 相,因此接收 到的波形和 发射波形相 反
❖ 红外线遥控接收
4) 每次正确的按键接收,蜂鸣器响一声提示。蜂鸣 器有两种办法实现,一种是I/O直接驱动,用子程序 来驱动。另一种是用芯片本身的功能BZ,用定时器 的溢出做蜂鸣器时钟源。 特别注意二者的Configuration Option 选项不同。
第3页/共17页
❖ 红外线遥控接收
1. HT6221应用的简单说明 1)HT6221的标准应用电路,如图36
VDD RES PC5 PC4
19 18 17 16
3 15
PC2
HT48R50A-1/HT4 8C50-1-A
VCC
C1 47p
Y1 4M
C2 47p VCC R9 10k C3 104
C6 104
图35
第1页/共17页
❖ 红外线遥控接收
2)红外线编码发射芯片采用HT6221
3)功能:遥控器上8个按键,对应8个LED指示灯。初 始LED全灭。
WDT : Disable
LVR : Disable
CLR WDT : One clear instruction
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
注:这里只强调额定功率,超过极限参数所规定的范围将对芯片造成损害,无法预期芯片在上述标示范围外的工作状态,而 且若长期在标示范围外的条件下工作,可能影响芯片的可靠性。 Rev. 2.20 4 2014-06-06
HT46R65/HT46C65 直流电气特性
符号 VDD IDD1 IDD2 IDD3 ISTB1 ISTB2 参数 工作电压 工作电流 (晶体振荡、RC 振荡) 工作电流 (晶体振荡,RC 振荡) 工作电流 (fSYS=32768Hz) 静态电流 (*fS=T1) 静态电流 (*fS=RTC 振荡) 静态电流 (*fS=WDT 振荡) VDD — — 3V 5V 5V 3V 5V 3V 5V 3V 5V 3V 5V 3V 5V 3V 5V 3V 5V 3V 5V — 测试条件 条件 fSYS=4MHz fSYS=8MHz 无负载,ADC 关闭 fSYS=4MHz 无负载,ADC 关闭 fSYS=8MHz 无负载,ADC 关闭 无负载,系统 HALT, HALT 时 LCD 关闭 无负载,系统 HALT, HALT 时 LCD 打开, 电容型偏压 无负载,系统 HALT, HALT 时 LCD 打开, 电容型偏压 无负载,系统 HALT, HALT 时 LCD 打开, 电阻型偏压,1/2bias, VLCD=VDD (选择低电流偏压) 无负载,系统 HALT, HALT 时 LCD 打开, 电阻型偏压,1/3bias, VLCD=VDD (选择低电流偏压) 无负载,系统 HALT, HALT 时 LCD 打开, 电阻型偏压,1/2bias, VLCD=VDD (选择低电流偏压) 无负载,系统 HALT, HALT 时 LCD 打开, 电阻型偏压,1/3bias, VLCD=VDD (选择低电流偏压) — 最小 2.2 3.3 — — — — — — — — — — — — — — — — — — — 0 典型 — — 1 3 4 0.3 0.6 — — 2.5 10 2 6 17 34 13 28 14 26 10 19 —
概述
HT46R65/HT46C65 是 8 位高性能精简指令集单片机, 专门为需要 A/D 转换和 LCD 显示的产品而设计。 掩膜版本 HT46C65 与 OTP 版本 HT46R65 引脚和功能完全相同。 低功耗、I/O 使用灵活、计数器、振荡类型选择、多通道 A/D 转换、脉冲测量功能、暂停和唤醒功能, 以及 LCD 显示功能,使这款单片机可以广泛应用于需要 A/D 转换和 LCD 显示的产品中,例如电子测量仪 器、环境监控、手持式测量工具、马达控制等工业和家庭系统中。
注:有关“fS”的具体说明请参阅 WDT 的时钟选择。
交流电气特性
符号 fSYS1 fSYS2 fRTCOSC fTIMER tWDTOSC tRES tSST tLVR tINT tAD tADC tADCS 参数 系统时钟 系统时钟 (32768Hz 晶体振荡) RTC 频率 定时器输入频率 (TMR0/TMR1) 看门狗振荡器周期 外部复位低电平脉宽 系统启动延迟时间 低压复位宽度 中断脉冲宽度 A/D 时钟周期 A/D 转换时间 A/D 采样时间 VDD — — — — — — 3V 5V — — — — — — — 2.2V~5.5V 3.3V~5.5V — — — 上电或从 HALT 状态唤醒 — — — — — 测试条件 条件 2.2V~5.5V 3.3V~5.5V 2.2V~5.5V — 最小 400 400 — — 0 0 45 32 1 — 1 1 1 — — 典型 — — 32768 32768 — — 90 65 — 1024 — — — 76 32
HT46R65/HT46C65 A/D+LCD 型八位单片机
特性
•
• • • • • • • • • •
工作电压: fSYS=4MHz:2.2V~5.5V fSYS=8MHz:3.3V~5.5V 24 个双向输入/输出口 2 个外部中断输入 2 个 16 位定时/计数器,具有 PFD(可编程分频 器)功能 41×3 或 40×4 段的 LCD 驱动(SEG0~SEG23 可 由掩膜选项设置为逻辑输出) 8K×16 程序存储器 384×8 数据存储器 具有 PFD 功能,可用于发声 一个实时时钟(RTC) 一个 8 位的实时时钟预分频器 看门狗定时器
System Clock OSC2 (RC only) PC PC PC+1 PC+2 T1 T2 T3 T4 T1 T2 T3 T4 T1 T2 T3 T4
Fetch INST (PC) Execute INST (PC-1)
Fetch INST (PC+1) Execute INST (PC)
静态电流 (*fS=RTC 振荡)
ISTB5
静态电流 (*fS=RTC 振荡)
IST流 (*fS=WDT 振荡) 输入/输出口、TMR0、 TMR1 、 INT 0 、 INT 1 的低电平输入电压 输入/输出口、TMR0、 TMR1 、 INT 0 、 INT 1 的低电平输入电压 低电平输入电压( RES ) 高电平输入电压( RES ) 低电压复位 低电压检测
• • • • • • • • • • • • •
蜂鸣器输出 内置晶体、RC 和 32768Hz 晶体振荡电路 HALT 和唤醒功能可降低功耗 16 层硬件堆栈 8 通道 10 位解析度的 A/D 转换器 4 通道 8 位 PWM 输出,与 4 个输入/输出口共 用引脚 位操作指令 查表指令,表格内容字长 16 位 系统频率为 8MHz 时,指令周期为 0.5μs 63 条指令 指令执行时间为 1 或 2 个指令周期 低电压复位/检测功能 64/100-pin LQFP 封装
VIL1
VIH1 VIL2 VIH2 VLVR VLVD
Rev. 2.20
— — — — —
5
— — — — —
0.7VDD 0 0.9 VDD 2.7 3.0
— — — 3.0 3.3
VDD 0.4 VDD VDD 3.3 3.6
V V V V V
2014-06-06
HT46R65/HT46C65
Ta=25℃
最大 5.5 5.5 2 5 8 0.6 1 1 2 5 20 5 10 30 60 25 50 25 50 20 40 0.3 VDD 单位 V V mA mA mA mA mA μA μA μA μA μA μA μA μA μA μA μA μA μA μA V
ISTB3
ISTB4
输入/输出
输入/输出
上拉电阻
输入/输出
上拉电阻 PWM
输入/输出 — 输入 输入 输入 输出 输出
上拉电阻
— — — — 1/3 或 1/4 Duty 逻辑输出
OSC1 OSC2
输入 输出
晶体或 RC
OSC3 OSC4 VDD
RES
输入 输出 — 输入
RTC 或系统时钟 — —
极限参数
电源供应电压………….VSS-0.3V~VSS+6.0V 端口输入电压………….VSS-0.3V~VDD+0.3V 储存温度………….-50℃~125℃ 工作温度………..….-40℃~85℃
IOL1 IOH1 IOL2 IOH2 RPH VAD EAD IADC 输入 / 输出口逻辑输出 灌电流 输入 / 输出口逻辑输出 源电流 LCD Com 和 Segment 电流 LCD Com 和 Segment 电流 输入 /输出口、 INT0 和 INT1 上拉电阻 A/D 输入电压 A/D 转换误差 A/D 转换电路打开时增 加的系统功耗 3V 5V 3V 5V 3V 5V 3V 5V 3V 5V — — 3V 5V VOL=0.1VDD VOH=0.9VDD VOL=0.1VDD VOH=0.9VDD — — — — — 6 10 -2 -5 210 350 -80 -180 20 10 0 — — — 12 25 -4 -8 420 700 -160 -360 60 30 — ±0.5 0.5 1.5 — — — — — — — — 100 50 VDD ±1 1 3 mA mA mA mA µA µA µA µA kΩ kΩ V LSB mA mA
指令执行时序 单片机的系统时钟由晶体振荡器或 RC 振荡器和 32768Hz 的晶体振荡器产生。该时钟在芯片内部被分 成四个互不重叠的时钟周期。一个指令周期包括四个系统时钟周期。 指令的读取和执行是以流水线方式进行的, 这种方式在一个指令周期进行读取指令操作,而在下一个 指令周期进行解码与执行该指令。因此,流水线方式使多数指令能在一个周期内执行完成。但如果渉及到 的指令要改变程序计数器的值,就需要花两个指令周期来完成这一条指令。
Ta=25℃
最大 4000 8000 — — 4000 8000 180 130 — — — — — — — kHz μs μs *tSYS ms μs μs tAD tAD 单位 kHz Hz
注:*tSYS =1/fSYS
Rev. 2.20
6
2014-06-06
HT46R65/HT46C65
系统功能说明
Rev. 2.20
1
2014-06-06
HT46R65/HT46C65
方框图
Rev. 2.20
2
2014-06-06
HT46R65/HT46C65
引脚图
Rev. 2.20
3
2014-06-06
HT46R65/HT46C65 引脚说明
引脚名称 PA0/BZ PA1/ BZ PA2 PA3/PFD PA4~PA7 PB0/AN0 PB1/AN1 PB2/AN2 PB3/AN3 PB4/AN4 PB5/AN5 PB6/AN6 PB7/AN7 PD0/PWM0 PD1/PWM1 PD2/PWM2 PD3/PWM3 PD4/ INT0 PD5/ INT1 PD6/TMR0 PD7TMR1 VSS VLCD VMAX V1,V2,C1,C2 COM0~COM2 COM3 / SEG40 SEG0~SEG39 输入/输出 掩膜选项 唤醒功能 上拉电阻 蜂鸣器 PFD 说明 8 位双向输入/输出口。每一位可由掩膜选项设置 为唤醒输入。可由软件设置为 CMOS 输出、带或 不带上拉电阻(由上拉电阻选项决定: 位选择)的斯 密特触发输入。BZ、BZ 和 PFD 分别与 PA0、PA1 和 PA3 共用引脚。 8 位双向输入/输出口。可由软件设置为 CMOS 输 出、带或不带上拉电阻(由上拉电阻选项决定:位 选择)的斯密特触发输入、或 A/D 输入。 一旦 PB 口做为 A/D 输入(由软件设置), 则其输入 /输出功能和上拉电阻会自动失效。 4 位双向输入/输出口。可由软件设置为 CMOS 输 出、带或不带上拉电阻(由上拉电阻选项决定:位 选择 ) 的斯密特触发输入。PWM0/PWM1/PWM2/ PWM3 输出与 PD0/PD1/PD2/PD3 共用引脚 ( 由 PWM 选项决定)。 4 位双向输入/输出口。可由软件设置为 CMOS 输 出、带或不带上拉电阻(由上拉电阻选项决定:位 选 择 ) 的 斯 密 特 触 发 输 入。 INT0 / INT1 /TMR0/ TMR1 与 PD4/PD5/PD6/PD7 共用引脚。 负电源,接地。 LCD 电源。 IC 最高电压,接至 VDD、VLCD 或 V1。 电压泵。 SEG40 可由掩膜选项设置为 LCD 显示的 Segment 或 Common 输出端。COM0~COM2 是 LCD 驱动 的 Common 输出。 LCD 驱动的 Segment 输出。SEG0~SEG23 可掩 膜选择为逻辑输出口。 OSC1、OSC2 连接 RC 或晶体(由掩膜选项确定) 以产生内部系统时钟。在 RC 振荡方式下,OSC2 是系统时钟四分频的输出口。系统时钟也可以选 择为 RTC 振荡;如果选择 RTC 振荡作为系统时 钟,则这两个引脚可以空接。 实时时钟振荡器。OSC3、OSC4 连接 32768Hz 的 晶体振荡器,用于提供定时或系统时钟(由掩膜选 项确定)。没有内建电容。 正电源。 斯密特触发复位输入。