搜索
bottom↓
回复: 30

AVR菜鸟移植ICCAVR到WINAVR演奏出第一首歌(music.c)

[复制链接]

出0入0汤圆

发表于 2004-12-28 21:53:04 | 显示全部楼层 |阅读模式
##############music的makefile文件################################





# Hey Emacs, this is a -*- makefile -*-

#

# WinAVR Sample makefile written by Eric B. Weddington, J鰎g Wunsch, et al.

# Released to the Public Domain

# Please read the make user manual!

#

# Additional material for this makefile was submitted by:

#  Tim Henigan

#  Peter Fleury

#  Reiner Patommel

#  Sander Pool

#  Frederik Rouleau

#  Markus Pfaff

#

# On command line:

#

# make all = Make software.

#

# make clean = Clean out built project files.

#

# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).

#

# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio

#                4.07 or greater).

#

# make program = Download the hex file to the device, using avrdude.  Please

#                customize the avrdude settings below first!

#

# make filename.s = Just compile filename.c into the assembler code only

#

# To rebuild project do "make clean" then "make all".

#





# MCU name

MCU = atmega8



# Output format. (can be srec, ihex, binary)

FORMAT = ihex



# Target file name (without extension).

TARGET = music





# List C source files here. (C dependencies are automatically generated.)

SRC = $(TARGET).c





# List Assembler source files here.

# Make them always end in a capital .S.  Files ending in a lowercase .s

# will not be considered source files but generated files (assembler

# output from the compiler), and will be deleted upon "make clean"!

# Even though the DOS/Win* filesystem matches both .s and .S the same,

# it will preserve the spelling of the filenames, and gcc itself does

# care about how the name is spelled on its command-line.

ASRC =







# Optimization level, can be [0, 1, 2, 3, s].

# 0 = turn off optimization. s = optimize for size.

# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)

OPT = s



# Debugging format.

# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.

# AVR (extended) COFF requires stabs, plus an avr-objcopy run.

DEBUG = stabs



# List any extra directories to look for include files here.

#     Each directory must be seperated by a space.

EXTRAINCDIRS =





# Compiler flag to set the C Standard level.

# c89   - "ANSI" C

# gnu89 - c89 plus GCC extensions

# c99   - ISO C99 standard (not yet fully implemented)

# gnu99 - c99 plus GCC extensions

CSTANDARD = -std=gnu99



# Place -D or -U options here

CDEFS =



# Place -I options here

CINCS =





# Compiler flags.

#  -g*:          generate debugging information

#  -O*:          optimization level

#  -f...:        tuning, see GCC manual and avr-libc documentation

#  -Wall...:     warning level

#  -Wa,...:      tell GCC to pass this to the assembler.

#    -adhlns...: create assembler listing

CFLAGS = -g$(DEBUG)

CFLAGS += $(CDEFS) $(CINCS)

CFLAGS += -O$(OPT)

CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffreestanding

CFLAGS += -Wall -Wstrict-prototypes

CFLAGS += -Wa,-adhlns=$(<:.c=.lst)

CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))

CFLAGS += $(CSTANDARD)







# Assembler flags.

#  -Wa,...:   tell GCC to pass this to the assembler.

#  -ahlms:    create listing

#  -gstabs:   have the assembler create line number information; note that

#             for use in COFF files, additional information about filenames

#             and function names needs to be present in the assembler source

#             files -- see avr-libc docs [FIXME: not yet described there]

ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs







#Additional libraries.



# Minimalistic printf version

PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min



# Floating point printf version (requires MATH_LIB = -lm below)

PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt



PRINTF_LIB =



# Minimalistic scanf version

SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min



# Floating point + %[ scanf version (requires MATH_LIB = -lm below)

SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt



SCANF_LIB =



MATH_LIB = -lm



# External memory options



# 64 KB of external RAM, starting after internal RAM (ATmega128!),

# used for variables (.data/.bss) and heap (malloc()).

#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff



# 64 KB of external RAM, starting after internal RAM (ATmega128!),

# only used for heap (malloc()).

#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff



EXTMEMOPTS =



# Linker flags.

#  -Wl,...:     tell GCC to pass this to linker.

#    -Map:      create map file

#    --cref:    add cross reference to  map file

LDFLAGS = -Wl,-Map=$(TARGET).map,--cref

