先贴代码#include <MAX3185.h>
#define LTCBH 0x0c
#define LTCBM 0x0d
#define LTCBL 0x0e
unsigned char tempL,tempM,tempH;
void SPI_INIT()
{
P_SW1 = 0x04; //SS_2/P2.2, MOSI_2/P2.3, MISO_2/P2.4, SCLK_2/P2.5
SS = 1;
SPCTL = 0x50; //使能SPI主机模式
SPSTAT = 0xc0; //清中断标志
}
unsigned char spi_transfer(unsigned char addr)
{
unsigned char dat = 0;
SS = 0; //拉低从机SS管脚
SPDAT = addr; //发送测试数据
while (!(SPSTAT & 0x80)); //查询完成标志
dat = SPDAT;
SPSTAT = 0xc0; //清中断标志
SS = 1; //拉高从机的SS管脚
return dat;
}
void main()
{
GPIO_INIT();
TM0_INit();
delayms(500);
//spi_transfer2(0x80,0x01);
while(1)
{
//p = 0;
p = spi_transfer(0x0c);
delayms(500);
}
}
void TM0_INit()
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x00; //设置定时初始值
TH0 = 0x28; //设置定时初始值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1; //使能定时器中断
EA = 1;
}
void TM0_Isr() interrupt 1
{
display(p);
}
不管读哪个寄存器都是0000,求大佬支个招或者有没有51例程
|