char led[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; char a[3]={0,0,0},code=0; void port_init(void) {
PORTA = 0x00; DDRA = 0x0F;
端口初始化 PORTB = 0x00;
PORTA作为输出控制LED DDRB = 0xFF;
PD0——PD5连接按键调节 PORTC = 0x00; //m103 output only
LED显示数值 DDRC = 0x01;
PC0接蜂鸣器 PORTD = 0xFF;
DDRD = 0x00; }
//初始化
void init_devices(void) {
//stop errant interrupts until set up
CLI(); //disable all interrupts port_init();
MCUCR = 0x00; GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources SEI(); //re-enable interrupts
//all peripherals are now initialized }
//延时子程序
void delay(int n)
{
char j;
while(n-->0)
for(j=0;j<1000;j++); }
//是否有键盘按下子程序 char pressed(void) {
if(PIND!=0xFF)return 1;
return 0;
}
//键盘扫描子程序 char keyscan(void) {
char keycode; if(pressed) display();
keycode=PIND;
while(pressed())display(); display();
return keycode; }
//按键处理子程序
void codedeal(void) {
switch(code) {
case 0b11111110: a[2]++; break;
延时子程序delay 延时N毫秒 检测是否有按键按下 并扫描按键 按键处理子程序 case 0b11111101: a[2]--; break;
case 0b11111011: a[1]++; break;
case 0b11110111: a[1]--; break;
case 0b11101111: a[0]++; break;
case 0b11011111: a[0]--; break;
case 0b10111111: a[2]++; break;
case 0b01111111: a[2]--; break; } }
//LED显示子程序 void display(void) {
char i;
for(i=0;i<3;i++) {
PORTB=led[a[i]];
PORTA=~(BIT(0)<PORTA=0xFF; } }
void main(void) {
float kk,j,n;
init_devices(); while(1) { j=0;
LED显示子程序 主程序按照现实的数值产生节拍 code=keyscan(); codedeal(); display();
kk=60000/(100*a[2]+10*a[1]+a[0]); PORTC|=BIT(0); display();
PORTC&=~BIT(0); n=kk/1-2.1;
while((j设计参数分析频率是120/min 时测定200拍的时间并调成程序内参数,最终测定n= kk/1-2.1
实物图
成员组成及分工
王滨龙 负责软件设计及调试
徐金龙 硬件设计,部分焊接及论文写作
徐卓 部分焊接,论文写作 及材料采购