LDFLAGS += $(EXTMEMOPTS)

LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)









# Programming support using avrdude. Settings and variables.



# Programming hardware: alf avr910 avrisp bascom bsd

# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500

#

# Type: avrdude -c ?

# to get a full listing.

#

AVRDUDE_PROGRAMMER = stk500



# com1 = serial port. Use lpt1 to connect to parallel port.

AVRDUDE_PORT = com1



AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex

#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep





# Uncomment the following if you want avrdude's erase cycle counter.

# Note that this counter needs to be initialized first using -Yn,

# see avrdude manual.

#AVRDUDE_ERASE_COUNTER = -y



# Uncomment the following if you do /not/ wish a verification to be

# performed after programming the device.

#AVRDUDE_NO_VERIFY = -V



# Increase verbosity level.  Please use this when submitting bug

# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>

# to submit bug reports.

#AVRDUDE_VERBOSE = -v -v



AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)

AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)

AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)

AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)







# ---------------------------------------------------------------------------



# Define directories, if needed.

DIRAVR = c:/winavr

DIRAVRBIN = $(DIRAVR)/bin

DIRAVRUTILS = $(DIRAVR)/utils/bin

DIRINC = .

DIRLIB = $(DIRAVR)/avr/lib





# Define programs and commands.

SHELL = sh

CC = avr-gcc

OBJCOPY = avr-objcopy

OBJDUMP = avr-objdump

SIZE = avr-size

NM = avr-nm

AVRDUDE = avrdude

REMOVE = rm -f

COPY = cp









# Define Messages

# English

MSG_ERRORS_NONE = Errors: none

MSG_BEGIN = -------- begin --------

MSG_END = --------  end  --------

MSG_SIZE_BEFORE = Size before:

MSG_SIZE_AFTER = Size after:

MSG_COFF = Converting to AVR COFF:

MSG_EXTENDED_COFF = Converting to AVR Extended COFF:

MSG_FLASH = Creating load file for Flash:

MSG_EEPROM = Creating load file for EEPROM:

MSG_EXTENDED_LISTING = Creating Extended Listing:

MSG_SYMBOL_TABLE = Creating Symbol Table:

MSG_LINKING = Linking:

MSG_COMPILING = Compiling:

MSG_ASSEMBLING = Assembling:

MSG_CLEANING = Cleaning project:









# Define all object files.

OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)



# Define all listing files.

LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)





# Compiler flags to generate dependency files.

GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d





# Combine all necessary flags and optional flags.

# Add target processor to flags.

ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)

ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)











# Default target.

all: begin gccversion sizebefore build sizeafter finished end



build: elf hex eep lss sym extcoff



elf: $(TARGET).elf

hex: $(TARGET).hex

eep: $(TARGET).eep

lss: $(TARGET).lss

sym: $(TARGET).sym







# Eye candy.

# AVR Studio 3.x does not check make's exit code but relies on

# the following magic strings to be generated by the compile job.

begin:

        @echo

        @echo $(MSG_BEGIN)



finished:

        @echo $(MSG_ERRORS_NONE)



end:

        @echo $(MSG_END)

        @echo





# Display size of file.

HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex

ELFSIZE = $(SIZE) -A $(TARGET).elf

sizebefore:

        @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi



sizeafter:

        @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi







# Display compiler version information.

gccversion :

        @$(CC) --version







# Program the device.  

program: $(TARGET).hex $(TARGET).eep

        $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)









# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.

COFFCONVERT=$(OBJCOPY) --debugging \

--change-section-address .data-0x800000 \

--change-section-address .bss-0x800000 \

--change-section-address .noinit-0x800000 \

--change-section-address .eeprom-0x810000





coff: $(TARGET).elf

        @echo

        @echo $(MSG_COFF) $(TARGET).cof

        $(COFFCONVERT) -O coff-avr $< $(TARGET).cof





extcoff: $(TARGET).elf

        @echo

        @echo $(MSG_EXTENDED_COFF) $(TARGET).cof

        $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof







# Create final output files (.hex, .eep) from ELF output file.

%.hex: %.elf

        @echo

        @echo $(MSG_FLASH) $@

        $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@



%.eep: %.elf

        @echo

        @echo $(MSG_EEPROM) $@

        -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \

        --change-section-lma .eeprom=0 -O $(FORMAT) $< $@



# Create extended listing file from ELF output file.

%.lss: %.elf

        @echo

        @echo $(MSG_EXTENDED_LISTING) $@

        $(OBJDUMP) -h -S $< > $@



# Create a symbol table from ELF output file.

%.sym: %.elf

        @echo

        @echo $(MSG_SYMBOL_TABLE) $@

        $(NM) -n $< > $@







# Link: create ELF output file from object files.

.SECONDARY : $(TARGET).elf

.PRECIOUS : $(OBJ)

%.elf: $(OBJ)

        @echo

        @echo $(MSG_LINKING) $@

        $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)





# Compile: create object files from C source files.

%.o : %.c

        @echo

        @echo $(MSG_COMPILING) $<

        $(CC) -c $(ALL_CFLAGS) $< -o $@





# Compile: create assembler files from C source files.

%.s : %.c

        $(CC) -S $(ALL_CFLAGS) $< -o $@





# Assemble: create object files from assembler source files.

%.o : %.S

        @echo

        @echo $(MSG_ASSEMBLING) $<

        $(CC) -c $(ALL_ASFLAGS) $< -o $@







# Target: clean project.

clean: begin clean_list finished end



clean_list :

        @echo

        @echo $(MSG_CLEANING)

        $(REMOVE) $(TARGET).hex

        $(REMOVE) $(TARGET).eep

        $(REMOVE) $(TARGET).obj

        $(REMOVE) $(TARGET).cof

        $(REMOVE) $(TARGET).elf

        $(REMOVE) $(TARGET).map

        $(REMOVE) $(TARGET).obj

        $(REMOVE) $(TARGET).a90

        $(REMOVE) $(TARGET).sym

        $(REMOVE) $(TARGET).lnk

        $(REMOVE) $(TARGET).lss

        $(REMOVE) $(OBJ)

        $(REMOVE) $(LST)

        $(REMOVE) $(SRC:.c=.s)

        $(REMOVE) $(SRC:.c=.d)

        $(REMOVE) .dep/*







# Include the dependency files.

-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)





# Listing of phony targets.

.PHONY : all begin finish end sizebefore sizeafter gccversion \

build elf hex eep lss sym coff extcoff \

clean clean_list program

出0入0汤圆

 楼主| 发表于 2004-12-28 21:53:55 | 显示全部楼层
//music.h

/*                 音阶常数=65536-8000000/8/2/f          */

#define DO        64580        //523

#define RE        64684        //587

#define        MI        64777        //659

#define FA        64820        //698

#define        SO        64898        //784

#define LA        64968        //880

#define        TI        65030        //988                                                       

#define DO_H        65058        //1046

#define RE_H        65110        //1174

#define MI_H        65157        //1318

#define FA_H        65178        //1397

#define SO_H        65217        //1568

#define LA_H        65252        //1760

#define TI_H        65283        //1976

#define DO_HH        65297        //2093

/*                                  位操作宏                                  */

#define set_bit(x,y)        (x|=(1<<y))

#define clr_bit(x,y)        (x&=~(1<<y))

#define get_bit(x,y)        (x&(1<<y))

出0入0汤圆

 楼主| 发表于 2004-12-28 21:54:39 | 显示全部楼层
//music.c



/*******************************************/

/*            广州天河双龙电子公司         */

/*            http://www.sl.com.cn         */

/*              电子音乐演示程序           */

/*            作者:ntzwq@wx88.net          */

/*                2002年5月10日            */

/*   目标MCU:MEGA8   晶振:外部(EXT) 8MHZ   */

/*******************************************/

//使用说明:音乐输出端口:PORTC.0,音乐数据存放

//于ATMEGA8的EEPROM存贮器中,可以使用music.exe

//程序通过RS232通信口进行修改。

//#include <iom8v.h>

//#include <macros.h>

//#include <eeprom.h>

#include <inttypes.h>

#include <avr/io.h>

#include <avr/interrupt.h>

#include <avr/signal.h>

#include <avr/wdt.h>

#include <avr/ina90.h>

#include <avr/eeprom.h>



#include "music.h"





//extern void uart_init(void);

//extern void isp(void);



/*-------------------------------------------------------------------------------*/

#define __noinit__ __attribute__ ((section (".noinit"))) //变量不初始化

