/*--------------------------------------------------------------------------
INTRINS.H
Intrinsic s for C51.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/
#ifndef __INTRINS_H__
#define __INTRINS_H__
extern void _nop_ (void);
extern bit _testbit_ (bit);
extern unsigned char _cror_ (unsigned char, unsigned char);
extern unsigned int _iror_ (unsigned int, unsigned char);
extern unsigned long _lror_ (unsigned long, unsigned char);
extern unsigned char _crol_ (unsigned char, unsigned char);
extern unsigned int _irol_ (unsigned int, unsigned char);
extern unsigned long _lrol_ (unsigned long, unsigned char);
extern unsigned char _chkfloat_(float);
#endif
/*--------------------------------------------------------------------------
伪本征函数——Keil C51头文件INTRINS.H的扩容工程
作者:HotPower@126.com 2004.5.27 第二版
--------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/
#define _setc_() CY = 1
#define _clrc_() CY = 0
#define _setb_(RBIT) RBIT = 1
#define _clrb_(RBIT) RBIT = 0
#define _clra_() ACC = 0
/*------------------------------------------------------------------------*/
#define _xorr_(RX) RX ^= RX //用于取奇偶位P,且RX=0
#define _andr_(RX) RX &= RX //用于取奇偶位P,且RX=不变
#define _orr_(RX) RX |= RX //用于取奇偶位P,且RX=不变
#define _notr_(RX) RX =~RX
/*------------------------------------------------------------------------*/
#define _movra_(RX) RX = ACC
#define _movar_(RX) ACC = RX
#define _movcb_(RBIT) CY = RBIT
#define _movbc_(RBIT) RBIT = CY
#define _movb0_(RBIT, RX) RBIT = RX & 0x01 //用于取RX的最低位
#define _movb7_(RBIT, RX) RBIT = RX & 0x80 //用于取RX的最高位
#define _movc0_(RX) CY = RX & 0x01
#define _movc7_(RX) CY = RX & 0x80
/*------------------------------------------------------------------------*/
#define _rrca_() CY = ACC & 0x01 //产生RRC A指令
#define _rlca_() CY = ACC & 0x80 //产生RLC A指令
/*------------------------------------------------------------------------*/
#define _rrcr_(RX) CY = RX & 0x01; RX = ACC //产生RRC RX指令
#define _rlcr_(RX) CY = RX & 0x80; RX = ACC //产生RLC RX指令
/*------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
累加器带进位右移指令 RRC A
#define _rrca_() CY = ACC & 0x01
汇编代码 rrc a
--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
累加器带进位左移指令 RLC A
#define _rlca_() CY = ACC & 0x80
汇编代码 rlc a
--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
寄存器带进位右移指令 RRC REG
#define _rrcr_(RX) CY = RX & 0x01; RX = ACC
汇编代码 mov a,RX
rrc a
mov RX,a
/*--------------------------------------------------------------------------
例:
C51程序
unsigned char i;
i = 0x55;
_setc_();//CY=1
_rrcr_(i);//i=0xaa,ACC=0xaa,CY=1
汇编代码
mov r7,#055h
setb c
mov a,r7
rrc a
mov r7,a
--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
寄存器带进位左移指令 RLC REG
#define _rlcar_(RX) CY = RX & 0x80; RX = ACC
汇编代码 mov a,RX
rlc a
mov RX,a
/*--------------------------------------------------------------------------
例:
C51程序
unsigned char i;
i = 0x55;
_setc_();//CY=1
_rlcr_(i);//i=0x55,ACC=0xab,CY=0
汇编代码
mov r7,#055h
setb c
mov a,r7
rlc a
mov r7,a
--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------
伪本征函数"汇编级"应用
----------------------------------------------------------------------------
1.写串行数据
C51程序
void writedata(unsigned char val)
{
_movar_(val);//或用ACC = val;
for (val = 8; val > 0; val--)
{
_clrb_(TXD);//或用TXD = 0;
_rrca_();
_movbc_(RXD);//或用RXD = CY;
_setb_(TXD);//或用TXD = 1;
_nop_();
}
}
A51代码
writedata:
mov a,r7
mov r7,#8
writedata_loop:
clr txd
rrc a
mov rxd,c
setb txd
nop
djnz r7,writedata_loop
ret
----------------------------------------------------------------------------
2.读串行数据
C51程序
unsigned char readdata(void)
{
unsigned char val;
for (val = 8; val > 0; val--)
{
_clrb_(TXD);//或用TXD = 0;
_nop_();
_movcb_(RXD);//或用CY = RXD;
_rrca_();
_setb_(TXD);//或用TXD = 1;
_nop_();
}
_movra_(val);//或用val = ACC;
return val;
}
A51代码
readdata:
mov r7,#8
readdata_loop:
clr txd
nop
mov c,rxd
rrc a
setb txd
nop
djnz r7,readdata_loop
mov r7,a
ret
--------------------------------------------------------------------------*/
(文章推荐人:长城笑气)