现在的问题是官方代码配reg51.h头文件是没问题的,但如果用STC8.h头文件就会出错,是什么原因呢?
官方读写EEPROM代码
- #include "reg51.h"
- //#include "STC8.h"
- #include "intrins.h"
- //测试工作频率为11.0592MHz
- sfr IAP_DATA = 0xC2;
- sfr IAP_ADDRH = 0xC3;
- sfr IAP_ADDRL = 0xC4;
- sfr IAP_CMD = 0xC5;
- sfr IAP_TRIG = 0xC6;
- sfr IAP_CONTR = 0xC7;
- #define WT_30M 0x80
- #define WT_24M 0x81
- #define WT_20M 0x82
- #define WT_12M 0x83
- #define WT_6M 0x84
- #define WT_3M 0x85
- #define WT_2M 0x86
- #define WT_1M 0x87
- void IapIdle()
- {
- IAP_CONTR=0;
- IAP_CMD=0;
- IAP_TRIG=0;
- IAP_ADDRH=0x80;
- IAP_ADDRL=0;
- }
- char IapRead(int addr)
- {
- char dat;
-
- IAP_CONTR=WT_12M;
- IAP_CMD=1;
- IAP_ADDRL=addr;
- IAP_ADDRH=addr>>8;
- IAP_TRIG=0x5a;
- IAP_TRIG=0xa5;
- _nop_();
- dat=IAP_DATA;
- IapIdle();
-
- return dat;
- }
- void IapProgram(int addr,char dat)
- {
- IAP_CONTR=WT_12M;
- IAP_CMD=2;
- IAP_ADDRL=addr;
- IAP_ADDRH=addr>>8;
- IAP_DATA=dat;
- IAP_TRIG=0x5a;
- IAP_TRIG=0xa5;
- _nop_();
- IapIdle();
- }
- void IapErase(int addr)
- {
- IAP_CONTR=WT_12M;
- IAP_CMD=3;
- IAP_ADDRL=addr;
- IAP_ADDRH=addr>>8;
- IAP_TRIG=0x5a;
- IAP_TRIG=0xa5;
- _nop_();
- IapIdle();
-
- }
- void main()
- {
-
- IapErase(0x0400);
- P0=IapRead(0x0400);
- IapProgram(0x0400,0x12);
- P1=IapRead(0x0400);
-
- while(1);
-
- }
复制代码
reg51.h
- /*--------------------------------------------------------------------------
- REG51.H
- Header file for generic 80C51 and 80C31 microcontroller.
- Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
- All rights reserved.
- --------------------------------------------------------------------------*/
- #ifndef __REG51_H__
- #define __REG51_H__
- /* BYTE Register */
- sfr P0 = 0x80;
- sfr P1 = 0x90;
- sfr P2 = 0xA0;
- sfr P3 = 0xB0;
- sfr P4 = 0xc0;
- sfr P5 = 0xc8;
- sfr P6 = 0xe8;
- sfr P7 = 0xf8;
- sfr PSW = 0xD0;
- sfr ACC = 0xE0;
- sfr B = 0xF0;
- sfr SP = 0x81;
- sfr DPL = 0x82;
- sfr DPH = 0x83;
- sfr PCON = 0x87;
- sfr TCON = 0x88;
- sfr TMOD = 0x89;
- sfr TL0 = 0x8A;
- sfr TL1 = 0x8B;
- sfr TH0 = 0x8C;
- sfr TH1 = 0x8D;
- sfr IE = 0xA8;
- sfr IP = 0xB8;
- sfr SCON = 0x98;
- sfr SBUF = 0x99;
- /* BIT Register */
- /* PSW */
- sbit CY = 0xD7;
- sbit AC = 0xD6;
- sbit F0 = 0xD5;
- sbit RS1 = 0xD4;
- sbit RS0 = 0xD3;
- sbit OV = 0xD2;
- sbit P = 0xD0;
- /* TCON */
- sbit TF1 = 0x8F;
- sbit TR1 = 0x8E;
- sbit TF0 = 0x8D;
- sbit TR0 = 0x8C;
- sbit IE1 = 0x8B;
- sbit IT1 = 0x8A;
- sbit IE0 = 0x89;
- sbit IT0 = 0x88;
- /* IE */
- sbit EA = 0xAF;
- sbit ES = 0xAC;
- sbit ET1 = 0xAB;
- sbit EX1 = 0xAA;
- sbit ET0 = 0xA9;
- sbit EX0 = 0xA8;
- /* IP */
- sbit PS = 0xBC;
- sbit PT1 = 0xBB;
- sbit PX1 = 0xBA;
- sbit PT0 = 0xB9;
- sbit PX0 = 0xB8;
- /* P3 */
- sbit RD = 0xB7;
- sbit WR = 0xB6;
- sbit T1 = 0xB5;
- sbit T0 = 0xB4;
- sbit INT1 = 0xB3;
- sbit INT0 = 0xB2;
- sbit TXD = 0xB1;
- sbit RXD = 0xB0;
- /* SCON */
- sbit SM0 = 0x9F;
- sbit SM1 = 0x9E;
- sbit SM2 = 0x9D;
- sbit REN = 0x9C;
- sbit TB8 = 0x9B;
- sbit RB8 = 0x9A;
- sbit TI = 0x99;
- sbit RI = 0x98;
- #endif
复制代码
STC8.h
|