注意切换时要在P页操作。
#include <REG_MA82G5B32.H>
void delay(unsigned int t)
{
unsigned int data i;
while(t--)
{
for(i=0;i<500;i++)
{
;
}
}
}
/***********************************************************************
* Function:Page_P_SFR_Write
*
* Description: 写P页寄存器
*
* Input: SFR,P页SFR的地址, dat,要写入的数据
*
* Output: None
*
* Return: None
**********************************************************************/
void Page_P_SFR_Write(unsigned char SFR,unsigned char dat)
{
bit EA_tmp = EA;
EA = 0;
IFADRH=0X00;
ISPCR |= 0x80;
IFMT = 4;
IFADRL = SFR;
IFD = dat;
SCMD = 0X46;
SCMD = 0XB9;
IFMT = 0;
ISPCR &= 0x7f;
IFADRH = 0XFF;
EA = EA_tmp;
}
/***********************************************************************
* Function:Page_P_SFR_Read
*
* Description: 读P页寄存器
*
* Input: SFR,P页SFR的地址
*
* Output: None
*
* Return: 读到的P页SFR寄存器的值
**********************************************************************/
unsigned char Page_P_SFR_Read(unsigned char SFR)
{
bit EA_tmp = EA;
EA = 0;
IFADRH=0X00;
ISPCR |= 0x80;
IFMT = 5;
IFADRL = SFR;
SCMD = 0X46;
SCMD = 0XB9;
IFMT = 0;
ISPCR &= 0x7f;
IFADRH = 0XFF;
EA = EA_tmp;
return IFD;
}
void main(void)
{
unsigned char tmp;
tmp=Page_P_SFR_Read(0x4c); //读DCON0(P页寄存器0X4C)
Page_P_SFR_Write(0x4c,tmp&0xFC);//切换P44,P45为IO。由于P44,P45默认为仿真口,
//要做为普通IO时写DCON0, 清零bit0 OCDE=0; P44,P45,P47为IO
while(1)
{
P44=~P44;
P45=~P45;
delay(1000);
}
}
|