?? tlc2543.c
字號:
/**************************************
TLC2543驅(qū)動程序
*************************************/
#include <reg51.h>
#include <intrins.h>
/**************************************
2543控制引腳宏定義
*************************************/
sbit CLOCK = P1^0; /*2543時(shí)鐘*/
sbit D_IN = P1^1; /*2543輸入*/
sbit D_OUT = P1^2; /*2543輸出*/
sbit _CS = P1^3; /*2543片選*/
#define uint unsigned int
#define uchar unsigned char
static unsigned char code seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共陰
//void delay (unsigned char i)
/**************************************
名稱:delay
功能:延時(shí)模塊
輸入?yún)?shù):n要延時(shí)的周期數(shù)
輸出參數(shù):無
*************************************/
void delay(uchar n)
{
uchar i;
for(i=0;i<n;i++)
{
_nop_();
}
}
/**************************************
名稱:read2543
功能:TLC2543驅(qū)動模塊
輸入?yún)?shù):port通道號
輸出參數(shù):ad轉(zhuǎn)換值
*************************************/
uint read2543(uchar port)
{
uint ad=0,i;
CLOCK=0;
_CS = 0;
port<<=4;
for(i=0;i<12;i++)
{
if(D_OUT) ad|=0x01;
D_IN=(bit)(port&0x80);
CLOCK=1;
delay(3);
CLOCK=0;
delay(3);
port<<=1;
ad<<=1;
}
_CS=1;
ad>>=1;
return(ad);
}
/**************************************
名稱:main
功能:主函數(shù)
輸入?yún)?shù):無
輸出參數(shù):無
*************************************/
void main(void)
{
unsigned int ad,aea;
float ff;
unsigned char i=0;
while(1)
{
ad=read2543(0);
ff=ad*1.22;
aea=(int)ff;
for(i=0;i<8;i++)
{
P2=0x0f-i;
P0=~seg[aea%10];
aea=aea/10;
delay(2000);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -