单片机快速读取15X16点阵字库芯片的程序,读不出数据,求解
时间:10-02
整理:3721RD
点击:
#include<stc12c5a60s2.h>
#include<intrins.h>
sbit CS = P4^0; // 片选信号
sbit SCLK = P4^3; // 时钟信号
sbit MOSI = P4^1; // 串行数据输入
sbit MISO = P4^2; // 串行数据输出
unsigned char flag,MSB,LSB;
unsigned char table[2];
unsigned char Hz_32[32];
unsigned char bdata Hz_08;
sbit Hz_080 = Hz_08^0;
sbit Hz_081 = Hz_08^1;
sbit Hz_082 = Hz_08^2;
sbit Hz_083 = Hz_08^3;
sbit Hz_084 = Hz_08^4;
sbit Hz_085 = Hz_08^5;
sbit Hz_086 = Hz_08^6;
sbit Hz_087 = Hz_08^7;
void Init_UART();
void Init_SPI();
void SPI_SendByte(unsigned char date);
unsigned char ZIKU();
void main()
{
unsigned long Address;
if(MSB>=0xA1&&MSB<=0xA9&&LSB>=0xA1)
Address=(94*(MSB-0xA1)+(LSB-0xA1))*32+0x2C9D0;
else if(MSB>=0xB0&&MSB<=0xF7&&LSB>=0xA1)
Address=(94*(MSB-0xB0)+(LSB-0xA1)+846)*32+0x2C9D0;
Init_UART();
SPI_SendByte(0x0b);
SPI_SendByte((Address>>16)&0xff);
SPI_SendByte((Address)&0xff);
SPI_SendByte(0xff);
while(1)
{
if(flag == 1)
{
ES = 0;
flag = 0;
SBUF = ZIKU();
while(!TI);
TI = 0;
ES = 1;
}
}
}
void SPI_SendByte(unsigned char date)
{
unsigned char i;
CS = 0;
for(i=0;i<8;i++)
{
SCLK = 0;
if((date&0x80) == 0x80)
MOSI = 1; // 传送位1
else
MOSI = 0; // 否则传送位0
date = date<<1;
SCLK = 1;
}
}
unsigned char ZIKU()
{
unsigned char j,k;
unsigned char tdata = 0x00;
SPDAT = 0x00;
for(k=0;k<32;k++)
{
for(j=0;j<8;j++)
{
SCLK = 1;
tdata = tdata << 1;
if(MISO == 1)
tdata = tdata | 0x01; //若接收到的位为1,则最后一位置1
else
tdata = tdata & 0xfe; //若接收到的位为0,则最后一位置0
SCLK = 0;
}
Hz_32[k] = tdata;
k++;
}
return Hz_32[32];
}
/*unsigned char ZIKU()
{
unsigned char k;
CS = 0;
for(k=0;k<32;k++)
{
SCLK = 1;
Hz_087 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_086 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_085 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_084= MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_083 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_082 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_081 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_080 = MISO;
SCLK = 0;
Hz_32[k] = Hz_08;
k++;
}
return Hz_32[32];
CS = 1;
} */
void Init_UART()
{
TMOD = 0X20;
TH1 = 0XFD;
TL1 = 0XFD;
TR1 = 1;
REN = 1;
SM0 = 0;
SM1 = 1;
EA = 1;
ES = 1;
IE2 = 0x02;
}
void ser() interrupt 4
{
unsigned char n;
RI = 0;
table[n] = SBUF;
n++;
MSB = table[0];
LSB = table[1];
if(n >= 2)
{
n = 0;
flag = 1;
}
}
#include<intrins.h>
sbit CS = P4^0; // 片选信号
sbit SCLK = P4^3; // 时钟信号
sbit MOSI = P4^1; // 串行数据输入
sbit MISO = P4^2; // 串行数据输出
unsigned char flag,MSB,LSB;
unsigned char table[2];
unsigned char Hz_32[32];
unsigned char bdata Hz_08;
sbit Hz_080 = Hz_08^0;
sbit Hz_081 = Hz_08^1;
sbit Hz_082 = Hz_08^2;
sbit Hz_083 = Hz_08^3;
sbit Hz_084 = Hz_08^4;
sbit Hz_085 = Hz_08^5;
sbit Hz_086 = Hz_08^6;
sbit Hz_087 = Hz_08^7;
void Init_UART();
void Init_SPI();
void SPI_SendByte(unsigned char date);
unsigned char ZIKU();
void main()
{
unsigned long Address;
if(MSB>=0xA1&&MSB<=0xA9&&LSB>=0xA1)
Address=(94*(MSB-0xA1)+(LSB-0xA1))*32+0x2C9D0;
else if(MSB>=0xB0&&MSB<=0xF7&&LSB>=0xA1)
Address=(94*(MSB-0xB0)+(LSB-0xA1)+846)*32+0x2C9D0;
Init_UART();
SPI_SendByte(0x0b);
SPI_SendByte((Address>>16)&0xff);
SPI_SendByte((Address)&0xff);
SPI_SendByte(0xff);
while(1)
{
if(flag == 1)
{
ES = 0;
flag = 0;
SBUF = ZIKU();
while(!TI);
TI = 0;
ES = 1;
}
}
}
void SPI_SendByte(unsigned char date)
{
unsigned char i;
CS = 0;
for(i=0;i<8;i++)
{
SCLK = 0;
if((date&0x80) == 0x80)
MOSI = 1; // 传送位1
else
MOSI = 0; // 否则传送位0
date = date<<1;
SCLK = 1;
}
}
unsigned char ZIKU()
{
unsigned char j,k;
unsigned char tdata = 0x00;
SPDAT = 0x00;
for(k=0;k<32;k++)
{
for(j=0;j<8;j++)
{
SCLK = 1;
tdata = tdata << 1;
if(MISO == 1)
tdata = tdata | 0x01; //若接收到的位为1,则最后一位置1
else
tdata = tdata & 0xfe; //若接收到的位为0,则最后一位置0
SCLK = 0;
}
Hz_32[k] = tdata;
k++;
}
return Hz_32[32];
}
/*unsigned char ZIKU()
{
unsigned char k;
CS = 0;
for(k=0;k<32;k++)
{
SCLK = 1;
Hz_087 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_086 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_085 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_084= MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_083 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_082 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_081 = MISO;
SCLK = 0;
_nop_();
SCLK = 1;
Hz_080 = MISO;
SCLK = 0;
Hz_32[k] = Hz_08;
k++;
}
return Hz_32[32];
CS = 1;
} */
void Init_UART()
{
TMOD = 0X20;
TH1 = 0XFD;
TL1 = 0XFD;
TR1 = 1;
REN = 1;
SM0 = 0;
SM1 = 1;
EA = 1;
ES = 1;
IE2 = 0x02;
}
void ser() interrupt 4
{
unsigned char n;
RI = 0;
table[n] = SBUF;
n++;
MSB = table[0];
LSB = table[1];
if(n >= 2)
{
n = 0;
flag = 1;
}
}
不能返回数组啊
你读出来了吗?
怎么向字库芯片写程序啊,,,,,,,急,,,急,,,,谢谢