#define __eeprom__ __attribute__ ((section (".eeprom"))) //变量定义在eeprom中



#define __flash__  PROGMEM //变量定义在flash中(写法1)

//#define __flash__  __attribute__ ((section (".progmem"))) //变量定义在flash中(写法2)

//#define __flash__  __attribute__ ((progmem)) //变量定义在flash中(写法3)

//prg_uchar等



#define persistent  __noinit__ //变量不初始化,相当于PICC的persistent

#define code  PROGMEM //同__flash__,变量定义在flash中,相当于Keil C51的code

/*-------------------------------------------------------------------------------*/





/*                   音乐数据(卡秒莎)            */

/* 四分之一拍为0x10, 二分之一拍为0x20, 一拍为0x40*/

/* 低1-1 2-2 3-3 4-4 5-5 6-6 7-7 */

/* 中1-8 2-9 3-A 4-B 5-C 6-D 7-E */

/* 高1-F*/                                                                         

//#pragma data:eeprom



/*

const __eeprom__ unsigned char sound[]={//正常节奏

// LA  TI    DO_H LA   DO_H DO_H  TI   LA   TI   MI

  0x66,0x27,0x68,0x26,0x28,0x28,0x27,0x26,0x47,0x43,

// TI  DO_H  RE_H TI   RE_H RE_H DO_H  TI   LA   LA

  0x67,0x28,0x69,0x27,0x29,0x29,0x28,0x27,0x46,0x46,

  0x4a,0x4d,0x4c,0x2d,0x2c,0x2b,0x2b,0x2a,0x29,0x4a,

  0x46,0x20,0x4b,0x29,0x6a,0x28,0x27,0x23,0x28,0x27,

  0x46,0x46,0x4a,0x4d,0x4c,0x2d,0x2c,0x2b,0x2b,0x2a,

  0x29,0x4a,0x46,0x20,0x4b,0x29,0x6a,0x28,0x27,0x23,

  0x28,0x27,0x46,0x46,0x00

};

*/



const __eeprom__ unsigned char sound[]={//全短音

// LA  TI    DO_H LA   DO_H DO_H  TI   LA   TI   MI

  0x26,0x27,0x28,0x26,0x28,0x28,0x27,0x26,0x27,0x23,

// TI  DO_H  RE_H TI   RE_H RE_H DO_H  TI   LA   LA

  0x67,0x28,0x29,0x27,0x29,0x29,0x28,0x27,0x26,0x26,

  0x2a,0x2d,0x2c,0x2d,0x2c,0x2b,0x2b,0x2a,0x29,0x2a,

  0x26,0x20,0x2b,0x29,0x2a,0x28,0x27,0x23,0x28,0x27,

  0x26,0x26,0x2a,0x2d,0x2c,0x2d,0x2c,0x2b,0x2b,0x2a,

  0x29,0x2a,0x26,0x20,0x2b,0x29,0x2a,0x28,0x27,0x23,

  0x28,0x27,0x26,0x26,0x00

};





/*

const __eeprom__ unsigned char sound[]={//全长音

// LA  TI    DO_H LA   DO_H DO_H  TI   LA   TI   MI

  0x66,0x67,0x68,0x66,0x68,0x68,0x67,0x66,0x67,0x63,

// TI  DO_H  RE_H TI   RE_H RE_H DO_H  TI   LA   LA

  0x67,0x68,0x69,0x67,0x69,0x69,0x68,0x67,0x66,0x66,

  0x6a,0x6d,0x6c,0x6d,0x6c,0x6b,0x6b,0x6a,0x69,0x6a,

  0x66,0x60,0x6b,0x69,0x6a,0x68,0x67,0x63,0x68,0x67,

  0x66,0x66,0x6a,0x6d,0x6c,0x6d,0x6c,0x6b,0x6b,0x6a,

  0x69,0x6a,0x66,0x60,0x6b,0x69,0x6a,0x68,0x67,0x63,

  0x68,0x67,0x66,0x66,0x00

};

*/

