BASIC4MCU | 질문게시판 | 함수들을 합치는방법 질문드려요
페이지 정보
작성자 마프 작성일2019-05-23 11:25 조회3,238회 댓글0건본문
/* 난수발생 코드
* GccApplication15.c
*
* Created: 2019-05-16 오후 12:36:05
* Author : admin
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 16000000UL
#include <util/delay.h>
unsigned char digit[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7c, 0x07, 0x7f, 0x67};
unsigned char fnd_sel[4] = {0x01, 0x02, 0x04, 0x08};
volatile int sw1 = 0;
ISR(INT4_vect)
{
sw1++;
_delay_ms(10);
}
void display_fnd(int sw1)
{
int i, fnd[4];
if(sw1 == 0)
{fnd[3] = 0;
fnd[2] = 0;
fnd[1] = 0;
fnd[0] = 0;}
else if (sw1 == 1)
{fnd[3] = 0;
fnd[2] = 0;
fnd[1] = 0;
fnd[0] = rand()%10;}
else if (sw1 == 2)
{fnd[3] = 0;
fnd[2] = 0;
fnd[1] = rand()%10;
fnd[0] = fnd[0];}
else if (sw1 == 3)
{fnd[3] = 0;
fnd[2] = rand()%10;
fnd[1] = fnd[1];
fnd[0] = fnd[0];}
else if (sw1 == 4)
{fnd[3] = rand()%10;
fnd[2] = fnd[2];
fnd[1] = fnd[1];
fnd[0] = fnd[0];}
for (i=0; i<4; i++)
{
PORTC = digit[fnd[i]];
PORTG = fnd_sel[i];
_delay_ms(2);
}
}
int main(void)
{
DDRC = 0xff;
DDRG = 0x0f;
DDRE = 0xef;
EICRB = 0x02;
EIMSK = 0x10;
sei();
while (1)
{
display_fnd(sw1);
}
}
노래 함수
#define F_CPU 16000000UL // 16 MHz
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
//
#define DO 0
#define RE 1
#define MI 2
#define FA 3
#define SOL 4
#define RA 5
#define SI 6
#define DDO 7
#define HI 8
#define HI2 9
#define EOS -1 // End Of Song 표시
#define ON 0
#define OFF 1
volatile char f_table[10]={17,43,66,77,97,114,117,137,253,254}; //각 음계
int song1[]={DDO,HI,DDO,HI,DDO,HI,DDO,HI,DDO,HI,EOS}; //당첨 노래
volatile int tone, state;
ISR(TIMER0_OVF_vect)
{
if(state == ON)
{
PORTB = 0x00;
state = OFF;
}
else
{
PORTB = 0x10;
state = ON;
}
TCNT0 = f_table[tone];
}
//
int main()
{
int i=0;
DDRB = 0x10;
TCCR0 = 0x03; //32분주
TIMSK = 0x01; // 오버플로
TCNT0 = f_table[song1[i]];
sei();
do
{
tone = song1[i++];
_delay_ms(100);
} while (tone != EOS);
}
이거 두개가 각각은 실행이 되는데 두개를 합칠수가 없어요.
댓글 0
조회수 3,238등록된 댓글이 없습니다.