yanwen217 发表于 2014-3-31 14:00
可以站内短消息我,或者有问题发上来一起探讨哈 #include <reg51.h>
void Init8113(void);
void OpenChannel(unsigned char cChannel,unsigned char cVideoNumber);
void SendOrder(void);
//unsigned char cHopeChannel = 0;
sbit UPDATE = P1^7;
sbit DATAIN = P1^6;
sbit CLK = P1^5;
sbit CE = P1^4;
sbit OCE1 = P1^3;
sbit OCE2 = P1^2;
//unsigned char cOrder0[16]={0};
unsigned int i = 0;
unsigned char ChannelIn;
unsigned char ChannelOut;
void main()
{
Init8113();
SendOrder();
while(1)
{
//for(i=0;i<100;i++);
OpenChannel(ChannelOut,ChannelIn);
SendOrder();
}
}
void Init8113() //AD8113的初始化
{
//RESET = 1; //上电复位
OCE1 = 0;
for(i=0;i<50;i++);
OCE2 = 0;
for(i=0;i<50;i++);
UPDATE = 1;
CLK = 1;
CE = 0; //引脚硬件接地
//RESET = 0;
// for(i=0;i<50;i++);
//UPDATE = 0;
// for(i=0;i<50;i++);
//UPDATE = 1;
// for(i=0;i<50;i++);
//CLK = 1;
cOrder0[0] = 15 + 0x10; //D4置1
cOrder0[1] = 14 + 0x10; //D4置1
cOrder0[2] = 13 + 0x10; //D4置1
cOrder0[3] = 12 + 0x10; //D4置1
cOrder0[4] = 11 + 0x10; //D4置1
cOrder0[5] = 10 + 0x10;
cOrder0[6] = 9 + 0x10;
cOrder0[7] = 8 + 0x10;
cOrder0[8] = 7 + 0x10;
cOrder0[9] = 6 + 0x10;
cOrder0[10] = 5 + 0x10;
cOrder0[11] = 4 + 0x10;
cOrder0[12] = 3 + 0x10;
cOrder0[13] = 2 + 0x10;
cOrder0[14] = 1 + 0x10;
cOrder0[15] = 0 + 0x10;
}
void OpenChannel(unsigned char cChannel,unsigned char cVideoNumber) //打开新的通道
{
cOrder0[cChannel] = cVideoNumber + 0x10; //D4置1
}
/*
void Config() //构造要发送控制命令的数组
{
unsigned char cTemp;
for(cTemp=0; cTemp<16; cTemp++)
{
if(cOldChannel[cTemp] != cNewChannel[cTemp])
{
OpenChannel(ChannelOut,ChannelIn);
cOldChannel[cTemp] = cNewChannel[cTemp];
}
}
}*/
void SendOrder() //发送控制命令
{
unsigned char cTemp;
unsigned char cBit;
//unsigned char cOrder0[16]={0};
unsigned i = 0;
//第一组
/*
for(cTemp=0; cTemp<16; cTemp++)
{
for(cBit=0; cBit<5; cBit++)
{
if(((cOrder0[cTemp]&(0x10>>cBit) )== 0))
{
DATAIN = 0;
}
else
{
DATAIN = 1;
}
for(i = 0;i<100;i++);
CLK = 1;
for(i = 0;i<100;i++);
CLK = 0;
}
}
//第二组
for(cTemp=0; cTemp<16; cTemp++)
{
for(cBit=0; cBit<5; cBit++)
{
if(((cOrder0[cTemp]&(0x10>>cBit) )== 0))
{
DATAIN = 0;
}
else
{
DATAIN = 1;
}
for(i = 0;i<100;i++);
CLK = 1;
for(i = 0;i<100;i++);
CLK = 0;
}
}
//第三组
for(cTemp=0; cTemp<16; cTemp++)
{
for(cBit=0; cBit<5; cBit++)
{
if(((cOrder0[cTemp]&(0x10>>cBit) )== 0))
{
DATAIN = 0;
}
else
{
DATAIN = 1;
}
for(i = 0;i<100;i++);
CLK = 1;
for(i = 0;i<100;i++);
CLK = 0;
}
} */
//第四组
/*
cOrder0[0] = 1 + 0x10; //D4置1
cOrder0[1] = 2 + 0x10; //D4置1
cOrder0[2] = 3 + 0x10; //D4置1
cOrder0[3] = 4 + 0x10; //D4置1
cOrder0[4] = 5 + 0x10; //D4置1
for(cTemp=0; cTemp<16; cTemp++)
{
for(cBit=0; cBit<5; cBit++)
{
if(((cOrder0[cTemp]&(0x10>>cBit) )== 0))
{
DATAIN = 0;
}
else
{
DATAIN = 1;
}
}
CLK = 0;
for(i=0;i<5;i++);
CLK = 1;
}
UPDATE = 1;
for(i=0;i<5;i++);
UPDATE = 0;
for(i = 0;i<100;i++);
UPDATE = 1; */
for(cTemp=0; cTemp<16; cTemp++)
{
for(cBit=0; cBit<5; cBit++)
{
if((cOrder0[cTemp]&(0x10>>cBit)))
{
DATAIN = 1;
}
else
{
DATAIN = 0;
}
// for(i=0;i<5;i++);
CLK = 0;
// for(i=0;i<5;i++);
CLK = 1;
// for(i=0;i<10;i++);
}
}
// UPDATE = 1;
//for(i=0;i<50;i++);
UPDATE = 0;
// for(i = 0;i<5;i++);
UPDATE = 1;
// for(i = 0;i<5;i++);
CE = 1;
}
|