STC15W408AS library 0.9.0
STC15Fxx.h
1#ifndef STC15Fxx_H
2#define STC15Fxx_H
3
4#include <compiler.h>
5
6// 包含本头文件后,不用另外再包含"REG51.H"
7// 适用于 STC15Wxx / STC15Fxx 系列的芯片
8// Modified based on STC-ISP version by: ZnHoCn
9
11//注意: STC15W4K32S4系列的芯片,上电后所有与PWM相关的IO口均为
12// 高阻态,需将这些口设置为准双向口或强推挽模式方可正常使用
13//相关IO: P0.6/P0.7/P1.6/P1.7/P2.1/P2.2
14// P2.3/P2.7/P3.7/P4.2/P4.4/P4.5
16
17//内核特殊功能寄存器 //复位值 描述
18#define _ACC 0xE0
19SFR(ACC, 0xE0); //0000,0000 累加器Accumulator
20#define _B 0xF0
21SFR(B, 0xF0); //0000,0000 B寄存器
22#define _PSW 0xD0
23SFR(PSW, 0xD0); //0000,0000 程序状态字
24SBIT(CY, _PSW, 7);
25SBIT(AC, _PSW, 6);
26SBIT(F0, _PSW, 5);
27SBIT(RS1, _PSW, 4);
28SBIT(RS0, _PSW, 3);
29SBIT(OV, _PSW, 2);
30SBIT(F1, _PSW, 1);
31SBIT(P, _PSW, 0);
32#define _SP 0x81
33SFR(SP, 0x81); //0000,0111 堆栈指针
34#define _DPL 0x82
35SFR(DPL, 0x82); //0000,0000 数据指针低字节
36#define _DPH 0x83
37SFR(DPH, 0x83); //0000,0000 数据指针高字节
38
39//I/O 口特殊功能寄存器
40#define _P0 0x80
41SFR(P0, 0x80); //1111,1111 端口0
42SBIT(P00, _P0, 0);
43SBIT(P01, _P0, 1);
44SBIT(P02, _P0, 2);
45SBIT(P03, _P0, 3);
46SBIT(P04, _P0, 4);
47SBIT(P05, _P0, 5);
48SBIT(P06, _P0, 6);
49SBIT(P07, _P0, 7);
50#define _P1 0x90
51SFR(P1, 0x90); //1111,1111 端口1
52SBIT(P10, _P1, 0);
53SBIT(P11, _P1, 1);
54SBIT(P12, _P1, 2);
55SBIT(P13, _P1, 3);
56SBIT(P14, _P1, 4);
57SBIT(P15, _P1, 5);
58SBIT(P16, _P1, 6);
59SBIT(P17, _P1, 7);
60#define _P2 0xA0
61SFR(P2, 0xA0); //1111,1111 端口2
62SBIT(P20, _P2, 0);
63SBIT(P21, _P2, 1);
64SBIT(P22, _P2, 2);
65SBIT(P23, _P2, 3);
66SBIT(P24, _P2, 4);
67SBIT(P25, _P2, 5);
68SBIT(P26, _P2, 6);
69SBIT(P27, _P2, 7);
70#define _P3 0xB0
71SFR(P3, 0xB0); //1111,1111 端口3
72SBIT(P30, _P3, 0);
73SBIT(P31, _P3, 1);
74SBIT(P32, _P3, 2);
75SBIT(P33, _P3, 3);
76SBIT(P34, _P3, 4);
77SBIT(P35, _P3, 5);
78SBIT(P36, _P3, 6);
79SBIT(P37, _P3, 7);
80#define _P4 0xC0
81SFR(P4, 0xC0); //1111,1111 端口4
82SBIT(P40, _P4, 0);
83SBIT(P41, _P4, 1);
84SBIT(P42, _P4, 2);
85SBIT(P43, _P4, 3);
86SBIT(P44, _P4, 4);
87SBIT(P45, _P4, 5);
88SBIT(P46, _P4, 6);
89SBIT(P47, _P4, 7);
90#define _P5 0xC8
91SFR(P5, 0xC8); //xxxx,1111 端口5
92SBIT(P50, _P5, 0);
93SBIT(P51, _P5, 1);
94SBIT(P52, _P5, 2);
95SBIT(P53, _P5, 3);
96SBIT(P54, _P5, 4);
97SBIT(P55, _P5, 5);
98SBIT(P56, _P5, 6);
99SBIT(P57, _P5, 7);
100#define _P6 0xE8
101SFR(P6, 0xE8); //0000,0000 端口6
102SBIT(P60, _P6, 0);
103SBIT(P61, _P6, 1);
104SBIT(P62, _P6, 2);
105SBIT(P63, _P6, 3);
106SBIT(P64, _P6, 4);
107SBIT(P65, _P6, 5);
108SBIT(P66, _P6, 6);
109SBIT(P67, _P6, 7);
110#define _P7 0xF8
111SFR(P7, 0xF8); //0000,0000 端口7
112SBIT(P70, _P7, 0);
113SBIT(P71, _P7, 1);
114SBIT(P72, _P7, 2);
115SBIT(P73, _P7, 3);
116SBIT(P74, _P7, 4);
117SBIT(P75, _P7, 5);
118SBIT(P76, _P7, 6);
119SBIT(P77, _P7, 7);
120
121#define _P0M0 0x94
122SFR(P0M0, 0x94); //0000,0000 端口0模式寄存器0
123#define _P0M1 0x93
124SFR(P0M1, 0x93); //0000,0000 端口0模式寄存器1
125#define _P1M0 0x92
126SFR(P1M0, 0x92); //0000,0000 端口1模式寄存器0
127#define _P1M1 0x91
128SFR(P1M1, 0x91); //0000,0000 端口1模式寄存器1
129#define _P2M0 0x96
130SFR(P2M0, 0x96); //0000,0000 端口2模式寄存器0
131#define _P2M1 0x95
132SFR(P2M1, 0x95); //0000,0000 端口2模式寄存器1
133#define _P3M0 0xB2
134SFR(P3M0, 0xB2); //0000,0000 端口3模式寄存器0
135#define _P3M1 0xB1
136SFR(P3M1, 0xB1); //0000,0000 端口3模式寄存器1
137#define _P4M0 0xB4
138SFR(P4M0, 0xB4); //0000,0000 端口4模式寄存器0
139#define _P4M1 0xB3
140SFR(P4M1, 0xB3); //0000,0000 端口4模式寄存器1
141#define _P5M0 0xCA
142SFR(P5M0, 0xCA); //0000,0000 端口5模式寄存器0
143#define _P5M1 0xC9
144SFR(P5M1, 0xC9); //0000,0000 端口5模式寄存器1
145#define _P6M0 0xCC
146SFR(P6M0, 0xCC); //0000,0000 端口6模式寄存器0
147#define _P6M1 0xCB
148SFR(P6M1, 0xCB); //0000,0000 端口6模式寄存器1
149#define _P7M0 0xE2
150SFR(P7M0, 0xE2); //0000,0000 端口7模式寄存器0
151#define _P7M1 0xE1
152SFR(P7M1, 0xE1); //0000,0000 端口7模式寄存器1
153
154//系统管理特殊功能寄存器
155#define _PCON 0x87
156SFR(PCON, 0x87); //0001,0000 电源控制寄存器
157#define _AUXR 0x8E
158SFR(AUXR, 0x8E); //0000,0000 辅助寄存器
159#define _AUXR1 0xA2
160SFR(AUXR1, 0xA2); //0000,0000 辅助寄存器1
161#define _P_SW1 0xA2
162SFR(P_SW1, 0xA2); //0000,0000 外设端口切换寄存器1
163#define _CLK_DIV 0x97
164SFR(CLK_DIV, 0x97); //0000,0000 时钟分频控制寄存器
165#define _BUS_SPEED 0xA1
166SFR(BUS_SPEED, 0xA1); //xx10,x011 总线速度控制寄存器
167#define _P1ASF 0x9D
168SFR(P1ASF, 0x9D); //0000,0000 端口1模拟功能配置寄存器
169#define _P_SW2 0xBA
170SFR(P_SW2, 0xBA); //0xxx,x000 外设端口切换寄存器
171
172//中断特殊功能寄存器
173#define _IE 0xA8
174SFR(IE, 0xA8); //0000,0000 中断控制寄存器
175SBIT(EA, _IE, 7);
176SBIT(ELVD, _IE, 6);
177SBIT(EADC, _IE, 5);
178SBIT(ES, _IE, 4);
179SBIT(ET1, _IE, 3);
180SBIT(EX1, _IE, 2);
181SBIT(ET0, _IE, 1);
182SBIT(EX0, _IE, 0);
183#define _IP 0xB8
184SFR(IP, 0xB8); //0000,0000 中断优先级寄存器
185SBIT(PPCA, _IP, 7);
186SBIT(PLVD, _IP, 6);
187SBIT(PADC, _IP, 5);
188SBIT(PS, _IP, 4);
189SBIT(PT1, _IP, 3);
190SBIT(PX1, _IP, 2);
191SBIT(PT0, _IP, 1);
192SBIT(PX0, _IP, 0);
193#define _IE2 0xAF
194SFR(IE2, 0xAF); //0000,0000 中断控制寄存器2
195#define _IP2 0xB5
196SFR(IP2, 0xB5); //xxxx,xx00 中断优先级寄存器2
197#define _INT_CLKO 0x8F
198SFR(INT_CLKO, 0x8F); //0000,0000 外部中断与时钟输出控制寄存器
199
200//定时器特殊功能寄存器
201#define _TCON 0x88
202SFR(TCON, 0x88); //0000,0000 T0/T1控制寄存器
203SBIT(TF1, _TCON, 7);
204SBIT(TR1, _TCON, 6);
205SBIT(TF0, _TCON, 5);
206SBIT(TR0, _TCON, 4);
207SBIT(IE1, _TCON, 3);
208SBIT(IT1, _TCON, 2);
209SBIT(IE0, _TCON, 1);
210SBIT(IT0, _TCON, 0);
211#define _TMOD 0x89
212SFR(TMOD, 0x89); //0000,0000 T0/T1模式寄存器
213#define _TL0 0x8A
214SFR(TL0, 0x8A); //0000,0000 T0低字节
215#define _TL1 0x8B
216SFR(TL1, 0x8B); //0000,0000 T1低字节
217#define _TH0 0x8C
218SFR(TH0, 0x8C); //0000,0000 T0高字节
219#define _TH1 0x8D
220SFR(TH1, 0x8D); //0000,0000 T1高字节
221#define _T4T3M 0xD1
222SFR(T4T3M, 0xD1); //0000,0000 T3/T4模式寄存器
223// #default _T3T4M 0xD1
224// SFR(T3T4M, 0xD1); //0000,0000 T3/T4模式寄存器
225#define _T4H 0xD2
226SFR(T4H, 0xD2); //0000,0000 T4高字节
227#define _T4L 0xD3
228SFR(T4L, 0xD3); //0000,0000 T4低字节
229#define _T3H 0xD4
230SFR(T3H, 0xD4); //0000,0000 T3高字节
231#define _T3L 0xD5
232SFR(T3L, 0xD5); //0000,0000 T3低字节
233#define _T2H 0xD6
234SFR(T2H, 0xD6); //0000,0000 T2高字节
235#define _T2L 0xD7
236SFR(T2L, 0xD7); //0000,0000 T2低字节
237#define _WKTCL 0xAA
238SFR(WKTCL, 0xAA); //0000,0000 掉电唤醒定时器低字节
239#define _WKTCH 0xAB
240SFR(WKTCH, 0xAB); //0000,0000 掉电唤醒定时器高字节
241#define _WDT_CONTR 0xC1
242SFR(WDT_CONTR, 0xC1); //0000,0000 看门狗控制寄存器
243
244//串行口特殊功能寄存器
245#define _SCON 0x98
246SFR(SCON, 0x98); //0000,0000 串口1控制寄存器
247SBIT(SM0, _SCON, 7);
248SBIT(SM1, _SCON, 6);
249SBIT(SM2, _SCON, 5);
250SBIT(REN, _SCON, 4);
251SBIT(TB8, _SCON, 3);
252SBIT(RB8, _SCON, 2);
253SBIT(TI, _SCON, 1);
254SBIT(RI, _SCON, 0);
255#define _SBUF 0x99
256SFR(SBUF, 0x99); //xxxx,xxxx 串口1数据寄存器
257#define _S2CON 0x9A
258SFR(S2CON, 0x9A); //0000,0000 串口2控制寄存器
259#define _S2BUF 0x9B
260SFR(S2BUF, 0x9B); //xxxx,xxxx 串口2数据寄存器
261#define _S3CON 0xAC
262SFR(S3CON, 0xAC); //0000,0000 串口3控制寄存器
263#define _S3BUF 0xAD
264SFR(S3BUF, 0xAD); //xxxx,xxxx 串口3数据寄存器
265#define _S4CON 0x84
266SFR(S4CON, 0x84); //0000,0000 串口4控制寄存器
267#define _S4BUF 0x85
268SFR(S4BUF, 0x85); //xxxx,xxxx 串口4数据寄存器
269#define _SADDR 0xA9
270SFR(SADDR, 0xA9); //0000,0000 从机地址寄存器
271#define _SADEN 0xB9
272SFR(SADEN, 0xB9); //0000,0000 从机地址屏蔽寄存器
273
274//ADC 特殊功能寄存器
275#define _ADC_CONTR 0xBC
276SFR(ADC_CONTR, 0xBC); //0000,0000 A/D转换控制寄存器
277#define _ADC_RES 0xBD
278SFR(ADC_RES, 0xBD); //0000,0000 A/D转换结果高8位
279#define _ADC_RESL 0xBE
280SFR(ADC_RESL, 0xBE); //0000,0000 A/D转换结果低2位
281
282//SPI 特殊功能寄存器
283#define _SPSTAT 0xCD
284SFR(SPSTAT, 0xCD); //00xx,xxxx SPI状态寄存器
285#define _SPCTL 0xCE
286SFR(SPCTL, 0xCE); //0000,0100 SPI控制寄存器
287#define _SPDAT 0xCF
288SFR(SPDAT, 0xCF); //0000,0000 SPI数据寄存器
289
290//IAP/ISP 特殊功能寄存器
291#define _IAP_DATA 0xC2
292SFR(IAP_DATA, 0xC2); //0000,0000 EEPROM数据寄存器
293#define _IAP_ADDRH 0xC3
294SFR(IAP_ADDRH, 0xC3); //0000,0000 EEPROM地址高字节
295#define _IAP_ADDRL 0xC4
296SFR(IAP_ADDRL, 0xC4); //0000,0000 EEPROM地址第字节
297#define _IAP_CMD 0xC5
298SFR(IAP_CMD, 0xC5); //xxxx,xx00 EEPROM命令寄存器
299#define _IAP_TRIG 0xC6
300SFR(IAP_TRIG, 0xC6); //0000,0000 EEPRPM命令触发寄存器
301#define _IAP_CONTR 0xC7
302SFR(IAP_CONTR, 0xC7); //0000,x000 EEPROM控制寄存器
303
304//PCA/PWM 特殊功能寄存器
305#define _CCON 0xD8
306SFR(CCON, 0xD8); //00xx,xx00 PCA控制寄存器
307SBIT(CF, _CCON, 7);
308SBIT(CR, _CCON, 6);
309SBIT(CCF2, _CCON, 2);
310SBIT(CCF1, _CCON, 1);
311SBIT(CCF0, _CCON, 0);
312#define _CMOD 0xD9
313SFR(CMOD, 0xD9); //0xxx,x000 PCA 工作模式寄存器
314#define _CL 0xE9
315SFR(CL, 0xE9); //0000,0000 PCA计数器低字节
316#define _CH 0xF9
317SFR(CH, 0xF9); //0000,0000 PCA计数器高字节
318#define _CCAPM0 0xDA
319SFR(CCAPM0, 0xDA); //0000,0000 PCA模块0的PWM寄存器
320#define _CCAPM1 0xDB
321SFR(CCAPM1, 0xDB); //0000,0000 PCA模块1的PWM寄存器
322#define _CCAPM2 0xDC
323SFR(CCAPM2, 0xDC); //0000,0000 PCA模块2的PWM 寄存器
324#define _CCAP0L 0xEA
325SFR(CCAP0L, 0xEA); //0000,0000 PCA模块0的捕捉/比较寄存器低字节
326#define _CCAP1L 0xEB
327SFR(CCAP1L, 0xEB); //0000,0000 PCA模块1的捕捉/比较寄存器低字节
328#define _CCAP2L 0xEC
329SFR(CCAP2L, 0xEC); //0000,0000 PCA模块2的捕捉/比较寄存器低字节
330#define _PCA_PWM0 0xF2
331SFR(PCA_PWM0, 0xF2); //xxxx,xx00 PCA模块0的PWM寄存器
332#define _PCA_PWM1 0xF3
333SFR(PCA_PWM1, 0xF3); //xxxx,xx00 PCA模块1的PWM寄存器
334#define _PCA_PWM2 0xF4
335SFR(PCA_PWM2, 0xF4); //xxxx,xx00 PCA模块1的PWM寄存器
336#define _CCAP0H 0xFA
337SFR(CCAP0H, 0xFA); //0000,0000 PCA模块0的捕捉/比较寄存器高字节
338#define _CCAP1H 0xFB
339SFR(CCAP1H, 0xFB); //0000,0000 PCA模块1的捕捉/比较寄存器高字节
340#define _CCAP2H 0xFC
341SFR(CCAP2H, 0xFC); //0000,0000 PCA模块2的捕捉/比较寄存器高字节
342
343//比较器特殊功能寄存器
344#define _CMPCR1 0xE6
345SFR(CMPCR1, 0xE6); //0000,0000 比较器控制寄存器1
346#define _CMPCR2 0xE7
347SFR(CMPCR2, 0xE7); //0000,0000 比较器控制寄存器2
348
349//增强型PWM波形发生器特殊功能寄存器
350#define _PWMCFG 0xF1
351SFR(PWMCFG, 0xF1); //x000,0000 PWM配置寄存器
352#define _PWMCR 0xF5
353SFR(PWMCR, 0xF5); //0000,0000 PWM控制寄存器
354#define _PWMIF 0xF6
355SFR(PWMIF, 0xF6); //x000,0000 PWM中断标志寄存器
356#define _PWMFDCR 0xF7
357SFR(PWMFDCR, 0xF7); //xx00,0000 PWM外部异常检测控制寄存器
358
359//如下特殊功能寄存器位于扩展RAM区域
360//访问这些寄存器,需先将P_SW2的BIT7设置为1,才可正常读写
361#define PWMC (*(unsigned int volatile xdata *)0xfff0)
362#define PWMCH (*(unsigned char volatile xdata *)0xfff0)
363#define PWMCL (*(unsigned char volatile xdata *)0xfff1)
364#define PWMCKS (*(unsigned char volatile xdata *)0xfff2)
365#define PWM2T1 (*(unsigned int volatile xdata *)0xff00)
366#define PWM2T1H (*(unsigned char volatile xdata *)0xff00)
367#define PWM2T1L (*(unsigned char volatile xdata *)0xff01)
368#define PWM2T2 (*(unsigned int volatile xdata *)0xff02)
369#define PWM2T2H (*(unsigned char volatile xdata *)0xff02)
370#define PWM2T2L (*(unsigned char volatile xdata *)0xff03)
371#define PWM2CR (*(unsigned char volatile xdata *)0xff04)
372#define PWM3T1 (*(unsigned int volatile xdata *)0xff10)
373#define PWM3T1H (*(unsigned char volatile xdata *)0xff10)
374#define PWM3T1L (*(unsigned char volatile xdata *)0xff11)
375#define PWM3T2 (*(unsigned int volatile xdata *)0xff12)
376#define PWM3T2H (*(unsigned char volatile xdata *)0xff12)
377#define PWM3T2L (*(unsigned char volatile xdata *)0xff13)
378#define PWM3CR (*(unsigned char volatile xdata *)0xff14)
379#define PWM4T1 (*(unsigned int volatile xdata *)0xff20)
380#define PWM4T1H (*(unsigned char volatile xdata *)0xff20)
381#define PWM4T1L (*(unsigned char volatile xdata *)0xff21)
382#define PWM4T2 (*(unsigned int volatile xdata *)0xff22)
383#define PWM4T2H (*(unsigned char volatile xdata *)0xff22)
384#define PWM4T2L (*(unsigned char volatile xdata *)0xff23)
385#define PWM4CR (*(unsigned char volatile xdata *)0xff24)
386#define PWM5T1 (*(unsigned int volatile xdata *)0xff30)
387#define PWM5T1H (*(unsigned char volatile xdata *)0xff30)
388#define PWM5T1L (*(unsigned char volatile xdata *)0xff31)
389#define PWM5T2 (*(unsigned int volatile xdata *)0xff32)
390#define PWM5T2H (*(unsigned char volatile xdata *)0xff32)
391#define PWM5T2L (*(unsigned char volatile xdata *)0xff33)
392#define PWM5CR (*(unsigned char volatile xdata *)0xff34)
393#define PWM6T1 (*(unsigned int volatile xdata *)0xff40)
394#define PWM6T1H (*(unsigned char volatile xdata *)0xff40)
395#define PWM6T1L (*(unsigned char volatile xdata *)0xff41)
396#define PWM6T2 (*(unsigned int volatile xdata *)0xff42)
397#define PWM6T2H (*(unsigned char volatile xdata *)0xff42)
398#define PWM6T2L (*(unsigned char volatile xdata *)0xff43)
399#define PWM6CR (*(unsigned char volatile xdata *)0xff44)
400#define PWM7T1 (*(unsigned int volatile xdata *)0xff50)
401#define PWM7T1H (*(unsigned char volatile xdata *)0xff50)
402#define PWM7T1L (*(unsigned char volatile xdata *)0xff51)
403#define PWM7T2 (*(unsigned int volatile xdata *)0xff52)
404#define PWM7T2H (*(unsigned char volatile xdata *)0xff52)
405#define PWM7T2L (*(unsigned char volatile xdata *)0xff53)
406#define PWM7CR (*(unsigned char volatile xdata *)0xff54)
407
408#endif