⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tlc1543.c

📁 一个充电控制器的完整单片机程序
💻 C
字号:
/*
 TLC1543//SPI port//11 channels Analog input//10 bit//10us Rate

 2003.1.6
 */
#include <AT89X52.H>
#include <INTRINS.h>
#include "charger.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
 //----------------------------------------
 //data read from (port)channel of tlc2543
 unsigned int tlc1543(unsigned char port){
 unsigned char data i;
 word data c;
 c.i=0;
 CLOCK=0;
 P_CS=0;//low level start a/d 
 port<<=4;//move to high 4bit
 _nop_(); _nop_(); _nop_();
 for(i=0;i<4;i++){//input channels signal
   D_IN=(bit)(port&0x80);
	 CLOCK=1; _nop_();CLOCK=0;
   port<<=1;
   }
	D_IN=0;
 for(i=0;i<8;i++){//fill 8 clock signal
   CLOCK=1;_nop_();CLOCK=0;
   }
 P_CS=1;
 for(i=0;i<20;i++);//wait a/d conversion
 P_CS=0;
 for(i=0;i<4;i++){//get  bit
   D_OUT=1;
   CLOCK=1;
   c.b[0]<<=1;
   if(D_OUT)c.b[0]|=0x01;
   CLOCK=0;
   }
 for(i=0;i<8;i++){//get D7~D0 bit
   D_OUT=1;
   CLOCK=1;
   c.b[1]<<=1;
   if(D_OUT)c.b[1]|=0x01;
   CLOCK=0;
   }
 _nop_(); _nop_(); _nop_();
 P_CS=1;

 RESET_DOG;

 return c.i;
 }

/*
 //----------------------------------------
 //data read from (port)channel of tlc1543
 unsigned int tlc1543(unsigned char port){
 unsigned char idata i;
 word idata c;
 c.i=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;
 for(i=0;i<10;i++);//wait a/d conversion,EOC low is busy 
 P_CS=0;
 _nop_();
 for(i=0;i<2;i++){//get D9,D8 bit
   D_OUT=1;
   CLOCK=1;
   c.b[0]<<=1;
   if(D_OUT)c.b[0]|=0x01;
   CLOCK=0;
   }
 for(i=0;i<8;i++){//get D7~D0 bit
   D_OUT=1;
   CLOCK=1;
   c.b[1]<<=1;
   if(D_OUT)c.b[1]|=0x01;
   CLOCK=0;
   }
 P_CS=1;
 return c.i;
 }

*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -