感謝一下帖子
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)
一下方式讀引腳:
首先將整個程序配置為。╯mall)模式,
然后定義xdata空間的相關變量,如下:
uchar xdata temp;
uchar xdata result;
temp=0x08;
result=P4&temp;
if((result==0x08)
{
.......
}