本帖最后由 电子三极管 于 2015-11-27 11:25 编辑
本人求助 ,我使用的是CC2530F256 ZigBee的单片机 ,因为需要读字库芯片 GT21L16S2W ,而给字库芯片发送的地址是24位的地址 需要用长整型 unsigned long 类型;但是IAR编译器能正常编译通过,又是按照unsigned int 类型在跑。 而且也无法有bit 位的定义 为什么IAR编译器只能到达16位 而不能达到32位 本人用的是CD-EW8051-8101 51 版本编译器
如下程序:
#define SI P0_4
#define CLK P0_5
#define SO P0_6
#define CS P0_7
#define CS_L do {CS = 0;}while(0)
#define CS_H do {CS = 1;}while(0)
#define SI_L do {SI = 0;}while(0)
#define SI_H do {SI = 1;}while(0)
#define CLK_L do {CLK= 0;}while(0)
#define CLK_H do {CLK= 1;}while(0)
P0SEL &= ~0x10; // P0_4
P0DIR |= 0x10;
P0INP &= ~0x10;
P0SEL &= ~0x20; // P0_5 sck
P0DIR |= 0x20;
P0INP &= ~0x20;
P0SEL &= ~0x40; // P0_6 输入
P0DIR &= ~0x40;
P0INP &= ~0x40;
P0SEL &= ~0x80; // P0_7 cs
P0DIR |= 0x80;
P0INP &= ~0x80;
void SendByte(uint32 cmd)
{
unsigned char i;
cmd=cmd|0x03000000;
for(i=0;i<32;i++)
{
CLK_L;
if(cmd&0x80000000)
SI_H;
else
SI_L;
CLK_H;
cmd=cmd<<1;
}
}
unsigned char ReadByte(void)
{
unsigned char i;
unsigned char dat=0;
CLK_H;
for(i=0;i<8;i++)
{
CLK_L;
dat=dat<<1;
if(SO)
dat=dat|0x01;
else
dat&=0xfe;
CLK_H ;
}
return dat;
}
unsigned char r_dat_bat(uint32 address,unsigned char byte_long,unsigned char *p_arr)
{
unsigned int j=0;
CS_L;
SendByte(address);
for(j=0;j<byte_long;j++)
{
p_arr[j]=ReadByte();
}
CS_H;
return p_arr[0];
}
void gt_16_GetData (unsigned char MSB, unsigned char LSB, unsigned char* DZ_Data)
{
uint32 BaseAdd=0,Address;
if(MSB == 0xA9 && LSB >=0xA1)
Address = (282 + (LSB - 0xA1))*32+BaseAdd;
else if(MSB >=0xA1 && MSB <= 0xA3 && LSB >=0xA1)
Address =( (MSB - 0xA1) * 94 + (LSB - 0xA1))*32+ BaseAdd;
else if(MSB >=0xB0 && MSB <= 0xF7 && LSB >=0xA1)
Address = ((MSB - 0xB0) * 94 + (LSB - 0xA1)+ 846)*32+ BaseAdd;
r_dat_bat(Address,32,DZ_Data);
}
gt_16_GetData(0xC7,0xE9,WZ_Data);
注:0xC7,0xE9 是内码 WZ_Data保存32字节的点阵
|