질문게시판 > 답변 : AVR하고 있는데 에러 좀 잡아주세요ㅜㅜ 도저히 모르겠어요..

TODAY1,213 TOTAL2,163,054
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 질문게시판 | 답변 : AVR하고 있는데 에러 좀 잡아주세요ㅜㅜ 도저히 모르겠어요..

페이지 정보

작성자 master 작성일2019-11-14 17:32 조회3,583회 댓글0건

본문

	

 

// DateTime : 2019-11-14 오후 5:29:19
// by Ok-Hyun Park
//
#include <avr/io.h>
#include <avr/delay.h>
#include <stdlib.h>
#include <stdio.h>
//
#define RED_ON     PORTA.0=1;
#define RED_OFF    PORTA.0=0;
#define GREEN_ON   PORTA.1=1;
#define GREEN_OFF  PORTA.1=0;
#define ENABLE_ON  PORTA.2=1;
#define ENABLE_OFF PORTA.2=0;
#define LATCH_ON   PORTA.3=1;
#define LATCH_OFF  PORTA.3=0;
#define CLOCK_ON   PORTA.4=1;
#define CLOCK_OFF  PORTA.4=0;
//
#define A3        PORTC.7;
#define A2        PORTC.6;
#define A1        PORTC.5;
#define A0        PORTC.4;
//
#define FUNCSET   0x28
#define ENTMODE   0x06
#define ALLCLR    0x01
#define DISPON    0x0c
#define HOME      0x02
#define LINE2     0xC0
#define DISPOFF   0x08
//
unsigned long FONT_O1[]={0xBA4C,0xAF10,0xBA1C,0xA204,0xFB18,0x0000,0x3BFA,0x4B6F,0x3F6A,0x1B6A,0x6BFB,0x0757,0x0555,0x0755,0x0155,0x0775    }; //Let's shoot gun
unsigned long FONT_O2[]={0x0000,0x8EE8,0x8840,0x8840,0x8840,0x8840,0x8847,0x8E48,0x8844,0x8842,0x8841,0x8841,0x8842,0xEE4C,0x0000,0x0000}; ///LET's
unsigned long FONT_O3[]={0x0000,0x6A67,0x8A92,0x8A92,0x8A92,0x8A92,0x4A92,0x2E92,0x2A92,0x2A92,0x2A92,0x2A92,0x2A92,0xC962,0x0000,0x0000}; //SHOT
unsigned long FONT_O4[]={0x0000,0x722F,0x8229,0x8229,0x8229,0x8229,0x8229,0xBA29,0x9229,0x9229,0x9229,0x9229,0x71C9,0x0000,0x0000,0x0000}; //GUN
unsigned long FONT_O5[]={0x8001,0x5FFA,0x300C,0x2004,0x2C34,0x2C34,0x2004,0x2184,0x2184,0x2004,0x1008,0x2FF4,0x4A52,0x8A51,0x0A50,0x0FF0}; //해골
unsigned long FONT_O6[]={0x6257,0x8575,0x8557,0xF754,0xA554,0x6557,0x0000,0x0000,0x6577,0x9555,0x9575,0x9547,0x9546,0x9545,0x6275,0x0000};
unsigned long pt[]={0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0100,0x0000,0x0000,0x00000,0x00000,0x0000,0x0000,0x0000,0x0000}; //조준점
unsigned long enemy[]={0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0100,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
unsigned long enemy1[]={0x1000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
unsigned long rdd[]={0x0040,0x4000,0x2000,0x1000,0x0800,0x0400,0x0200,0x0100,0x0080,0x0040,0x0020,0x0010,0x0008,0x0004,0x0002,0x0100};
unsigned long rdd1[]={0x0040,0x4000,0x2000,0x1000,0x0800,0x0400,0x0200,0x0100,0x0080,0x0040,0x0020,0x0010,0x0008,0x0004,0x0002,0x0100};
unsigned long font//폰트 저장
unsigned char sel,sel1,N,a,b,c,d,kill,ol_kill,ol_life,cnt;
unsigned char life=5;
unsigned char addr1=0;
unsigned char pos_y=7,pos_x=7;
unsigned char pos1_y=7,pos1_x=7;
unsigned char pos2_y,pos2_x;
unsigned int p,rd,rd1,pp;
unsigned char ene1,ene2;
unsigned int ad_val1,ad_val2// AD 변환값.
//
void control(void);
void enemy_screen(void);
void enemy_screen2(void);
void LCD_init(void);
void LCD_String(char*);
void Busy(void);
void Command(unsigned char);
void Data(unsigned char);
void LCD_screen1(void);
// 상,하,좌,우 컨트롤(가속도 센서)
void control(void){
  if(sel==1){
    ad_val2=ad_val2&0b1111111111;
    if((ad_val2&0b1111111111)<610){ //610 0b1001100010
      if(++a==100){ a=0;
        pt[pos_y]=pt[pos_y]>>1;
        if(pos_x==15){ pt[pos_y]=0x0001; }
        else pos_x++;
        delay_ms(2);
        if((pt[pos_y]&0xFFFF)==0x0000)pt[pos_y]=0x8000;
      }
    }
    else if((ad_val2&0b1111111111)>780){ //0b1010111100
      if(++b==100){ b=0;
        pt[pos_y]=pt[pos_y]<<1;
        if(pos_x==0)pt[pos_y]=0x8000;
        else pos_x--;
        delay_ms(2);
        if((pt[pos_y]&0xFFFF)==0x0000)pt[pos_y]=0x0001;
      }
    }
    if(ad_val1<635){
      if(++c==100){ c=0;
        if(pos_y==15){ pos_y=15pt[15]=pt[15]; }
        elsept[pos_y+1]=pt[pos_y]; pt[pos_y]=0pos_y++; }
      }
    }
    if(ad_val1>730){
      if(++d==100){ d=0;
        if(pos_y==0){ pos_y=0pt[0]=pt[0]; }
        elsept[pos_y-1]=pt[pos_y]; pt[pos_y]=0pos_y--; }
      }
    }
  }
  else if(sel==0)pt[pos_y]=0x0100;
}
// 랜덤 적 출현
void enemy_screen(void){
  if(sel==1){
    p=rdd[pos1_x];
    if(p&0x4000){ p=p&0x4000enemy[pos1_y]=penemy[pos1_y+1]=0xE000enemy[pos1_y+2]=0x4000enemy[pos1_y+3]=0xA000; }
    else if(p&0x2000){ p=p&0x2000enemy[pos1_y]=penemy[pos1_y+1]=0x7000enemy[pos1_y+2]=0x2000enemy[pos1_y+3]=0x5000; }
    else if(p&0x1000){ p=p&0x1000enemy[pos1_y]=penemy[pos1_y+1]=0x3800enemy[pos1_y+2]=0x1000enemy[pos1_y+3]=0x2800; }
    else if(p&0x0800){ p=p&0x0800enemy[pos1_y]=penemy[pos1_y+1]=0x1C00enemy[pos1_y+2]=0x0800enemy[pos1_y+3]=0x1400; }
    else if(p&0x0400){ p=p&0x0400enemy[pos1_y]=penemy[pos1_y+1]=0x0E00enemy[pos1_y+2]=0x0400enemy[pos1_y+3]=0x0A00; }
    else if(p&0x0200){ p=p&0x0200enemy[pos1_y]=penemy[pos1_y+1]=0x0700enemy[pos1_y+2]=0x0200enemy[pos1_y+3]=0x0500; }
    else if(p&0x0100){ p=p&0x0100enemy[pos1_y]=penemy[pos1_y+1]=0x0380enemy[pos1_y+2]=0x0100enemy[pos1_y+3]=0x0280; }
    else if(p&0x0080){ p=p&0x0080enemy[pos1_y]=penemy[pos1_y+1]=0x01C0enemy[pos1_y+2]=0x0080enemy[pos1_y+3]=0x0140; }
    else if(p&0x0040){ p=p&0x0040enemy[pos1_y]=penemy[pos1_y+1]=0x00E0enemy[pos1_y+2]=0x0040enemy[pos1_y+3]=0x00A0; }
    else if(p&0x0020){ p=p&0x0020enemy[pos1_y]=penemy[pos1_y+1]=0x0070enemy[pos1_y+2]=0x0020enemy[pos1_y+3]=0x0050; }
    else if(p&0x0010){ p=p&0x0010enemy[pos1_y]=penemy[pos1_y+1]=0x0038enemy[pos1_y+2]=0x0010enemy[pos1_y+3]=0x0028; }
    else if(p&0x0008){ p=p&0x0008enemy[pos1_y]=penemy[pos1_y+1]=0x001Cenemy[pos1_y+2]=0x0008enemy[pos1_y+3]=0x0014; }
    else if(p&0x0004){ p=p&0x0004enemy[pos1_y]=penemy[pos1_y+1]=0x000Eenemy[pos1_y+2]=0x0004enemy[pos1_y+3]=0x000A; }
    else if(p&0x0002){ p=p&0x0002enemy[pos1_y]=penemy[pos1_y+1]=0x0007enemy[pos1_y+2]=0x0002enemy[pos1_y+3]=0x0005; }
  }
}
// 랜덤 적 출현
void enemy_screen2(void){
  if(sel==1){
    pp=rdd1[pos2_x];
    if(pp&0x4000){ pp=pp&0x4000enemy1[pos2_y]=ppenemy1[pos2_y+1]=0xE000enemy1[pos2_y+2]=0x4000enemy1[pos2_y+3]=0xA000; }
    else if(pp&0x2000){ pp=pp&0x2000enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x7000enemy1[pos2_y+2]=0x2000enemy1[pos2_y+3]=0x5000; }
    else if(pp&0x1000){ pp=pp&0x1000enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x3800enemy1[pos2_y+2]=0x1000enemy1[pos2_y+3]=0x2800; }
    else if(pp&0x0800){ pp=pp&0x0800enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x1C00enemy1[pos2_y+2]=0x0800enemy1[pos2_y+3]=0x1400; }
    else if(pp&0x0400){ pp=pp&0x0400enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x0E00enemy1[pos2_y+2]=0x0400enemy1[pos2_y+3]=0x0A00; }
    else if(pp&0x0200){ pp=pp&0x0200enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x0700enemy1[pos2_y+2]=0x0200enemy1[pos2_y+3]=0x0500; }
    else if(pp&0x0100){ pp=pp&0x0100enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x0380enemy1[pos2_y+2]=0x0100enemy1[pos2_y+3]=0x0280; }
    else if(pp&0x0080){ pp=pp&0x0080enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x01C0enemy1[pos2_y+2]=0x0080enemy1[pos2_y+3]=0x0140; }
    else if(pp&0x0040){ pp=pp&0x0040enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x00E0enemy1[pos2_y+2]=0x0040enemy1[pos2_y+3]=0x00A0; }
    else if(pp&0x0020){ pp=pp&0x0020enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x0070enemy1[pos2_y+2]=0x0020enemy1[pos2_y+3]=0x0050; }
    else if(pp&0x0010){ pp=pp&0x0010enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x0038enemy1[pos2_y+2]=0x0010enemy1[pos2_y+3]=0x0028; }
    else if(pp&0x0008){ pp=pp&0x0008enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x001Cenemy1[pos2_y+2]=0x0008enemy1[pos2_y+3]=0x0014; }
    else if(pp&0x0004){ pp=pp&0x0004enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x000Eenemy1[pos2_y+2]=0x0004enemy1[pos2_y+3]=0x000A; }
    else if(pp&0x0002){ pp=pp&0x0002enemy1[pos2_y]=ppenemy1[pos2_y+1]=0x0007enemy1[pos2_y+2]=0x0002enemy1[pos2_y+3]=0x0005; }
  }
}
//
void LCD_init(void){
  DDRB=0xFFPORTB&=0xFBdelay_ms(15);
  Command(0x20); delay_ms(5); Command(0x20); delay_us(100); Command(0x20);
  Command(FUNCSET); Command(DISPON); Command(ALLCLR); Command(ENTMODE);
}
//
void LCD_String(char*str){ unsigned char*pStr=0pStr=strwhile(*pStr)Data(*pStr++); }
//
void Command(unsigned char byte){
  Busy();
  PORTB=(byte&0xF0); PORTB&=0xFEPORTB&=0xFDdelay_us(1); PORTB|=0x04delay_us(1); PORTB&=0xFB;
  PORTB=(byte<<4); PORTB&=0xFEPORTB&=0xFDdelay_us(1); PORTB|=0x04delay_us(1); PORTB&=0xFB;
}
//
void Data(unsigned char byte){
  Busy();
  PORTB=(byte&0xF0); PORTB|=0x01PORTB&=0xFDdelay_us(1); PORTB|=0x04delay_us(1); PORTB&=0xFB;
  PORTB=(byte<<4); PORTB|=0x01PORTB&=0xFDdelay_us(1); PORTB|=0x04delay_us(1); PORTB&=0xFB;
}
//
void Busy(void){ delay_ms(2); }
//
void LCD_screen1(void){
  char temp1[16],temp2[16];
  Command(HOME); sprintf(temp1,"KILL:%03u",kill); LCD_String(temp1);
  Command(LINE2); sprintf(temp2,"LIFE:%03u",life); LCD_String(temp2);
  Command(LINE2);
  if(life==255){
    Command(HOME); LCD_String("game over!!");
    Command(LINE2); LCD_String("                    ");
    Command(LINE2);
  }
}
//
interrupt[EXT_INT4]void shoot(void){
  if(sel==1){
    if(pos_y==pos1_y){
      enemy[pos1_y]=(enemy[pos1_y]&0xFFFF);
      if(pt[pos_y]==enemy[pos1_y]){
        pos1_x=rdsel1=1;
        if(pos1_y==13){ pos1_y=0enemy[0]=enemy[13]; enemy[13]=0enemy[14]=0enemy[15]=0; }
        elseenemy[pos1_y+1]=enemy[pos1_y]; enemy[pos1_y]=0pos1_y++; }
        delay_ms(1); kill++; LCD_screen1(); TCNT1=0xD000if(kill<10)cnt=0ene1=1;
      }
    }
    else if(pos_y==pos1_y+1){
      enemy[pos1_y+1]=(enemy[pos1_y+1]&0xFFFF);
      if((pt[pos_y]|enemy[pos1_y+1])==enemy[pos1_y+1]){
        pos1_x=rdsel1=1;
        if(pos1_y==13){ pos1_y=0enemy[0]=enemy[13]; enemy[13]=0enemy[14]=0enemy[15]=0; }
        elseenemy[pos1_y+1]=enemy[pos1_y]; enemy[pos1_y]=0pos1_y++; }
        delay_ms(1); kill++; LCD_screen1(); TCNT1=0xD000if(kill<10)cnt=0ene1=1;
      }
    }
    else if(pos_y==pos1_y+2){
      enemy[pos1_y+2]=(enemy[pos1_y+2]&0xFFFF);
      if((pt[pos_y]|enemy[pos1_y+2])==enemy[pos1_y+2]){
        pos1_x=rdsel1=1;
        if(pos1_y==13){ pos1_y=0enemy[0]=enemy[13]; enemy[13]=0enemy[14]=0enemy[15]=0; }
        elseenemy[pos1_y+1]=enemy[pos1_y]; enemy[pos1_y]=0pos1_y++; }
        delay_ms(1); kill++; LCD_screen1(); TCNT1=0xD000if(kill<10)cnt=0ene1=1;
      }
    }
    else if(pos_y==pos1_y+3){
      enemy[pos1_y+3]=(enemy[pos1_y+3]&0xFFFF);
      if((pt[pos_y]|enemy[pos1_y+3])==enemy[pos1_y+3]){
        pos1_x=rd;
        sel1=1;
        if(pos1_y==13){ pos1_y=0enemy[0]=enemy[13]; enemy[13]=0enemy[14]=0enemy[15]=0; }
        elseenemy[pos1_y+1]=enemy[pos1_y]; enemy[pos1_y]=0pos1_y++; }
        delay_ms(1); kill++; LCD_screen1(); TCNT1=0xD000if(kill<10)cnt=0ene1=1;
      }
    }
  }
  if(pos_y==pos2_y){
    if(pt[pos_y]==enemy1[pos2_y]){
      pos2_x=rd1sel1=1;
      if(pos2_y==13){ pos2_y=0enemy1[0]=enemy1[13]; enemy1[13]=0enemy1[14]=0enemy1[15]=0; }
      elseenemy1[pos2_y+1]=enemy1[pos2_y]; enemy1[pos2_y]=0pos2_y++; }
      delay_ms(1); kill++; LCD_screen1(); ene2=1;
    }
  }
  else if(pos_y==pos2_y+1){
    if((pt[pos_y]|enemy1[pos2_y+1])==enemy1[pos2_y+1]){
      pos2_x=rd1sel1=1;
      if(pos2_y==13){ pos2_y=0enemy1[0]=enemy1[13]; enemy1[13]=0enemy1[14]=0enemy1[15]=0; }
      elseenemy1[pos2_y+1]=enemy1[pos2_y]; enemy1[pos2_y]=0pos2_y++; }
      delay_ms(1); kill++; LCD_screen1(); ene2=1;
    }
  }
  else if(pos_y==pos2_y+2){
    if((pt[pos_y]|enemy1[pos2_y+2])==enemy1[pos2_y+2]){
      pos2_x=rd1sel1=1;
      if(pos2_y==13){ pos2_y=0enemy1[0]=enemy1[13]; enemy1[13]=0enemy1[14]=0enemy1[15]=0; }
      elseenemy1[pos2_y+1]=enemy1[pos2_y]; enemy1[pos2_y]=0pos2_y++; }
      delay_ms(1); kill++; LCD_screen1(); ene2=1;
    }
  }
  else if(pos_y==pos2_y+3){
    if((pt[pos_y]|enemy1[pos2_y+3])==enemy1[pos2_y+3]){
      pos2_x=rd1sel1=1;
      if(pos2_y==13){ pos2_y=0enemy1[0]=enemy1[13]; enemy1[13]=0enemy1[14]=0enemy1[15]=0; }
      elseenemy1[pos2_y+1]=enemy1[pos2_y]; enemy1[pos2_y]=0pos2_y++; }
      delay_ms(1); kill++; LCD_screen1(); ene2=1;
    }
  }
}
//
interrupt[TIM1_OVF]void hurt(void){
  if(sel==1){
    if(kill<10){ //적이 나를 공격할떄까지 약 7.5초
      if(++cnt==7){ cnt=0sel1=2life--; LCD_screen1(); pos1_x=rdpos2_x=rd1; }
      TCNT1=0xD000;
    }
    else if((kill>=10)&&(kill<15)){ // 적이 나를 공격할떄까지 약 5.5초
      if(++cnt==5){ cnt=0sel1=2life--; LCD_screen1(); pos1_x=rdpos2_x=rd1; }
      TCNT1=0xD000;
    }
    else if((kill>=15)&&(kill<20)){ //적이 나를 공격 할떄까지 약 33.5초
      if(++cnt==3){ cnt=0sel1=2life--; LCD_screen1(); pos1_x=rdpos2_x=rd1; }
      TCNT1=0xD000;
    }
    else if((kill>=20)&&(kill<25)){ //적이 나를 공격 할떄까지 약 33.5초
      if(++cnt==3){ cnt=0sel1=2life--; LCD_screen1(); pos1_x=rdpos2_x=rd1; }
      TCNT1=0xD000;
    }
    else if((kill>=25)&&(kill<30)){ //적이 나를 공격 할떄까지 약 33.5초
      if(++cnt==3){ cnt=0sel1=2life--; LCD_screen1(); pos1_x=rdpos2_x=rd1; }
      TCNT1=0xD000;
    }
    else if((kill>=35)&&(kill<40)){ //적이 나를 공격 할떄까지 약 33.5초
      if(++cnt==2){ cnt=0sel1=2life--; LCD_screen1(); pos1_x=rdpos2_x=rd1; }
      TCNT1=0xD000;
    }
    else if((kill>=40)&&(kill<45)){ //적이 나를 공격 할떄까지 약 33.5초
      if(++cnt==2){ cnt=0sel1=2life--; LCD_screen1(); pos1_x=rdpos2_x=rd1; }
      TCNT1=0xD000;
    }
    else if((kill>=45)&&(kill<50)){ //적이 나를 공격 할떄까지 약 33.5초
      if(++cnt==1){ cnt=0sel1=2life--; LCD_screen1(); pos1_x=rdpos2_x=rd1; }
      TCNT1=0xD000;
    }
  }
}
//
interrupt[EXT_INT6]void start_sw6(void){
  sel=(sel+1)%2;
  if(sel==0){ }
}
//
interrupt[TIM0_OVF]void timer1(void){
  unsigned char k;
  unsigned int tt,ee,j,cc;
  TCNT0=0xEB;
  if(sel==1){
    addr1=(addr1+1)%16;
    if(sel1==0){
      font=pt[addr1]|enemy[addr1];
      if(kill>=10){
        font=pt[addr1]|enemy[addr1]|enemy1[addr1];
        if(ene1==0&&ene2==1){ font=pt[addr1]|enemy[addr1]; }
        else if(ene1==1&&ene2==0){ font=pt[addr1]|enemy1[addr1]; }
        else if(ene1==1&&ene2==1){ font=pt[addr1]|enemy[addr1]|enemy1[addr1]; ene1=0ene2=0cnt=0; }
      }
      ee=enemy[addr1]; cc=enemy1[addr1]; tt=pt[addr1];
    }
    if((sel1==1)|(sel1==2)|sel1==3){
      for(j=0j<7000j++){
        addr1=(addr1+1)%16;
        if(sel1==1){ cnt=0font=FONT_O3[addr1]; }
        else if(sel1==2)font=FONT_O5[addr1];
        for(k=0k<16k++){
          if(font&0x8000){
            if(sel1==1)GREEN_ON;
            else if(sel1==2)RED_ON;
          }
          elseGREEN_OFFRED_OFF; }
          CLOCK_ONdelay_us(1); CLOCK_OFFdelay_us(1); font=font<<1;
        }
        PORTA=(PORTA&0x0B); //0b0000 1001; PORTC=addr1<<4; ENABLE_ON; LATCH_OFF; LATCH_ON; ENABLE_OFF; rd=rand()%16;
      }
      sel1=0;
    }
    if(sel1==0){
      for(k=0k<16k++){
        if(font&0x8000){
          if(tt&0x8000){ GREEN_ON; }
          else GREEN_OFF;
          if(ee&0x8000){ RED_ON; }
          if(cc&0x8000){ RED_ON; }
        }
        elseGREEN_OFFRED_OFF; }
        CLOCK_ONdelay_us(1); CLOCK_OFFdelay_us(1); font=font<<1tt=tt<<1ee=ee<<1cc=cc<<1;
      }
      PORTA=(PORTA&0x0B); //0b0000 1001; PORTC=addr1<<4; ENABLE_ON; LATCH_OFF; LATCH_ON; ENABLE_OFF;
    }
  }
  else{
    for(j=0j<10000j++){
      addr1=(addr1+1)%16;
      if(N==0)font=FONT_O1[addr1];
      else if(N==1)font=FONT_O2[addr1];
      else if(N==2)font=FONT_O3[addr1];
      else font=FONT_O4[addr1];
      if(sel1==3){ font=FONT_O6[addr1]; N=((N+1)%2)+1; }
      for(k=0k<16k++){ //총 16개 LED 쉬프트(각행마다)
        if(font&0x8000){
          RED_ON;
          if(N==2){ GREEN_ONRED_OFF; }
          if(N==0){
            if(5<addr1&&addr1<11){ RED_OFFGREEN_ON; }
          }
        }
        elseRED_OFFGREEN_OFF; }
        CLOCK_ONCLOCK_OFFfont=font<<1// 다음값을 위해 왼쪽으로 쉬프트.
      }
      PORTA=(PORTA&0x0B); //0b0000 1001; PORTC=addr1<<4; ENABLE_ON; LATCH_OFF; LATCH_ON; ENABLE_OFF;
    }
    if(sel==0)N=(N+1)%4;
  }
}
//
void main(void){
  DDRA=0xFF//A포트 출력 // dot matrix 제어
  DDRC=0xFF//C포트 출력 // dot matrix 주소
  DDRF=0x00//F포트 입력 ADC
  DDRB=0xFF//B포트 출력/LCD
  PORTB&=0xFB;
  PORTA=0x00//폰트 출력 및 인에이블 off
  EIMSK=0b01110000// 인트럽트,6,5,4,인에이블  6--시작 스위치 5-숨기 스위치 4-발사 스위치
  EICRB=0b00101010//  인트럽트 4 5 6 하강에지에서 동작
  // 타이머 선언 타이머0 도트 출력,타이머1 적 출현,타이머 3 적이 공격.
  TCCR0=0b00000111TCNT0=0xFFTIMSK=0b00000101;
  TCCR1B=0b00000101TCNT1=0xD000;
  TCCR3B=0b00000101;
  TCNT3H=0xD0;
  ADMUX=0b11000000//단극성 입력
  LCD_init();
  SREG=0x80;
  LCD_screen1();
  while(1){
    if(sel==0){ life=5kill=0; }
    ADMUX=0b11000000ADCSRA=0b11100111delay_us(250); ad_val1=ADCW;
    ADMUX=0b1100000001delay_us(250); ad_val2=ADCW;
    if(ol_kill!=kill)LCD_screen1(); ol_kill=kill;
    if(ol_life!=life)LCD_screen1(); ol_life=life;
    control();
    enemy_screen(); enemy_screen2();
    if(life==255||life==254){ delay_us(10); LCD_screen1(); sel=0sel1=3; }
    if(kill<10)rd=rand()%16// random 함수
    if(kill>=10){ rd=rand()%16rd1=(rand()+108)%16; }
  }
}

 

질문 소스는 코드비젼 소스코드인데

헤더파일만 AVRstudio용으로 교체한 상태입니다.

 

 

#include <avr/io.h>
#include <avr/delay.h>

위 헤더파일을

 

#include <mega128.h>
#include <delay.h>

이렇게 변경하고 코드비젼을 설치해서 컴파일 하세요

 

  • BASIC4MCU 작성글 SNS에 공유하기
  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기

댓글 0

조회수 3,583

등록된 댓글이 없습니다.

질문게시판HOME > 질문게시판 목록

MCU, AVR, 아두이노 등 전자공학에 관련된 질문을 무료회원가입 후 작성해주시면 전문가가 답변해드립니다.
ATMEGA128PWMLED초음파
아두이노AVR블루투스LCD
UART모터적외선ATMEGA
전체 스위치 센서
질문게시판 목록
제목 작성자 작성일 조회
공지 MCU, AVR, 아두이노 등 전자공학에 관련된 질문은 질문게시판에서만 작성 가능합니다. 스태프 19-01-15 9631
공지 사이트 이용 안내댓글[24] master 17-10-29 29644
질문 아두이노 서보모터제어 하나도 모르겠습니다 ㅠ 이미지새글첨부파일 오소로롯 22:01 5
질문 아트메가 128 을 이용해서적외선 센서 코딩 중 물어볼게있습니다!! 새글 noster 19:32 15
질문 아두이노 에러질문댓글[1] 이미지새글첨부파일 리니어 16:09 21
질문 아두이노 블루투스 통신 관련 질문 있습니다!! 새글 블루툿 10:51 23
답변 답변글 답변 : 아두이노 블루투스 통신 관련 질문 있습니다!! 새글 master 11:05 16
질문 아두이노 DRV2605 헵틱 모터 드라이버댓글[1] 새글 gano 08:43 20
질문 아두이노 d1r2 W238 방수 초음파 센서댓글[1] 새글 밤새아두이노 03:24 17
질문 아두이노 블루투스(hc-06)사용중 질문있습니다. 새글첨부파일 띵꽁 22-05-20 24
답변 답변글 답변 : 아두이노 블루투스(hc-06)사용중 질문있습니다. 새글 master 09:52 16
질문 아두이노 블루투스 통신댓글[1] 새글 블루툿 22-05-20 23
질문 ATmega128 진동센서 코딩 질문입니다.댓글[5] 새글 444222a 22-05-20 31
질문 아두이노 초음파센서 코딩 질문댓글[3] 이미지새글첨부파일 아두이노아린이 22-05-20 30
질문 아두이노 스케치 후 pc usb 연결없이 사용한가요?댓글[1] 새글 까치 22-05-20 20
질문 atmega128 서보모터와 초음파센서댓글[5] 새글 tmiae 22-05-20 31
질문 avr compiler 종류 질문입니다!댓글[3] 새글 민준싸 22-05-20 27
질문 컴퓨터 usb연결시 정상 작동하나 9V건전지 외부전원 연결 시 작동하지 않는 문제댓글[3] 이미지첨부파일 보겐을운용 22-05-19 189
질문 아두이노 dac 연결댓글[5] 이미지첨부파일 kodory 22-05-19 29
질문 아두이노 millis ->atmega128에서 사용하고 싶습니다. akmong413 22-05-19 32
답변 답변글 답변 : 아두이노 millis ->atmega128에서 사용하고 싶습니다. master 22-05-19 34
질문 아트메가 모터드라이브와 초음파 센서 연동 질문입니다댓글[1] 123424135123q 22-05-19 43
질문 스텝모터 드라이버 선정 질문드립니다. 아흐흑 22-05-18 39
답변 답변글 답변 : 스텝모터 드라이버 선정 질문드립니다.댓글[1] 이미지 master 22-05-19 38
질문 아두이노로 모터+드라이버 제어댓글[6] 모토 22-05-18 76
질문 온도센서로 서보모터 제어 코딩댓글[1] 진수네1조 22-05-18 68
질문 라즈베리파이 웹캠 데이터 아두이노 전송 (초보)댓글[3] 전자과 22-05-17 62
질문 아두이노 코딩 도와주세요 (초음파센서와 금속감지센서로 서보모터 제어하기) 이현주 22-05-17 89
답변 답변글 답변 : 아두이노 코딩 도와주세요 (초음파센서와 금속감지센서로 서보모터 제어하기) master 22-05-18 142
질문 아두이노 우노 2개와 앱인벤터끼리의 블루투스 통신 방법댓글[3] 이미지첨부파일 pyoleo 22-05-17 116
게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기