51单片机引入头文件报重复定义的错误

开发环境( 蓝色粗体字为特别注意内容)
1,开发板:89C52RC。

2,开发环境:Keil uv5

在用KEIL做51单片机开发的时候,有时会遇到一个奇怪的错误

compiling main.c...
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(13): error C231: 'P0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(14): error C231: 'P1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(15): error C231: 'P2': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(16): error C231: 'P3': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(17): error C231: 'PSW': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(18): error C231: 'ACC': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(19): error C231: 'B': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(20): error C231: 'SP': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(21): error C231: 'DPL': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(22): error C231: 'DPH': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(23): error C231: 'PCON': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(24): error C231: 'TCON': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(25): error C231: 'TMOD': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(26): error C231: 'TL0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(27): error C231: 'TL1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(28): error C231: 'TH0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(29): error C231: 'TH1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(30): error C231: 'IE': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(31): error C231: 'IP': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(32): error C231: 'SCON': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(33): error C231: 'SBUF': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(45): error C231: 'CY': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(46): error C231: 'AC': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(47): error C231: 'F0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(48): error C231: 'RS1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(49): error C231: 'RS0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(50): error C231: 'OV': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(51): error C231: 'P': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(54): error C231: 'TF1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(55): error C231: 'TR1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(56): error C231: 'TF0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(57): error C231: 'TR0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(58): error C231: 'IE1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(59): error C231: 'IT1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(60): error C231: 'IE0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(61): error C231: 'IT0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(64): error C231: 'EA': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(66): error C231: 'ES': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(67): error C231: 'ET1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(68): error C231: 'EX1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(69): error C231: 'ET0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(70): error C231: 'EX0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(74): error C231: 'PS': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(75): error C231: 'PT1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(76): error C231: 'PX1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(77): error C231: 'PT0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(78): error C231: 'PX0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(81): error C231: 'RD': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(82): error C231: 'WR': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(83): error C231: 'T1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(84): error C231: 'T0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(85): error C231: 'INT1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(86): error C231: 'INT0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(87): error C231: 'TXD': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(88): error C231: 'RXD': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(91): error C231: 'SM0': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(92): error C231: 'SM1': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(93): error C231: 'SM2': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(94): error C231: 'REN': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(95): error C231: 'TB8': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(96): error C231: 'RB8': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(97): error C231: 'TI': redefinition
E:\1_PROGRAM_FILE\KEIL\KEIL51\C51\INC\REG52.H(98): error C231: 'RI': redefinition

发现这些51单片机的寄存器都重复定义,一开始怀疑是不是reg51.h头文件的引入方式有问题,但是有时候正常,有时候又出现错误,甚是疑惑。

其实出现的错误的原因很简单,就是因为你工程里面的文件中有的文件引入reg51.h,有的文件引入reg52.h,这时候就会报错重复定义,把工程里面所有的引用都改成统一即可。

1、Ctrl+F

2、选择Find in Files全局搜索修改即可

你可能感兴趣的:(51单片机引入头文件报重复定义的错误)