게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
아트메가128 노래만드는것좀 도와주세요
게시물ID : computer_234878짧은주소 복사하기
작성자 : NackNack
추천 : 0
조회수 : 3218회
댓글수 : 7개
등록시간 : 2015/04/08 21:00:18
옵션
  • 본인삭제금지
ㅠㅠ 과제로 아트메가128하는데 능력자분들의

도움이 필요합니다

노래를 만들래서 짜보고있는데

한음이 일정하게 나오지 않고 음이 높아집니다

Ex) 미 솔 을  차례대로 입력하면 미이이이이이↑

하고 비행기 활강하는소리처럼 쭉 올라갑니다

원래계획대로라면 미이이이→  하고 일자로

나야하는데 말이죠ㅜㅜ

도움줌 부탁드려봅니다

#include <avr/io.h>
#include <stdint.h>  
#define F_CPU 16000000UL 
#define __DELAY_BACKWARD_COMPATIBLE__  #include <util/delay.h>  
#define HALF_CYC 500000UL 
#define P0 0x01 
 #define P1 0x04 
 #define do1 65 
 #define do2 131
 #define do3 262
 #define do4 523
 #define re1 73 
 #define re2 147 
 #define re3 294  
#define re4 587
 #define mi1 82
 #define mi2 165 
 #define mi3 330
 #define mi4 659 
#define pa1 87 
 #define pa2 175 
 #define pa3 349 
 #define pa4 698 
#define sol1 98 
 #define sol2 196 
 #define sol3 392
 #define sol4 784 
#define ra1 110 
 #define ra2 220 
 #define ra3 440 
 #define ra4 880
 #define si1 123
 #define si2 247 
 #define si3 494 
 #define si4 988 

 void tone2(int fr, int duration)
 { 
uint32_t t_tot=HALF_CYC/fr;  
int t_ms=t_tot/1000, t_us=t_tot % 1000, i; 

 for (i=0; i<duration; i++)  

PORTB = PORTB | P1;
 _delay_ms(t_ms);
 _delay_us(t_us);
 PORTB = PORTB & ~P1;  
_delay_ms(t_ms); 
 _delay_us(t_us);
 } 
}

 int main() 
 { 
int melody[]= {mi3, mi3, mi3, do3, mi3, sol3, mi3}; 

  int dura[]= {1000, 1000,1000, 1000, 500, 500, 500}; 

 double pause[] = {1000, 500, 500, 1000,1000,1000, 500};
 DDRB = P1; 

 while(1)
 {  
if ((PINB & P0)== 0)

for(int j=0; j<6; j++) 
{
 tone2(melody[j], dura[j]);
 _delay_ms(pause[j]); 

 } 
 } 


입니다ㅠㅜ 
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호