欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
51單片機驅動TM1809源程序
[打印本頁]
作者:
趣致克林
時間:
2023-6-3 12:17
標題:
51單片機驅動TM1809源程序
//========================================================================//
//-----------MCU型號為STC15F104E(程序下載時輸入內置30MHz振蕩)-----------//
// 程序功能:向TM1809低速模式發送3個像素點數據并檢測交流過零信號以實現 //
// 七彩同步漸變循環。 ISP程序下載:P3.0(RXD) P3.1(TXD) //
// 交流過零檢測輸入:P3.2(采用外部0中斷) 數據輸出:P3.3 //
//========================================================================//
#include<reg52.h> //MCU資源頭文件
#include<intrins.h> //移位函數
#define nop _nop_();
#define uchar unsigned char //宏替換,方便書寫
#define uint unsigned int //宏替換,方便書寫
sbit DIO=P3^3; //數據輸出引腳聲明
uchar bdata LED_DAT; //可位操作的數據發送暫存變量聲明
sbit bit0=LED_DAT^0; //被發送的數據各位定義
sbit bit1=LED_DAT^1;
sbit bit2=LED_DAT^2;
sbit bit3=LED_DAT^3;
sbit bit4=LED_DAT^4;
sbit bit5=LED_DAT^5;
sbit bit6=LED_DAT^6;
sbit bit7=LED_DAT^7;
uint j; //時間控制全局變量聲明
uchar RR,GG,BB; //RGB灰度值全局變量聲明
void h_dat0(); //數碼BIT0
void h_dat1(); //數碼BIT1
void fs_rgbdat(); //發送RGB灰度數據
void red_jl(); //紅色漸亮
void red_jm(); //紅色漸滅
void green_jl(); //綠色漸亮
void green_jm(); //綠色漸滅
void blue_jl(); //藍色漸亮
void blue_jm(); //藍色漸滅
void white_jl(); //白色漸亮
void white_jm(); //白色漸滅
void delay_1ms(uint z); //延時函數聲明
//*****************************主程序開始*****************************//
void main()
{
while(1)
{
RR=0; GG=0; BB=0;
fs_rgbdat(); //發送RGB灰度數據
DIO=0; //數據IO口置0
delay_1ms(50); //延時100毫秒等待所有MCU復位
red_jl(); //紅色漸亮
red_jm(); //紅色漸滅
green_jl(); //綠色漸亮
green_jm(); //綠色漸滅
blue_jl(); //藍色漸亮
blue_jm(); //藍色漸滅
white_jl(); //白色漸亮
white_jm(); //白色漸滅
}
}
//*****************************主程序結束*****************************//
//*****************************子程序開始*****************************//
//=======================紅色漸亮=======================//
void red_jl()
{
uint i;
RR=0; GG=0; BB=0;
for(i=0; i<256; i++) //白色漸滅
{
fs_rgbdat(); //發送RGB灰度數據
DIO=0; //數據IO口置0
delay_1ms(5);
RR++;
}
RR=255; GG=0; BB=0;
}
//=======================紅色漸滅=======================//
void red_jm()
{
uint i;
RR=255; GG=0; BB=0;
for(i=0; i<256; i++) //白色漸滅
{
fs_rgbdat(); //發送RGB灰度數據
DIO=0; //數據IO口置0
delay_1ms(5);
RR--;
}
RR=0; GG=0; BB=0;
}
//=======================綠色漸亮=======================//
void green_jl()
{
uint i;
RR=0; GG=0; BB=0;
for(i=0; i<256; i++) //白色漸滅
{
fs_rgbdat(); //發送RGB灰度數據
DIO=0; //數據IO口置0
delay_1ms(5);
GG++;
}
RR=0; GG=255; BB=0;
}
//=======================綠色漸滅=======================//
void green_jm()
{
uint i;
RR=0; GG=255; BB=0;
for(i=0; i<256; i++) //白色漸滅
{
fs_rgbdat(); //發送RGB灰度數據
DIO=0; //數據IO口置0
delay_1ms(5);
GG--;
}
RR=0; GG=0; BB=0;
}
//=======================藍色漸亮=======================//
void blue_jl()
{
uint i;
RR=0; GG=0; BB=0;
for(i=0; i<256; i++) //白色漸滅
{
fs_rgbdat(); //發送RGB灰度數據
DIO=0; //數據IO口置0
delay_1ms(5);
BB++;
}
RR=0; GG=0; BB=255;
}
//=======================藍色漸滅=======================//
void blue_jm()
{
uint i;
RR=0; GG=0; BB=255;
for(i=0; i<256; i++) //白色漸滅
{
fs_rgbdat(); //發送RGB灰度數據
DIO=0; //數據IO口置0
delay_1ms(5);
BB--;
}
RR=0; GG=0; BB=0;
}
//=======================白色漸亮=======================//
void white_jl()
{
uint i;
RR=0; GG=0; BB=0;
for(i=0; i<256; i++) //白色漸滅
{
fs_rgbdat(); //發送RGB灰度數據
DIO=0; //數據IO口置0
delay_1ms(5);
RR++;
GG++;
BB++;
}
RR=255; GG=255; BB=255;
}
//=======================白色漸滅=======================//
void white_jm()
{
uint i;
RR=255; GG=255; BB=255;
for(i=0; i<256; i++) //白色漸滅
{
fs_rgbdat(); //發送RGB灰度數據
DIO=0; //數據IO口置0
delay_1ms(5);
RR--;
GG--;
BB--;
}
RR=0; GG=0; BB=0;
}
//=============低速模式數碼BIT0(高電平時間:600ns 低電平時間:1940ns 周期T=2.54US)=============//
void h_dat0()
{
DIO=1;
nop; nop; nop; nop; nop;
nop; nop; nop;
DIO=0;
nop; nop; nop; nop; nop;
nop; nop; nop; nop; nop;
nop; nop; nop; nop; nop;
nop; nop; nop; nop; nop;
nop; nop; nop; nop; nop;
nop; nop;
}
//=============低速模式數碼BIT1(高電平時間:1840ns 低電平時間:700ns 周期T=2.54US)=============//
void h_dat1()
{
DIO=1;
nop; nop; nop; nop; nop;
nop; nop; nop; nop; nop;
nop; nop; nop; nop; nop;
nop; nop; nop; nop; nop;
nop; nop; nop; nop; nop;
nop; nop; nop; nop; nop;
nop; nop; nop; nop; nop;
DIO=0;
}
//===================發送RGB灰度數據===================//
void fs_rgbdat() //發送RGB灰度數據
{
uint k;
for(k=0; k<1024; k++) //發送1024個像素點的數據 (燈的封裝與PCB封裝不一致,須按RBG的順序發送數據!!!)
{
LED_DAT=RR; //紅燈數據賦值給LED_DAT
if(bit7==1) h_dat1(); else h_dat0();
if(bit6==1) h_dat1(); else h_dat0();
if(bit5==1) h_dat1(); else h_dat0();
if(bit4==1) h_dat1(); else h_dat0();
if(bit3==1) h_dat1(); else h_dat0();
if(bit2==1) h_dat1(); else h_dat0();
if(bit1==1) h_dat1(); else h_dat0();
if(bit0==1) h_dat1(); else h_dat0();
LED_DAT=BB; //藍燈數據賦值給LED_DAT
if(bit7==1) h_dat1(); else h_dat0();
if(bit6==1) h_dat1(); else h_dat0();
if(bit5==1) h_dat1(); else h_dat0();
if(bit4==1) h_dat1(); else h_dat0();
if(bit3==1) h_dat1(); else h_dat0();
if(bit2==1) h_dat1(); else h_dat0();
if(bit1==1) h_dat1(); else h_dat0();
if(bit0==1) h_dat1(); else h_dat0();
LED_DAT=GG; //綠燈數據賦值給LED_DAT
if(bit7==1) h_dat1(); else h_dat0();
if(bit6==1) h_dat1(); else h_dat0();
if(bit5==1) h_dat1(); else h_dat0();
if(bit4==1) h_dat1(); else h_dat0();
if(bit3==1) h_dat1(); else h_dat0();
if(bit2==1) h_dat1(); else h_dat0();
if(bit1==1) h_dat1(); else h_dat0();
if(bit0==1) h_dat1(); else h_dat0();
}
}
//========================延時1MS======================//
void delay_1ms(uint z)
{
uint x,y;
for(x=z; x>0; x--)
for(y=2800; y>0; y--);
}
//*****************************程序結束*****************************//
復制代碼
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1