#include <htc.h>
#define uchar unsigned char
#define uint unsigned int
#define DIN RC0
#define SCLK RC1
#define CS RC2
void init();
void TLC5615_write_byte(uint date);
void SPI_write_byte(uchar x);
uint date;
uchar x;
void main()
{
init();
while(1)
{ //TRISA1=0;
//RA1=1;
TLC5615_write_byte(date);
}
}
void init()
{
TRISC0=0;
TRISC1=0;
TRISC2=0;
}
void TLC5615_write_byte(uint date)
{ CS=1;
SCLK=0;
DIN=0;
CS=0;
date<<2;
x=date;
SPI_write_byte(x>>8);
SPI_write_byte(x);
CS=1;
}
void SPI_write_byte(uchar x)
{
uchar i;
for(i=0;i<8;i++)
{
DIN=x&&0x80;
SCLK=1;
x<<1;
SCLK=0;
}
}
请高手帮我看看我写的用IO口模拟SPI通过TLC5615输出电压的程序,不知道什么原因,给一个值,输出电压始终为零,调了很长时间也没弄出来,实在不知道是什么地方出问题了,向高手求助,谢谢 |