/*

const __eeprom__ unsigned char sound[]={//全低音

// LA  TI    DO_H LA   DO_H DO_H  TI   LA   TI   MI

  0x66,0x27,0x61,0x26,0x21,0x21,0x27,0x26,0x47,0x43,

// TI  DO_H  RE_H TI   RE_H RE_H DO_H  TI   LA   LA

  0x67,0x21,0x62,0x27,0x22,0x22,0x21,0x27,0x46,0x46,

  0x43,0x46,0x45,0x26,0x25,0x24,0x24,0x23,0x22,0x43,

  0x46,0x20,0x44,0x22,0x63,0x21,0x27,0x23,0x21,0x27,

  0x46,0x46,0x43,0x46,0x45,0x26,0x25,0x24,0x24,0x23,

  0x22,0x41,0x46,0x20,0x44,0x22,0x63,0x21,0x27,0x23,

  0x21,0x27,0x46,0x46,0x00

};

*/



//#pragma data:data                                                                                                                              

/*                              音阶表                                */       

const unsigned int TONETABLE[15]={DO,RE,MI,FA,SO,LA,TI,DO_H,

                                             RE_H,MI_H,FA_H,SO_H,LA_H,TI_H,DO_HH};

/*                          音阶重装常数                        */                                               

unsigned int toneconst;                                                                                                                                                                                                                                 

/*                                微秒级延时程序                          */

void delay_us(int time)

         {     

            do

                  {

                 time--;

                }       

            while (time>1);

         }

/*                              毫秒级延时程序                        */         

void delay_ms(unsigned int time)

         {

          while(time!=0)

                    {               

                   delay_us(1000);

                   time--;

                  }

         }                                       

//#pragma interrupt_handler timer1_ovf_isr:iv_TIMER1_OVF

//void timer1_ovf_isr(void)

SIGNAL(SIG_OVERFLOW1)

         {

          TCNT1=toneconst;

//          PORTC^=1;

          PORTC^=(1 << PC0);//PC0翻转产生发声频率

         }                  

void music(void)

         {

          unsigned char temp,temp1;

          unsigned int sound_add=0;

          TCCR1A = 0x00;

          TCCR1B =(1<<CS11);//8分频

//          temp1=EEPROMread((int)&sound[sound_add]);

//      temp1 = eeprom_read_byte(sound[sound_add]);

      temp1 = eeprom_read_byte(sound + sound_add);

          while(temp1!=0)//0为音乐结尾符

                          {

                        temp=temp1;

                        temp&=0x0f;//取低四位选择音调频率

                        if(temp!=0)

                          {

                           TIMSK|=(1<<TOIE1);//根据SOUNDTABLE中数据的低四位选择音调频率

                           temp--;                          

                   toneconst=TONETABLE[temp];//取选择音调频率

                           TCNT1=toneconst;//发声定时开始

                          }

                        temp=temp1;

                        temp>>=4;//取高四位

//                        temp&=0x0f;//废话!!!

//                        delay_ms(temp*129);//根据SOUNDTABLE中数据的高四位*5后,为音调持续时间(等待)

                        delay_ms(temp*138);//根据SOUNDTABLE中数据的高四位*5后,为音调持续时间(等待138mS较好些)

                        TIMSK&=~(1<<TOIE1);//发声结束

                        sound_add++;//乐谱音符指针+1

//                        temp1=EEPROMread((int)&sound[sound_add]);

//            temp1 = eeprom_read_byte(sound[sound_add]);

            temp1 = eeprom_read_byte(sound + sound_add);//取一个音符或结尾符

                        }

                delay_ms(1000);                                                        

         }                                    

/*                                      主程序                                      */          

void main(void)

         {

          DDRC=0x01;

          PORTC=0xff;

//          uart_init();

          sei();

          while(1)

                   {

             music();

            }

         }
头像被屏蔽

出0入0汤圆

发表于 2004-12-28 21:56:42 | 显示全部楼层
呵呵,不错啊!

出0入0汤圆

 楼主| 发表于 2004-12-28 21:59:54 | 显示全部楼层
请大家注意:



1.makefile中的-ffreestanding



这样可以用

void main(void)

{

//.......................

}



2.菜鸟的心得

/*-------------------------------------------------------------------------------*/

#define __noinit__ __attribute__ ((section (".noinit"))) //变量不初始化

#define __eeprom__ __attribute__ ((section (".eeprom"))) //变量定义在eeprom中



#define __flash__  PROGMEM //变量定义在flash中(写法1)

//#define __flash__  __attribute__ ((section (".progmem"))) //变量定义在flash中(写法2)

