📄 tlc1543.c
字号:
/*
TLC1543//SPI port//11 channels Analog input//10 bit//10us Rate
2003.1.6
*/
#include <AT89X52.H>
#include <INTRINS.h>
//hardware conection
#define CLOCK P1_2
#define D_IN P1_1
#define D_OUT P1_3
#define P_CS P1_0
#define EOC P1_4
typedef struct
{
unsigned char ah;
unsigned char al;
}word;
union bitseg
{
word byte;
unsigned int i;
};
//----------------------------------------
//data read from (port)channel of tlc1543
unsigned int tlc1543(unsigned char port){
unsigned char idata i;
union bitseg idata c;
c.byte.al=0,c.byte.ah=0;
CLOCK=0;
P_CS=0;//low level start a/d
port<<=4;//move to high 4bit
for(i=0;i<4;i++){//input channels signal
D_IN=(bit)(port&0x80);CLOCK=1;CLOCK=0;
port<<=1;
}
for(i=0;i<6;i++){//fill 6 clock signal
CLOCK=1;CLOCK=0;
}
P_CS=1;
_nop_(); _nop_(); _nop_(); _nop_();
P_CS=0;//wait a/d conversion,EOC low is busy
for(i=0;i<2;i++){//get D9,D8 bit
D_OUT=1;
CLOCK=1;
c.byte.ah<<=1;
if(D_OUT)c.byte.ah|=0x01;
CLOCK=0;
}
for(i=0;i<8;i++){//get D7~D0 bit
D_OUT=1;
CLOCK=1;
c.byte.al<<=1;
if(D_OUT)c.byte.al|=0x01;
CLOCK=0;
}
P_CS=1;
_nop_();
P1=0xff;
return c.i;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -