51单片机-TLC5615代码

2019-04-15 12:22发布

仅供参考 按照程序中定义的管脚连接   数码管是用PNP三极管驱动共阳数码管     用定时器计数给5615 #include #define uint unsigned int #define uchar unsigned char uchar table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; sbit LED1=P2^0; sbit LED2=P2^1; sbit LED3=P2^2; sbit LED4=P2^3; sbit TLC5615_SCLK=P2^4; sbit TLC5615_CS=P2^5; sbit TLC5615_DIN=P2^6; uint num,num1; void delay(uint k) { uint i,j; for(i=11;i>0;i--) for(j=k;j>0;j--); } void display(uint n) { LED1=0; P0=table[n/1000]; delay(0); P0=0xff; LED1=1; LED2=0; P0=table[n%1000/100]; delay(0); P0=0xff; LED2=1; LED3=0; P0=table[n%100/10]; delay(0); P0=0xff; LED3=1; LED4=0; P0=table[n%10]; delay(0); P0=0xff; LED4=1; } void Write_TLC5615(uint date) { uint i; TLC5615_SCLK=0; TLC5615_CS=0; date<<=6; for(i=0;i<12;i++) { TLC5615_DIN=(bit)(date&0x8000); TLC5615_SCLK=1; date<<=1; TLC5615_SCLK=0; delay(0); } TLC5615_CS=1; TLC5615_SCLK=0; } void init() { TMOD=0x01; TH0=(65536-458)/256; TL0=(65536-458)%256; EA=1; ET0=1; TR0=1; } void main() { init(); while(1) { Write_TLC5615(num1); display(num1); } } void T0_Time() interrupt 1 { TH0=(65536-4580)/256; TL0=(65536-4580)%256; num++; if(num==512) { num=0; num1++; if(num1==1023) { num1=0; } } }