为什么在示波器上可以显示05啊,06啊这样的数据,但是在仿真状态下观察变量的值却一直为0,程序如下:
#include <p18f4550.h>
#define sda_in PORTEbits.RE1
#define sda_out LATEbits.LATE1
#define sck LATEbits.LATE0
#define rest LATAbits.LATA2
uchar readbyte()
{
uchar i,j,num;
j=0;
TRISEbits.TRISE1=1;
for(i=8;i>0;i--)
{
sda_in=1;
num >>=1;
if(sda_in)
num|=0x80;
else
num&=0x7f;
sck=1;
Nop();
Nop();
sck=0;
}
TRISEbits.TRISE1=0;
return num;
}
void writebyte(uchar addr)
{
uchar i,j=0;
for(i=8;i>0;i--)
{
if(addr & 0x01)
sda_out=1;
else
sda_out=0;
sck=1;
Nop();
Nop();
sck=0;
addr >>=1;
}
}
uchar read(uchar addr)
{
uchar num;
rest=1;
writebyte(addr);
num=readbyte();
rest=0;
return num;
}
void write(uchar addr,uchar num)
{
rest=1;
writebyte(addr);
writebyte(num);
rest=0;
}
void ds_init()
{
sck=0;
//LATEbits.LATE0=0;
rest=1;
TRISEbits.TRISE0=0;
TRISEbits.TRISE1=0;
TRISAbits.TRISA2=0;
write(0x8e,0x0); /* 允许写入单个数据字节 */
write(0x80,0x0); /* ch=0 */
write(0xfe,0x0);
}
void main(void)
{
uchar t;
// sys_init();
// pwm1();
ds_init();
write(0x82,0x12);//
write(0x84,0x07);//
// write(0x8e,0x80);
SetTimer();
while(1)
{
// write(0x82,0x12);//min=59
xxx[0]=read(0x83);
if(xxx[0]==0)
{
TRISCbits.TRISC1=0; //点亮第2个LED
PORTCbits.RC1=~PORTCbits.RC1;
}
}
}
而去晶振一直没有用示波器测出来,请教大虾们 |