1024手机基地看电影,午夜福利视频导航,国产精品福利在线一区,亚洲欧美日韩另类成人,在线观看午夜日本理论片,成年超爽免费网站,国产精品成人免费,精品动作一级毛片,成人免费观看网站,97精品伊人久久大香蕉
標(biāo)題:
自己做的旋轉(zhuǎn)月球無線感應(yīng)彩色燈單片機(jī)源程序
[打印本頁]
作者:
丁后莊
時(shí)間:
2018-10-21 15:29
標(biāo)題:
自己做的旋轉(zhuǎn)月球無線感應(yīng)彩色燈單片機(jī)源程序
旋轉(zhuǎn)月球燈的感應(yīng)部分程序,可以無極調(diào)光
單片機(jī)源程序如下:
#include "main.h"
unsigned short TimeCounter_100ms;
unsigned char TimeFlag_100ms;
unsigned short TimeCounter_500ms;
unsigned char TimeFlag_500ms;
unsigned short TimeCounter_30ms;
unsigned char TimeFlag_30ms;
volatile unsigned int shuju[3]={0}; //存放數(shù)據(jù)
unsigned int temp=0; //臨時(shí)變量
unsigned char i,j; //數(shù)組及移位計(jì)數(shù)用
unsigned char biaozhi=0; //起始碼標(biāo)志位
unsigned char flag=1; //有鍵按下,打開定時(shí)器
unsigned int count=0;
unsigned char ledflag=0;
unsigned char xunhuan=1;
unsigned char suo=0;
/****************************************************************
*模塊名稱:初始化函數(shù)模塊
*功能描述:
*修改日期:2008-9-8
*****************************************************************/
void SystemInitial(void)
{
OSCCON=0x71;//8M內(nèi)部RC振蕩器
INTCON=0x00;
PIE1=0x00;
SETBIT(PIE1,0);//TMR1IE置1
ANSEL =0 ;
ANSELH = 0;
TRISA=0B10111111;
PORTA=0B00000000;
TimeCounter_100ms=0;
TimeFlag_100ms=0;
TimeCounter_500ms=0;
TimeFlag_500ms=0;
TimeCounter_30ms=0;
TimeFlag_30ms=0;
}
void main(void)
{
SystemInitial();
LedInitial();
Timer0Initial();
Ir_Init(); //初始化函數(shù)
PEIE=1; //PEIE: 外設(shè)中斷允許位
GIE=1; //開全局中斷*/
while(1)
{
if(shuju[1]==0XF906 ){shuju[1]=0;LedOff();suo=0;}
if(shuju[1]==0X3BC4 ){shuju[1]=0;LedOn();suo=0;}
if(shuju[1]==0Xd926 ){shuju[1]=0;Led1();suo=0;}
if(shuju[1]==0X59A6 ){shuju[1]=0;Led2();suo=0;}
if(shuju[1]==0X7986 ){shuju[1]=0;Led3();suo=0;}
if(shuju[1]==0x916E ){shuju[1]=0;Led4();suo=0;}
if(shuju[1]==0xa15e ){shuju[1]=0;Led5();suo=0;}
if(shuju[1]==0x817e ){shuju[1]=0;Led6();suo=0;}
if(shuju[1]==0x11ee ){shuju[1]=0;Led7();suo=0;}
if(shuju[1]==0X21DE ){shuju[1]=0;Led8();suo=0;}
if(shuju[1]==0X01FE ){shuju[1]=0;LedBlue();suo=0;}
if(shuju[1]==0xb14e ){shuju[1]=0;LedGreen();suo=0;}
if(shuju[1]==0x31Ce ){shuju[1]=0;LedRed();suo=0;}
if(shuju[1]==0x49b6 )
{
shuju[1]=0;
if(ledflag>1)ledflag--;
suo=1;
xunhuan=0;
}//左
/* if(shuju[1]==0x8976)
{
shuju[1]=0;
xunhuan=1;
suo=1;
}//循環(huán)
*/
if(shuju[1]==0x09f6 )
{
shuju[1]=0;
if(ledflag<12)ledflag++;
suo=1;
xunhuan=0;
}//右
if(suo==1)
{
if(ledflag==1){LedOn();}
if(ledflag==2){Led1();}
if(ledflag==3){Led2();}
if(ledflag==4){Led3();}
if(ledflag==5 ){Led4();}
if(ledflag==6){Led5();}
if(ledflag==7){Led6();}
if(ledflag==8){Led7();}
if(ledflag==9){Led8();}
if(ledflag==10){LedBlue();}
if(ledflag==11){LedGreen();}
if(ledflag==12){LedRed();}
}
if(xunhuan==1)
{
/* CLRBIT(PORTD,0);delay(2000);
SETBIT(PORTD,0);delay(2000);
Led2();delay(2000);
Led3();delay(2000);
Led4();delay(2000);
Led5();delay(2000);
Led6();delay(2000);
Led7();delay(2000);
Led8();delay(2000);
LedBlue();delay(2000);
LedGreen();delay(2000);
LedRed();delay(2000);
*/
}
if(TimeFlag_100ms==1)
{
TimeFlag_100ms=0;
}
if(TimeFlag_500ms==1)
{
TimeFlag_500ms=0;
}
if(TimeFlag_30ms==1)
{
TimeFlag_30ms=0;
}
}
}
void Timer0Initial(void)//TIMER0初始化
{
T0CS=0; // 選通Fosc/4
PSA=0; //設(shè)定為用TIMER0,而不是WDT
PS2=0; //1:2 預(yù)除2倍,數(shù)完250次=(1us)*250=250us
PS1=0;//PS2,PS1,PS0為除頻設(shè)置
PS0=0;
T0IF=0;//設(shè)置溢位初始值為0
TMR0=6; //預(yù)設(shè)TMR0=6,運(yùn)行250次會(huì)進(jìn)位
T0IE=1;
}
void Ir_Init(void)//初始化函數(shù)
{
SETBIT(TRISB,0);//RB0為輸入
CLRBIT(ANSEL,12);//作為數(shù)字io
INTE=1; //允許外部中斷
RBIE=1; //允許RB口中斷
INTEDG=0;
WPUB=0X01; //RB2上拉復(fù)位
T1CON=0x10;//配置定時(shí)器2倍預(yù)分頻,使用內(nèi)部時(shí)鐘,禁止定時(shí)器
TMR1H=0;//計(jì)數(shù)值清0
TMR1L=0;
}
void interrupt Timer0_ISR(void)//TIMER0 1ms定時(shí)
{
////////////////////////////
if(T0IF==1)
{
T0IF=0;
count++;
if(count==4)
{
TMR0=6;
count=0;
TimeCounter_30ms++;
if(TimeCounter_30ms>=30)
{
TimeFlag_30ms=TURE;
TimeCounter_30ms=0;
}
TimeCounter_100ms++;
if(TimeCounter_100ms>=100)
{
TimeFlag_100ms=TURE;
TimeCounter_100ms=0;
}
TimeCounter_500ms++;
if(TimeCounter_500ms>=500)
{
TimeFlag_500ms=TURE;
TimeCounter_500ms=0;
}
}
}
//////////////////////////////
if(INTF==1) //判斷是否為CCP1模塊中斷,當(dāng)在一個(gè)系統(tǒng)中時(shí)會(huì)用
{
if(flag==1)
{
TMR1H=0;
TMR1L=0;
TMR1ON=1; //開定時(shí)器
flag=0;
}else{
TMR1ON=0; //先停定時(shí)器
temp=TMR1L+TMR1H*256; //取數(shù)據(jù)并判斷
TMR1H=0; //清0計(jì)數(shù)值
TMR1L=0;
TMR1ON=1; //開定時(shí)器等待下一個(gè)脈沖到來
if(temp>12600&&temp<14600&&biaozhi==0) //起始碼13500
{
biaozhi=1; //當(dāng)檢測(cè)到起始碼時(shí),下次直接進(jìn)行入數(shù)據(jù)判斷
i=0;
j=0;
//LedBlue();
}
else //數(shù)據(jù)判斷區(qū)
{
if((temp < 1300)&&(temp > 1000)) //時(shí)間在2.2ms左右的為數(shù)碼1120
{
shuju[i]=shuju[i]<<1;
j++;
}else if((temp < 2390)&&(temp > 2000)) //時(shí)間在4ms左右的為為數(shù)碼1 2240
{
shuju[i]=(shuju[i]<<1)+1;
j++;
}
else
biaozhi=0; //否則為終止碼,清0起始碼標(biāo)志位,準(zhǔn)備下一次按鍵的接收
}
……………………
…………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
Program.zip
(403.94 KB, 下載次數(shù): 7)
2018-10-21 15:28 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
admin
時(shí)間:
2018-10-21 18:42
補(bǔ)全原理圖或者詳細(xì)說明一下電路連接即可獲得100+黑幣
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1