专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

关于SST89V58RD2的P4口的使用

作者:佚名   来源:本站原创   点击数:  更新时间:2010年09月14日   【字体:

感谢一下帖子

http://hi.baidu.com/ghy198607/blog/item/d9ae0063dbcc2dd6e6113a17.html

http://hi.baidu.com/baifei_110/blog/item/58086af1e9d9d9c47831aa5b.html

http://www.daxia.com/bibis/moredata30_1242625_86532.shtml

因为P4是无法位寻址的,这跟P0-P3不同,但是datasheet得sfr一节讲到P4 is similar to P0-P3!

而且P4的度操作有bug!

正确操作如下:

sfr P4 = 0xa5;

#define SetBit(Value,Bit)  Value |= (0x01<<Bit)     //Bit(0~7)
#define ClrBit(Value,Bit)  Value &= (~(0x01<<Bit))
用这种方式去做位操作。

比如

//4^0
#define CS_0         ClrBit(P4,0)
#define CS_1         SetBit(P4,0)   
//4^1
#define PR_0          ClrBit(P4,1)
#define PR_1          SetBit(P4,1)   

一下方式读引脚:

首先将整个程序配置为小(small)模式,
然后定义xdata空间的相关变量,如下:
uchar xdata temp;   
uchar xdata result;
temp=0x08;
result=P4&temp;
if((result==0x08)
{
.......
}

关闭窗口

相关文章