程序执行后四位数码管全部显示为0,另外,程序中延时可保证完全正确,求高手找错,谢谢……
#include<stm8s103f3p.h>
#define ui unsigned int
#define uc unsigned char
#define DQ_HIGH() PD_DDR|=0x40; PD_CR1|=0x40;PD_ODR|=0x40
#define DQ_LOW() PD_DDR|=0x40; PD_CR1|=0x40;PD_ODR&=0xbf
#define DQ_IN() PD_DDR&=0xbf;PD_CR1|=0x40
uc const table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f};
uc const table0[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
uc temp1,temp2;
ui temp;
void delay(ui jx,ui jy)
{
ui x,y;
for(x=jx;x>0;x--);
for(y=jy;y>0;y--);
}
void init(void)
{
CLK_CKDIVR=0;
PA_DDR=0xff;
PA_CR1=0xff;
PA_ODR=0;
PC_DDR=0xff;
PC_CR1=0xff;
PC_ODR=0;
PD_DDR=0x4f;
PD_CR1=0x4f;
PD_ODR=0;
PA_CR2=0;
PC_CR2=0;
PD_CR2=0;
}
void pro(uc jp)
{
PC_ODR=jp;
PA_ODR=jp<<1;
}
void reset(void)
{
uc jf=1;
DQ_HIGH();
delay(1,1);
// while(jf)
//{
DQ_LOW();
delay(1000,150);//721us
DQ_HIGH();
delay(100,10);//71
DQ_IN();
if(PD_IDR&0x40==0x40)
{
jf=1;
}
else
jf=0;
delay(600,200);//502us///////////
//}
// DQ_HIGH();
}
void writebyte(uc dat)
{
uc i;
DQ_HIGH();
delay(1,1);
for(i=0;i<8;i++)
{
DQ_LOW();
delay(4,15);//14us
if(dat&0x01)
{
DQ_HIGH();
}
delay(70,5);//49
DQ_HIGH();
delay(1,1);
dat=dat>>1;
}
}
uc readbyte(void)
{
uc i,val;
for(i=0;i<8;i++)
{
val=val>>1;
DQ_HIGH();
delay(1,1);//3
DQ_LOW();
delay(1,1);delay(1,1);
DQ_HIGH();
delay(1,1);//3
DQ_IN();
if(PD_IDR&0x40==0x40)
{
val=val|0x80;
}
delay(70,5);//49
}
return val;
}
void display(ui jd)
{
uc bai,shi,ge,dian;
bai=jd/1000;
shi=jd%1000/100;
ge=jd%100/10;
dian=jd%10;
PD_ODR&=0xf0;
pro(table[bai]);
delay(25,15);
PD_ODR+=0x02;
pro(table0[shi]);
delay(25,15);
PD_ODR+=0x02;
pro(table[ge]);
delay(25,15);
PD_ODR+=0x02;
pro(table[dian]);
delay(25,15);
}
void get(void)
{
ui jn;
reset();
delay(1,1);
writebyte(0xcc);
delay(1,0);
writebyte(0x44);
for(jn=6500;jn>0;jn--)
display(temp);//
reset();
delay(1,1);
writebyte(0xcc);
delay(1,0);
writebyte(0xbe);
delay(1,1);
temp1=readbyte();
delay(1,0);
temp2=readbyte();
delay(5,5);
temp=((temp2<<8)+temp1)*6.25;
}
main()
{
init();
while (1)
{
get();
/* delay(1000,150);//721us
delay(100,10);//71
delay(600,200);//502us///////////
delay(4,15);//14us
delay(70,5);//49
for(jn=6500;jn>0;jn--)
display(temp);//*/
}
} |
|