BASIC4MCU | 질문게시판 | Atmega128과 도트매트릭스을 이용해 16x16미로찾기
페이지 정보
작성자 JJEE 작성일2023-05-26 17:28 조회1,816회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=22713
본문
조이스틱으로 움직이게 하는 미로찾기를
만들고 싶어요 혹시 도움을 좀 주실수 있을까요? 이 코딩을 하면 16x16에서 오른쪽 절반만 나와요...
#include <mega128.h>
#include <delay.h>
#include <stdio.h>
#define RED PORTC.0
#define GREEN PORTC.1
#define ENABLE PORTC.2
#define LATCH PORTC.3
#define CLOCK PORTA.3
#define X_ST 512
#define Y_ST 512
#define DXY 200
int dot_i=0;
unsigned int dot_gval[16];
unsigned int dot_rval[16];
int gx=0, gy=0;
flash char stage[16]={0x209F, 0xEA91, 0xA97, 0xEA97, 0x2AF4, 0x2A04, 0x2BF4, 0x2894, 0x2094, 0x3E97, 0x291, 0xFE9F, 0x8000, 0xBFFF, 0x8000, 0xFFFF};
void up_move(void);
void down_move(void);
void left_move(void);
void right_move(void);
void main(void)
{
int i, joy_x=0, joy_y=0;
DDRA=0xFF;
DDRC=0xFF;
PORTC=0b00001000;
TIMSK=0x01;
ASSR=0x00;
TCCR0=0x04;
TCNT0=0x00;
SREG=0x80;
for(i=0;i<16;i++)dot_rval[i]=stage[i]<<0;
dot_gval[gy]=1<<(15-gx);
ADCSRA=0x87;
while (1)
{
ADMUX=0x0;
ADCSRA=ADCSRA | 0x40;
while((ADCSRA & 0x10)==0);
joy_x=ADCW;
ADMUX=0x01;
ADCSRA=ADCSRA | 0x40;
while((ADCSRA & 0x10)==0);
joy_y=ADCW;
if((joy_x-X_ST)>DXY)up_move();
else if((X_ST-joy_x)>DXY)down_move();
if((joy_y-Y_ST)>DXY)right_move();
else if((Y_ST-joy_y)>DXY)left_move();
delay_ms(200);
}
}
void up_move(void)
{
int tmp;
if(gy>0){
tmp=dot_gval[gy];
dot_gval[gy]=0;
gy--;
dot_gval[gy]=tmp;
}
}
void down_move(void)
{
int tmp;
if(gy<15){
tmp=dot_gval[gy];
dot_gval[gy]=0;
gy++;
dot_gval[gy]=tmp;
}
}
void left_move(void)
{
if(gx>0){
gx--;
dot_gval[gy]<<=1;
}
}
void right_move(void)
{
if(gx<15){
gx++;
dot_gval[gy]>>=1;
}
}
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
int di;
for(di=0;di<16;di++){
if(((dot_rval[dot_i]<<di) & 0x8000)!=0) RED=1;
else RED=0;
if(((dot_gval[dot_i]<<di) & 0x8000)!=0) GREEN=1;
else GREEN=0;
CLOCK=1;
delay_us(1);
CLOCK=0;
delay_us(1);
}
ENABLE=1;
LATCH=0;
delay_us(2);
LATCH=1;
PORTC=(PORTC & 0b00001111) | (dot_i<<4);
delay_us(2);
ENABLE=0;
dot_i=(dot_i+1)%16;
}
댓글 0
조회수 1,816등록된 댓글이 없습니다.