//#define __flash__  __attribute__ ((progmem)) //变量定义在flash中(写法3)

//prg_uchar等



#define persistent  __noinit__ //变量不初始化,相当于PICC的persistent

#define code  PROGMEM //同__flash__,变量定义在flash中,相当于Keil C51的code

/*-------------------------------------------------------------------------------*/

出0入0汤圆

发表于 2006-9-18 17:22:03 | 显示全部楼层
不错。我也来听听

出0入0汤圆

发表于 2006-9-18 18:04:09 | 显示全部楼层
#include <avr/io.h>

#include <avr/delay.h>

#include <avr/signal.h>

#include <avr/interrupt.h>

#include <avr/wdt.h>





#define TEMPO        8

#define _1                 TEMPO*4

#define _1d                TEMPO*6

#define _2                 TEMPO*2

#define _2d                TEMPO*3

#define _4                 TEMPO*1

#define _4d          TEMPO*3/2

#define _8                TEMPO*1/2

#define _8d                TEMPO*3/4

#define _16                TEMPO*1/4

#define _16d        TEMPO*3/8

#define _32                TEMPO*1/8





//低音

#define                _1DO        262

#define                _1RE        294

#define                _1MI        330

#define                _1FA        349

#define                _1SO        392

#define                _1LA        440

#define                _1TI        494



//中音

#define                _DO                523

#define                _RE                587

#define                _MI                659

#define                _FA                698

#define                _SO                784

#define                _LA                880

#define                _TI                988



//高音

#define                _DO1        1047

#define                _RE1        1175

#define                _MI1        1319

#define                _FA1        1397

#define                _SO1        1568

#define                _LA1        1760

#define                _TI1        1976





volatile long int HCMM[]=

{

       

        _LA,_SO,_MI,_LA,_SO,_MI,

        _LA,_LA,_SO,_LA,

        _LA,_SO,_MI,_LA,_SO,_MI,

        _RE,_RE,_DO,_RE,

        _MI,_MI,_SO,_LA,_DO1,_LA,_SO,

        _MI,_MI,_SO,_DO,

        _MI,_MI,_MI,_MI,_MI,

        _1LA,_1LA,_1SO,_1LA,       

       

};



volatile unsigned char HCMM_L[]=

{



        _4,_8,_8,_4,_8,_8,

        _8,_4,_8,_2,

        _4,_8,_8,_4,_8,_8,

        _8,_4,_8,_2,

        _4,_8,_8,_8,_8,_8,_8,

        _8,_4,_8,_2,

        _4,_4,_4,_8,_8,

        _8,_4,_8,_2,



};







void mdelay(unsigned char dly)

{

        for(;dly>0;dly--)

        {

                _delay_ms(125);

                _delay_ms(125);               

        }

}





main()

{

        unsigned char i;

       

        PORTB = 0XFF;

    DDRB = 0X03;   //OC1A定义为输出

        DDRC = 0XFF;   //低三位为输入

        PORTC = 0xFF;       

        PORTD = 0XFF;

        DDRD = 0X02;

       

       

        TCCR1A &= ~((1 << COM1A1) | (1 << COM1A0));

        TCCR1A |= 1 << COM1A0;

       

        TCCR1A &= ~((1 << WGM11) | (1 << WGM10));

        TCCR1B &= ~((1 << WGM13) | (1 << WGM12));

       

        TCCR1B |= 1 << WGM12;

       

        TCCR1B &= ~((1 << CS12) | (1 << CS11) | (1 << CS10));

        TCCR1B |= 1 << CS10;  //1分频

        sei();   //开总中断

       



        while(1)

        {

                i= 0;               

                for(i = 0; i < sizeof(HCMM_L); i++)

                {

                        OCR1A= 8000000/HCMM;

                        mdelay(HCMM_L);

                }

               

               

               

        }

}

出0入0汤圆

发表于 2006-9-18 18:05:37 | 显示全部楼层
MAKE FILE文件参数为:



MCU = atmega8

F_CPU = 8000000



听听吧,虹彩妹妹

出0入0汤圆

发表于 2006-9-18 18:06:45 | 显示全部楼层
不过现在不知道怎么把简谱转换成标准格式?

出0入0汤圆

发表于 2006-10-27 18:41:55 | 显示全部楼层
music.c文件中



"#include <avr/ina90.h> "这句话编译的时候通不过.



请问,为什么?

出0入0汤圆

发表于 2006-10-28 12:47:04 | 显示全部楼层
xwyjianghu的程序是好使的;



如果将楼主的上面那条语句除去,还是不好使。



请楼主帮忙回答!

出0入0汤圆

发表于 2006-12-18 15:05:07 | 显示全部楼层
音乐这么复杂

出0入0汤圆

发表于 2006-12-20 11:08:41 | 显示全部楼层

出0入0汤圆

 楼主| 发表于 2006-12-22 20:04:24 | 显示全部楼层
这是用旧版本做的,新版本应该为:

//#include <avr/ina90.h>

#include <compat/ina90.h>

出0入0汤圆

发表于 2006-12-27 12:35:23 | 显示全部楼层
把酷帖顶起!把酷帖顶齐!

出0入0汤圆

发表于 2007-3-8 11:22:35 | 显示全部楼层
音乐程序!直接就可以下载到AVR内,就可以听到了吗?不用别的辅助硬件



我是新手!  



请大家多多指点!



谢谢!



我的邮箱sdq-2008@163.com

出0入0汤圆

发表于 2007-3-18 16:28:06 | 显示全部楼层
sundaqing  需要蜂鸣器及相关驱动,如果直接就能听到,那还不神了。



hotpower 菜农

可不可以把ICC的程序找一下。我到SL的网站查了没有看到。

出0入0汤圆

发表于 2007-7-3 10:55:45 | 显示全部楼层
还是很晕~

出0入0汤圆

发表于 2008-2-26 17:49:56 | 显示全部楼层
Makes the compiler generate code that takes the given amount of cycles to perform, that is it inserts a time delay that lasts the specified number of cycles.

出0入0汤圆

发表于 2008-2-26 17:57:12 | 显示全部楼层
感觉很难读懂程序..

出0入0汤圆

发表于 2008-4-19 23:58:10 | 显示全部楼层
请问有没有用GCC环境编辑的!
谢谢!

出0入0汤圆

发表于 2008-4-20 00:40:29 | 显示全部楼层
本不想多说的,只是看到这个帖子是"酷"贴,还是忍不住了.

这种放音乐的东西不实用,甚至是"害"人的.51也就算了,AVR这样做容易使学习者走到弯路上.

下载我的电子书第8章看看偶的放音乐例程,比较一下吧.

/*****************************************************
File name           : demo_8_7.c
Chip type           : ATmega16L
Program type        : Application
Clock frequency     : 1.000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/
#include <mega16.h>

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;
        }
    }         
}

// Declare your global variables here

void main(void)
{
    PORTD=0x08;
    DDRD=0x20;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: CTC top=OCR1A
// OC1A output: Toggle
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: Off
TCCR1A=0x40;
TCCR1B=0x08;
TCNT1 = 0x00;
ICR1H = 0x00;
ICR1L = 0x00;
OCR1A = 0x00;
OCR1B = 0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x10;

// External Interrupt(s) initialization
// INT0: Off
// INT1: On
// INT1 Mode: Falling Edge
// INT2: Off
GICR|=0x80;
MCUCR=0x08;
MCUCSR=0x00;
GIFR=0x80;

// Global enable interrupts
#asm("sei")

    while (1)
    {
    }
}

出0入0汤圆

发表于 2008-5-13 15:45:13 | 显示全部楼层

出0入0汤圆

发表于 2008-8-16 16:35:34 | 显示全部楼层
mark

出0入0汤圆

发表于 2009-9-14 09:40:29 | 显示全部楼层
有道理

出0入0汤圆

发表于 2009-10-28 08:39:29 | 显示全部楼层
mark

出0入0汤圆

发表于 2010-2-24 20:59:34 | 显示全部楼层
呵呵!!!

出0入0汤圆

发表于 2010-5-6 11:45:56 | 显示全部楼层
新人  顶一个

出0入0汤圆

发表于 2010-9-11 20:55:01 | 显示全部楼层
我狂顶

出0入0汤圆

发表于 2010-9-26 22:37:45 | 显示全部楼层

出0入0汤圆

发表于 2011-10-9 16:19:22 | 显示全部楼层
MARK
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-11 15:34

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表