|
先貼代碼#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主機(jī)模式
SPSTAT = 0xc0; //清中斷標(biāo)志
}
unsigned char spi_transfer(unsigned char addr)
{
unsigned char dat = 0;
SS = 0; //拉低從機(jī)SS管腳
SPDAT = addr; //發(fā)送測(cè)試數(shù)據(jù)
while (!(SPSTAT & 0x80)); //查詢完成標(biāo)志
dat = SPDAT;
SPSTAT = 0xc0; //清中斷標(biāo)志
SS = 1; //拉高從機(jī)的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; //定時(shí)器時(shí)鐘1T模式
TMOD &= 0xF0; //設(shè)置定時(shí)器模式
TL0 = 0x00; //設(shè)置定時(shí)初始值
TH0 = 0x28; //設(shè)置定時(shí)初始值
TF0 = 0; //清除TF0標(biāo)志
TR0 = 1; //定時(shí)器0開始計(jì)時(shí)
ET0 = 1; //使能定時(shí)器中斷
EA = 1;
}
void TM0_Isr() interrupt 1
{
display(p);
}
不管讀哪個(gè)寄存器都是0000,求大佬支個(gè)招或者有沒有51例程
|
|