📄 stc15.h
字号:
/*------------------------------------------------*/
/* --- 宏晶科技 STCMCU ---------------------------*/
/* --- Mobile: (86)13922805190 -------------------*/
/* --- Fax: 86-755-82944243 ----------------------*/
/* --- Tel: 86-755-82948412 ----------------------*/
/* --- Web: www.STCMCU.com -----------------------*/
/* 适用于: STC15Fxx STC15Lxx ---------------*/
/* ------- STC15FxxE STC15LxxE ---------------*/
/* ------- STC15FxxXE STC15LxxXE ---------------*/
/* ------- STC15FxxCPP STC15LxxCPP ---------------*/
/* ------- STC15FxxAD STC15LxxAD ---------------*/
/* ------- IAP15FxxAD IAP15LxxAD ---------------*/
/*------------------------------------------------*/
#ifndef __STC15_H__
#define __STC15_H__
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sfr PSW = 0xd0; //程序状态字 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 CY AC F0 RS1 RS0 OV F1 P
//初始值=0000,0000 0 0 0 0 0 0 0 0
sbit CY = PSW^7; //进位标志
sbit AC = PSW^6; //辅助进位标志
sbit F0 = PSW^5; //用户标志
sbit RS1 = PSW^4; //寄存器组选择位1
sbit RS0 = PSW^3; //寄存器组选择位0
sbit OV = PSW^2; //溢出标志
sbit P = PSW^0; //ACC的偶校验位
/////////////////////////////////
sfr ACC = 0xe0; //累加器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//初始值=0000,0000 0 0 0 0 0 0 0 0
sbit ACC7 = ACC^7; //累加器第7位
sbit ACC6 = ACC^6; //累加器第6位
sbit ACC5 = ACC^5; //累加器第5位
sbit ACC4 = ACC^4; //累加器第4位
sbit ACC3 = ACC^3; //累加器第3位
sbit ACC2 = ACC^2; //累加器第2位
sbit ACC1 = ACC^1; //累加器第1位
sbit ACC0 = ACC^0; //累加器第0位
/////////////////////////////////
sfr B = 0xf0; //B寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//初始值=0000,0000 0 0 0 0 0 0 0 0
/////////////////////////////////
sfr SP = 0x81; //堆栈指针 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//初始值=0000,0111 0 0 0 0 0 1 1 1
/////////////////////////////////
sfr DPL = 0x82; //数据指针低字节 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//初始值=0000,0000 0 0 0 0 0 0 0 0
/////////////////////////////////
sfr DPH = 0x83; //数据指针高字节 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//初始值=0000,0000 0 0 0 0 0 0 0 0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sfr PCON = 0x87; //电源控制寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 SMOD SMOD0 LVDF POF GF1 GF0 PD IDL
//初始值=0011,0000 0 0 1 1 0 0 0 0
#define SMOD 0x80 //串口波特率倍速位,置1可使波特率快1倍
#define SMOD0 0x40 //FE/SM0选择位,0:SCON.7为SM0 1:SCON.7为FE
#define LVDF 0x20 //低压检测中断请求位,由硬件置1,需由软件清0
#define POF 0x10 //上电复位标志位,上电时由硬件置1,需由软件清0
#define GF1 0x08 //通用标志位1
#define GF0 0x04 //通用标志位0
#define PD 0x02 //掉电控制位,写1可以使MCU进入PowerDown模式
#define IDL 0x01 //空闲控制位,写1可以使MCU进入Idle模式
/////////////////////////////////
sfr WAKE_CLKO = 0x8f; //掉电唤醒/时钟输出控制 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 - RXDPINIE T1PINIE T0PINIE - BRTCLKO T1VLKO T0CLKO
//初始值=x000,x000 x 0 0 0 x 0 0 0
#define RXD_PIN_IE 0x40 //允许RXD(P3.0)下降沿置位RI中断时唤醒掉电MCU(必须打开相应中断)
#define T1_PIN_IE 0x20 //允许T1(P3.5)下降沿置位T1中断时唤醒掉电MCU(必须打开相应中断)
#define T0_PIN_IE 0x10 //允许T0(P3.4)下降沿置位T0中断时唤醒掉电MCU(必须打开相应中断)
#define BRTCLKOEN 0x04 //打开P1.0脚的BRT时钟溢出脉冲,输出的时钟频率为1/2倍的BRT溢出率
#define T1CLKOEN 0x02 //打开P3.5脚的定时器1时钟溢出脉冲,输出的时钟频率为1/2倍的T1溢出率
#define T0CLKOEN 0x01 //打开P3.4脚的定时器0时钟溢出脉冲,输出的时钟频率为1/2倍的T0溢出率
/////////////////////////////////
sfr CLK_DIV = 0x97; //时钟分频寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 - - - - - CLKS2 CLKS1 CLKS0
//初始值=xxxx,x000 x x x x x 0 0 0
#define FOSCD1 0x00 //系统时钟为Fosc
#define FOSCD2 0x01 //系统时钟为Fosc/2
#define FOSCD4 0x02 //系统时钟为Fosc/4
#define FOSCD8 0x03 //系统时钟为Fosc/8
#define FOSCD16 0x04 //系统时钟为Fosc/16
#define FOSCD32 0x05 //系统时钟为Fosc/32
#define FOSCD64 0x06 //系统时钟为Fosc/64
#define FOSCD128 0x07 //系统时钟为Fosc/128
/////////////////////////////////
sfr BUS_SPEED = 0xa1; //数据总线速度控制器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 - - ALES1 ALES0 - RWS2 RWS1 RWS0
//初始值=xx10,x011 x x 1 0 x 0 1 1
#define ALES1 0x20 //P0地址建立时间和保持时间到ALE信号的下降沿的时钟数
#define ALES0 0x10 //ALES1/ALES0=0/0:1个时钟 0/1:2个时钟 1/0:3个时钟 1/1:4个时钟
#define RWS2 0x04 //MOVX指令的时钟数
#define RWS1 0x02 //RWS2/RWS1/RWS0=000:1个时钟 001:2个时钟 010:3个时钟 011:4个时钟
#define RWS0 0x01 // 100:5个时钟 101:6个时钟 110:7个时钟 111:8个时钟
/////////////////////////////////
sfr WKTCL = 0xaa; //掉电唤醒定时器低字节 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 B7 B6 B5 B4 B3 B2 B1 B0
//初始值=0000,0000 0 0 0 0 0 0 0 0
/////////////////////////////////
sfr WKTCH = 0xab; //掉电唤醒定时器高字节 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 WKTEN - - - B11 B10 B9 B8
//初始值=0xxx,0000 0 x x x 0 0 0 0
#define WKTEN 0x80 //掉电唤醒定时器使能位,置1时,当CPU进入掉电模式后开始计时,计时单周期约为560us,最大可计4095次(大约2.3s)
/////////////////////////////////
sfr WDT_CONTR = 0xc1; //看门狗定时器控制器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 WDT_FLAG - EN_WDT CLR_WDT IDL_WDT PS2 PS1 PS0
//初始值=0x00,0000 0 x 0 0 0 0 0 0
#define WDT_FLAG 0x80 //看门狗复位标志,当看门狗溢出产生复位后,硬件自动置1,需要由软件清0
#define EN_WDT 0x20 //软件使能看门狗,打开后不能用软件的方式关闭
#define CLR_WDT 0x10 //清看门狗定时器
#define IDLE_WDT 0x08 //IDLE模式下,看门狗定时器是否继续计时
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sfr AUXR = 0x8e; //辅助寄存器 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 T0x12 T1x12 UM0x6 BRTR - BRTx12 EXTRAM S1BRS
//初始值=0000,x000 0 0 0 0 x 0 0 0
#define T0x12 0x80 //定时器0时钟控制,0:Fosc/12(传统的12分频) 1:Fosc/1(1T模式,不分频,即12倍于传统速度)
#define T1x12 0x40 //定时器1时钟控制,0:Fosc/12(传统的12分频) 1:Fosc/1(1T模式,不分频,即12倍于传统速度)
#define UR0x6 0x20 //串口模式0的时钟控制,0:Fosc/12(传统的12分频) 1:Fosc/2(2分频,,即6倍于传统速度)
#define BRTR 0x10 //独立波特率发生器启动控制位,1:启动独立波特率发生器 0:停止独立波特率发生器
#define BRTx12 0x04 //独立波特率发生器时钟控制,0:Fosc/12(传统的12分频) 1:Fosc/1(1T模式,不分频,即12倍于传统速度)
#define EXTRAM 0x02 //内部扩展RAM禁能位,0:内部扩展RAM有效 1:禁用内部扩展RAM
#define S1BRS 0x01 //串口1的波特率发生器选择位,0:定时器1 1:独立波特率发生器(注意串口2只能够使用独立波特率发生器)
/////////////////////////////////
sfr AUXR1 = 0xa2; //辅助寄存器1 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 UART_P1 PCA_P4 - - GF2 - - DPS
//初始值=01xx,0xx0 0 1 x x 0 x x 0
#define UAER_P1 0x80 //将串口映射到P1口,0:RXD(P3.0)TXD(P3.1) 1:RXD2(P1.6)TXD2(P1.7)
#define PCA_P4 0x40 //将PCA口映射到P4口,0:ECI(P1.2)CEX0(P1.3)CEX1(P1.4) 1:ECI(P4.1)CEX0(P4.2)CEX1(P4.3)
#define GF2 0x08 //通用标志位2
#define DPS 0x01 //DPTR0/DPTR1选择位,0:DPTR0 1:DPTR1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sfr P0 = 0x80; //I/O端口0 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0
//初始值=1111,1111 1 1 1 1 1 1 1 1
sbit P07 = P0^7; //I/O口P0.7
sbit P06 = P0^6; //I/O口P0.6
sbit P05 = P0^5; //I/O口P0.5
sbit P04 = P0^4; //I/O口P0.4
sbit P03 = P0^3; //I/O口P0.3
sbit P02 = P0^2; //I/O口P0.2
sbit P01 = P0^1; //I/O口P0.1
sbit P00 = P0^0; //I/O口P0.0
/////////////////////////////////
sfr P1 = 0x90; //I/O端口0 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0
//初始值=1111,1111 1 1 1 1 1 1 1 1
sbit P17 = P1^7; //I/O口P1.7
sbit P16 = P1^6; //I/O口P1.6
sbit P15 = P1^5; //I/O口P1.5
sbit P14 = P1^4; //I/O口P1.4
sbit P13 = P1^3; //I/O口P1.3
sbit P12 = P1^2; //I/O口P1.2
sbit P11 = P1^1; //I/O口P1.1
sbit P10 = P1^0; //I/O口P1.0
sbit ADCIN7 = P1^7; //ADC通道7的模拟信号输入脚
sbit ADCIN6 = P1^6; //ADC通道6的模拟信号输入脚
sbit ADCIN5 = P1^5; //ADC通道5的模拟信号输入脚
sbit ADCIN4 = P1^4; //ADC通道4的模拟信号输入脚
sbit ADCIN3 = P1^3; //ADC通道3的模拟信号输入脚
sbit ADCIN2 = P1^2; //ADC通道2的模拟信号输入脚
sbit ADCIN1 = P1^1; //ADC通道1的模拟信号输入脚
sbit ADCIN0 = P1^0; //ADC通道0的模拟信号输入脚
sbit CEX1 = P1^4; //比较/捕获/PWM1外部引脚
sbit CEX0 = P1^3; //比较/捕获/PWM0外部引脚
sbit ECI = P1^2; //比较/捕获/PWM模块的外部时钟输入脚(最大值为Fosc/2)
sbit P1TXD = P1^7; //可选串口数据输出脚
sbit P1RXD = P1^6; //可选串口数据输入脚
sbit BRTCLKO = P1^0; //BRT时钟溢出脉冲输出脚
/////////////////////////////////
sfr P2 = 0xa0; //I/O端口2 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
//位描述 P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0
//初始值=1111,1111 1 1 1 1 1 1 1 1
sbit P27 = P2^7; //I/O口P2.7
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -