BASIC4MCU | 질문게시판 | Atmega128 큐함수에 질문있습니다.
페이지 정보
작성자 kosmosi 작성일2021-12-05 01:52 조회1,004회 댓글1건첨부파일
본문
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdlib.h>
#include <stdio.h>
#define QUEUE_SIZE 32
//전역 변수 선언입니다.
volatile int state, tone;
char f_table[8] = { 17, 43, 66, 77, 97, 114, 117, 137 };
int i, j;
int front = 0; // 삭제 위치
int rear = 0; // 추가 위치
int i, j;
int Full();
int Empty();
void EnQueue(int value, int asdf, int* _queue); // Queue 에 데이터 추가하는 함수
void QueueData(int* _queue); // Queue 의 데이터 출력하는 함수
void QueueData(int* _queue) {
for (int i = front; i != rear; i = ++i % QUEUE_SIZE) {
_queue[i];
}
}
void EnQueue(int value, int asdf, int* _queue) {
int a = 0;
for (int g = 0; g < rear; g++) {
a = a + value;
value = a;
_queue[rear] = value;
_queue[rear] = asdf;
}
rear = ++rear % QUEUE_SIZE;// 순서에 따라서 데이터 추가
}
int Empty() {
return front == rear;
}
int Full() {
return (rear + 1) % QUEUE_SIZE == front;
}
int main()
{
int* queue = (int*)malloc(sizeof(int) * QUEUE_SIZE); //동적 할당
int PORTGT;
//7-segment
DDRC = 0XFF;
DDRG = 0X0F;
while (1) {
if ((PINE & 0x10) == 0x00 && (PINE & 0x20) == 0x00) {
for (i = 0; i < 8; i++) {
int j[2] = { 0x10,0x20 };
int k = rand() % 2;
PORTG = 0x10;
PORTC = j[k];
if (PORTC == 0x10) {
for (int b = 0; b < 4; b++) {
PORTG = PORTG >> 1;
PORTC = 0x10;
PORTG = PORTG + PORTGT;
EnQueue(PORTG, PORTC, queue);
QueueData(queue);
_delay_ms(300);
PORTG;
PORTG = PORTG + PORTGT;
PORTC = 0x04;
EnQueue(PORTG, PORTC, queue);
QueueData(queue);
_delay_ms(300);
}
}
if (PORTC == 0x20) {
for (int b = 0; b < 4; b++) {
PORTG = PORTG >> 1;
PORTC = 0x20;
PORTG = PORTG + PORTGT;
EnQueue(PORTG, PORTC, queue);
QueueData(queue);
_delay_ms(300);
PORTG = PORTG + PORTGT;
PORTG;
PORTC = 0x02;
EnQueue(PORTG, PORTC, queue);
QueueData(queue);
_delay_ms(300);
}
}
}
}
}
}
/*코드 내용은리듬게임처럼 되도록 PORTG=0x08자리에서 PORTC를 0x10또는 0x20으로 뽑아서 PORTC=0x10일때 PORTC=0x04자리로 내려오고, PORTC=0x20일때 PORTC=0x01자리로 내려오고이 반복작업을 PORTG=0x01자리까지 저장되면서 뽑으려고 큐함수를 사용했는데 안되는데요 제가 코드 작성을 잘못한 것일까요? 아니면 큐함수 말고 다른방법을 찾아야하나요?*/
댓글 1
조회수 1,004master님의 댓글
master 작성일게임 내용이 이해가 안됩니다.