最最近再调1302但调了很久还是没调出来,也查了很多资料但是找不出原因,就是如果在主程序中加读1302的化,1302的时间就不会走,而且数码管的显示也不对,如果主程序中把读的去掉,1302就能正常走,调了很久希望高手指点下(附件中有仿真图和程序)······
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define miao 0x80
#define fen 0x82
#define shi 0x84
#define ri 0x86
#define xingqi 0x88
#define yue 0x8a
#define nian 0x8c
#define wp 0x8e
sbit clk=P1^0;
sbit rst=P1^1;
sbit io=P1^2;
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
sbit P17=P1^7;
uchar a,b,c;
uchar tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
void delay(uint t)
{
uchar x,y ;
for(x=t;x>0;x--)
for(y=50;y>0;y--) ;
}
//写一字节
void writebyte(uchar date)
{
uchar ACC=date;
uchar i;
for(i=0;i<8;i++)
{
io=(bit)(ACC&0x01);
clk=1;
clk=0;
ACC=ACC>>1;
delay(1);
}
}
//读一字节
uchar readbyte()
{
uchar i;
//ACC=0x00;
io=0xff;
for(i=0;i<8;i++)
{ ACC=ACC>>1;
ACC7=io;
clk=0;
clk=1 ;
delay(1);
}
return ACC;
}
//先写地址,后写命令/数据
void write(uchar add,uchar datee)
{ //add=add&0xfe;
rst=0;
_nop_();
clk=0;
_nop_();
rst=1;
writebyte(add);
//delay(1);
writebyte(datee);
clk=1;
rst=0;
}
//先写地址,后读数据
uchar read(uchar add)
{
uchar dat1,dat2;
//add =add|0x01;
rst=0;
_nop_();
clk=0;
_nop_();
rst=1;
writebyte(add);
//delay(1);
dat1=readbyte();
clk=1;
rst=0;
// dat1=ACC;
// dat2=dat1/16; //数据进制转换
// dat1=dat1%16; //十六进制转十进制
// dat1=dat1+dat2*10;
return dat1 ;
}
void init()
{ write(wp,0x00);
write(miao,0x00);
write(fen,0x08);
write(shi,0x00);
write(ri,0x01);
write(xingqi,0x01);
write(yue,0x01);
write(nian,0x01);
write(wp,0x80);
}
void main()
{
init();
while(1)
{
read(0x83);
a=read(0x83);
b=a/10;
c=a%10;
P2=0xfe ;
P0=tab[c];
//delay(5);
//P2=0xfd ;
//P0=tab[c];
}
} |