TLC1549数码管显示程序
#include"reg52.h"
#include "intrins.h"
sbit AD_CS = P3^7;
sbit AD_DAT = P3^5;
sbit AD_CLK = P3^4;
unsigned char i,j,q,p,k; //
unsigned int AD_Temp,Temp,TempA;
/**********4个7段数码管锁存器地址************/
#define LED1ADDR 0x80
#define LED2ADDR 0x81
#define LED3ADDR 0x82
#define LED4ADDR 0x83
/******0-9 a-f 的7段数码管显示编码**********/
unsigned char ledcode[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x00};
// 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f
/***************存放要显示的数字值********/
unsigned char val[4];//
/***************延时的子程序***************/
void delay(unsigned int t)
{
unsigned int ii;
for(i=0;ii<t;ii++)
//for(j=0;j<10;j++)
;
}
void DelayMS(unsigned int T)
{
for(;T>0;T--);
}
/**********4个7段数码管锁存器地址************/
TLC1549() //111111
{
TempA=0;
Temp=0;
AD_CS = 1;
AD_CLK = 1;
AD_DAT = 1;
AD_CS = 0;
// DelayMS(10);
_nop_();
for(i=0;i<2;i++)
{
AD_CLK =0;
_nop_();
if(AD_DAT)
{ Temp+=0x01;}
Temp =Temp<<1;
AD_CLK=1;
_nop_();
}
for(i=0;i<8;i++)
{
AD_CLK =0;
_nop_();
if(AD_DAT)
{ TempA+=0x01; }
TempA =TempA<<1;
AD_CLK =1;
_nop_();
}
AD_CLK =0;
AD_CS =0;
AD_Temp= Temp*256+TempA;
P0=AD_Temp;
j=AD_Temp/1000;
q=(AD_Temp%1000)/100;
p=AD_Temp%1000%100/10;
k=AD_Temp%1000%100%10;
}
/* 写锁存器的子程序 */
void wraddr(unsigned int addr1,unsigned char d)
{
P2=addr1;
P0=d;
}
/* 显示子程序 */
void display(void)
{ unsigned int addr[4]={LED1ADDR,LED2ADDR,LED3ADDR,LED4ADDR};
delay(50);
wraddr(addr[0],ledcode[val[j]]);
delay(50);
wraddr(addr[1],ledcode[val[q]]);
delay(50);
wraddr(addr[2],ledcode[val[p]]);
delay(50);
wraddr(addr[3],ledcode[val[k]]);
}
/* 初始化子程序 */
void init(void)
{ wraddr(LED1ADDR,0XFF);
wraddr(LED2ADDR,0XFF);
wraddr(LED3ADDR,0XFF);
wraddr(LED4ADDR,0XFF);
//输入要显示的数值
val[0]=1;
val[1]=2;
val[2]=3;
val[3]=4;
}
/* 主程序入口 */
int main(void)
{ init();
while(1)
{
TLC1549();
display();
}
}