标题:
如何制作手动流水灯以及控制蜂鸣器
[打印本页]
作者:
ddsdssd
时间:
2017-5-5 08:39
标题:
如何制作手动流水灯以及控制蜂鸣器
如何制作手动流水灯以及控制蜂鸣器
完整代码下载:
实验六.docx
(13.01 KB, 下载次数: 7)
2017-5-5 08:38 上传
点击文件名下载附件
单片机实验程序
下载积分: 黑币 -5
实验六 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);
}
流水灯改(按一下向后进一位)
#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);
}
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1