初级会员

- 积分
- 130
- 金钱
- 130
- 注册时间
- 2016-1-10
- 在线时间
- 17 小时
|
发表于 2017-9-15 21:45:06
|
显示全部楼层
本帖最后由 xiezhoujian 于 2023-3-31 10:13 编辑
void WriteComm(unsigned int i)//MCU16位,写操作,先写要读的寄存器,常见IC的ID寄存器都是04H,你也可以读DAH,DBH,DCH
{
CS0=0;
RD0=1;
RS=0;
DBH=i>>8;
DBL=i;
WR0=0;
WR0=1;
CS0=1;
}
unsigned int ReadData(void)//MCU16位,读操作
{
unsigned int temp;
DBL = 0xff; //GPIO先拉高
DBH = 0xff;//GPIO先拉高
CS0 = 0;
RS = 1;
WR0 = 1;
RD0 = 0;
P4MDOUT = 0x00; //Set Input Mode Before Read
P2MDOUT = 0x00; //Set Input Mode Before Read
_nop_(); _nop_();_nop_(); _nop_();
RD0 = 1; //rad enable
_nop_(); _nop_();_nop_(); _nop_();
temp=DBH;//ID的低8位
temp<<=8;
temp|=DBL;//ID的高
P4MDOUT = 0xFF; //Set output Mode Before Read
P2MDOUT = 0xFF; //Set output Mode Before Read
RD0 = 1;
_nop_(); _nop_();_nop_(); _nop_();
CS0 = 1;
return temp; //返回ID值
}
|
|