atmega16单片机C语言程序

发布时间:2021-06-08

#include <mega16.h> //AVR单片机相关库

flash unsigned int t[9] = {0,956,865,759,716,638,568,506,470}; flash unsigned char d[9] = {0,105,116,132,140,157,176,198,209}; #define Max_note 32

flash unsigned char music[Max_note] =

{5,2,8,2,5,2,4,2,3,2,2,2,1,4,1,2,1,2,2,2,3,2,3,2,1,2,3,2,4,2,5,8}; unsigned char note_n;

unsigned int int_n;

bit play_on;

// External Interrupt 1 service routine

interrupt [EXT_INT1] void ext_int1_isr(void)

{

if (!play_on)

{

TCCR1B = 0x09;

}

}

// Timer 1 output compare A interrupt service routine

interrupt [TIM1_COMPA] void timer1_compa_isr(void)

{

if (!play_on)

{

note_n = 0;

int_n = 1;

play_on = 1;

}

else

{

if (--int_n == 0)

{

TCCR1B = 0x08;

if (note_n Max_note)

{

OCR1A = t[music[note_n]];

int_n = d[music[note_n]];

note_n++;

int_n = int_n * music[note_n];

note_n++;

TCCR1B = 0x09;

}

else

play_on = 0;

}

atmega16单片机C语言程序.doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219