27,375
社区成员
发帖
与我相关
我的任务
分享
//MCU:STC12C5A60S2 晶振是33M
//TM1812芯片手册下载地址:http://wenku.baidu.com/view/31422efd04a1b0717fd5ddb7.html
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsinged long
#define nop() _nop_()
#define RGB_count 4
#define RGB_speed 40
sbit TM18xx_dat_in = P0^0;
sbit LED = P1^0;
void TM18xx_send_dat(uchar date) //高速,0码500n,1码1000n (33M)
{
uchar i;
for(i=0;i<8;i++)
{
if(date&0x80)
{
TM18xx_dat_in=1;
nop(); nop(); nop(); nop();
nop(); nop(); nop(); nop();
nop(); nop(); nop(); nop(); //最少14个nop,550NS可用,
nop(); nop(); nop(); nop();//多无限
TM18xx_dat_in=0;
nop(); nop(); nop(); nop();
nop(); nop(); nop();
}
else
{
TM18xx_dat_in=1;//120NS
nop(); nop(); nop(); nop();
nop(); nop(); nop(); //10个nop可用,420NS
// nop();
// nop(); //最少单单一个DIO=1;120nS,可用
// nop(); //最多13个nop,520NS可用
//nop();//1812.0921D加这一个nop,不可用
TM18xx_dat_in=0;
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
}
date<<=1;
}
}
void TM18xx_resst()
{
uint i;
TM18xx_dat_in =0;
for(i=500;i>0;i--); //>24us
}
void delay(uint t)
{
unsigned long j;
while(t--) for(j=0;j<1000;j++);
}
void main()
{
uchar i,num,t,n;
uchar ;
TM18xx_resst();
while(1)
{
for(n=RGB_count;n>0;n--) //确定RGB点数
{
TM18xx_send_dat(0xff); //红
TM18xx_send_dat(0x00); //绿
TM18xx_send_dat(0x00); //蓝
// TM18xx_resst();
}
TM18xx_resst();
delay(800);
for(n=RGB_count;n>0;n--) //确定RGB点数
{
TM18xx_send_dat(0x00); //红
TM18xx_send_dat(0xff); //绿
TM18xx_send_dat(0x00); //蓝
// TM18xx_resst();
}
TM18xx_resst();
delay(800);
for(n=RGB_count;n>0;n--) //确定RGB点数
{
TM18xx_send_dat(0x00); //红
TM18xx_send_dat(0x00); //绿
TM18xx_send_dat(0xff); //蓝
// TM18xx_resst();
}
TM18xx_resst();
delay(800);
for(n=RGB_count;n>0;n--) //确定RGB点数
{
TM18xx_send_dat(0xff); //红
TM18xx_send_dat(0xff); //绿
TM18xx_send_dat(0xff); //蓝
// TM18xx_resst();
}
TM18xx_resst();
delay(800);
}
}
/*本程序为内部测试程序,仅供参考。任何个人或单位因为直接使用本程序
造成的损失,本公司不承担任何责任*/