標(biāo)題:
如何制作手動(dòng)流水燈以及控制蜂鳴器
[打印本頁]
作者:
ddsdssd
時(shí)間:
2017-5-5 08:39
標(biāo)題:
如何制作手動(dòng)流水燈以及控制蜂鳴器
如何制作手動(dòng)流水燈以及控制蜂鳴器
完整代碼下載:
實(shí)驗(yàn)六.docx
(13.01 KB, 下載次數(shù): 7)
2017-5-5 08:38 上傳
點(diǎn)擊文件名下載附件
單片機(jī)實(shí)驗(yàn)程序
下載積分: 黑幣 -5
實(shí)驗(yàn)六 2.12 2.14
2.12
蜂鳴器改(按一下一直響 再按一下停止)
#include "config.h"
#define BEEPCON 1<<7
#define KEY 1<<20
int main (void)
{uint32 i;
int k=1;
PINSEL0=0x00000000;
IO0DIR=BEEPCON;
while(1)
{
if((IO0PIN&KEY)==0)
{
k=!k;
if(k==1)
{
IO0CLR=BEEPCON;
}
if(k==0)
{
IO0SET=BEEPCON;
}
}
for(i=0;i<1000;i++);
}
return(0);
}
流水燈改(按一下向后進(jìn)一位)
#include "config.h"
#include "config.h"
#define KEY 1<<20
#define LED1 1<<16
#define LED2 1<<17
#define LED3 1<<18
#define LED4 1<<19
#define LED5 1<<20
#define LED6 1<<21
#define LED7 1<<22
#define LED8 1<<23
#define LEDCON 0x00ff0000
const uint32 DISP_TAB[8]={0xff01ffff,0xff02ffff,0xff04ffff,0xff08ffff,
0xff10ffff,0xff20ffff,0xff40ffff,0xff80ffff};
void DelayNS(uint32 dly)
{
uint32 i;
for(;dly>0;dly--)
{
for(i=0;i<5000;i++);
}
}
int main (void)
{
uint8 i;
IO2DIR=LEDCON;
while(1)
{
for(i=0;i<8;)
{
if((IO0PIN&KEY)==0)
{DelayNS(1);
}
if((IO0PIN&KEY)==0)
{
DelayNS(10);
IO2CLR=DISP_TAB[i++];
DelayNS(10);
IO2SET=0xffffffff;
while((IO0PIN&KEY)==0)
}
}
}
return 0;
}
2.14
#include "config.h"
#define BEEPCON 1<<7 // P0.7
void __irq IRQ_Eint3(void)
{ uint32 i;
i = IO0SET;
if( (i&BEEPCON)==0 )
{
IO0SET = BEEPCON;
}
else
{
IO0CLR = BEEPCON;
}
while( (EXTINT&1<<3)!=0 )
{
EXTINT = 1<<3;
}
VICVectAddr = 0;
}
int main(void)
{
IRQEnable();
PINSEL1 = 3<<8;
IO0DIR = BEEPCON;
VICIntSelect = 0x00000000;
VICDefVectAddr = (int)IRQ_Eint3;
EXTMODE = 0x00;
EXTINT = 1<<3;
VICIntEnable = 1<<17;
while(1);
return(0);
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1