#include "reg51.h"
#include<intrins.h>
#include<stdio.h>
#define uint unsigned int
uint wei, liu;
sbit Max144_clk=P1^0;
sbit Max144_do=P1^1;
sbit Max144_cs=P1^2;
void conver(uint i)
{ uint ch;
ch=i&0x1000;
if(ch==0)
{wei=i;
}
else
{liu=i;
}
}
//===延迟函数====
void delay1ms(void)
{
unsigned char a,b;
for(b=102;b>0;b--)
for(a=3;a>0;a--);
}
void init(void)
{
SCON=0x50;
TMOD=0x20;
PCON=0x00;
TL1=0xFD;
TH1=0xFD;
ES=1;
TR1=1;
}
uint Max144(void)
{
char i;
uint buff=0;
Max144_clk=0;
Max144_cs=0;
_nop_();
_nop_();
_nop_();
for(i=0;i<16;i++)
{
buff<<=1;
Max144_clk=1;
buff|=Max144_do;
Max144_clk=0;
}
Max144_cs=1;
buff&=0x1fff;
return buff;
}
void send(void)
{
SBUF=0xff;
while(!TI);
TI=0;
delay1ms();
SBUF=wei/256;//发送高位
while(TI!=0);
TI=0;
delay1ms();
SBUF=wei%256;
while(TI!=0);
TI=0;
delay1ms();
SBUF=liu/256;//发送高位
while(TI!=0);
TI=0;
delay1ms();
SBUF=liu%256;
while(TI!=0);
TI=0;
delay1ms();
}
void main()
{
uint a,b;
init ();
wei=0,liu=0;
P1=0xff;
while(1)
{
a=0;
b=0;
a=Max144();
conver (a);
send();
}
}
程序能通过,可是在51上不能正常工作,用的AT89C51,求教哪里出错 |