모바일 오유 바로가기
http://m.todayhumor.co.kr
분류 게시판
베스트
  • 베스트오브베스트
  • 베스트
  • 오늘의베스트
  • 유머
  • 유머자료
  • 유머글
  • 이야기
  • 자유
  • 고민
  • 연애
  • 결혼생활
  • 좋은글
  • 자랑
  • 공포
  • 멘붕
  • 사이다
  • 군대
  • 밀리터리
  • 미스터리
  • 술한잔
  • 오늘있잖아요
  • 투표인증
  • 새해
  • 이슈
  • 시사
  • 시사아카이브
  • 사회면
  • 사건사고
  • 생활
  • 패션
  • 패션착샷
  • 아동패션착샷
  • 뷰티
  • 인테리어
  • DIY
  • 요리
  • 커피&차
  • 육아
  • 법률
  • 동물
  • 지식
  • 취업정보
  • 식물
  • 다이어트
  • 의료
  • 영어
  • 맛집
  • 추천사이트
  • 해외직구
  • 취미
  • 사진
  • 사진강좌
  • 카메라
  • 만화
  • 애니메이션
  • 포니
  • 자전거
  • 자동차
  • 여행
  • 바이크
  • 민물낚시
  • 바다낚시
  • 장난감
  • 그림판
  • 학술
  • 경제
  • 역사
  • 예술
  • 과학
  • 철학
  • 심리학
  • 방송연예
  • 연예
  • 음악
  • 음악찾기
  • 악기
  • 음향기기
  • 영화
  • 다큐멘터리
  • 국내드라마
  • 해외드라마
  • 예능
  • 팟케스트
  • 방송프로그램
  • 무한도전
  • 더지니어스
  • 개그콘서트
  • 런닝맨
  • 나가수
  • 디지털
  • 컴퓨터
  • 프로그래머
  • IT
  • 안티바이러스
  • 애플
  • 안드로이드
  • 스마트폰
  • 윈도우폰
  • 심비안
  • 스포츠
  • 스포츠
  • 축구
  • 야구
  • 농구
  • 바둑
  • 야구팀
  • 삼성
  • 두산
  • NC
  • 넥센
  • 한화
  • SK
  • 기아
  • 롯데
  • LG
  • KT
  • 메이저리그
  • 일본프로야구리그
  • 게임1
  • 플래시게임
  • 게임토론방
  • 엑스박스
  • 플레이스테이션
  • 닌텐도
  • 모바일게임
  • 게임2
  • 던전앤파이터
  • 마비노기
  • 마비노기영웅전
  • 하스스톤
  • 히어로즈오브더스톰
  • gta5
  • 디아블로
  • 디아블로2
  • 피파온라인2
  • 피파온라인3
  • 워크래프트
  • 월드오브워크래프트
  • 밀리언아서
  • 월드오브탱크
  • 블레이드앤소울
  • 검은사막
  • 스타크래프트
  • 스타크래프트2
  • 베틀필드3
  • 마인크래프트
  • 데이즈
  • 문명
  • 서든어택
  • 테라
  • 아이온
  • 심시티5
  • 프리스타일풋볼
  • 스페셜포스
  • 사이퍼즈
  • 도타2
  • 메이플스토리1
  • 메이플스토리2
  • 오버워치
  • 오버워치그룹모집
  • 포켓몬고
  • 파이널판타지14
  • 배틀그라운드
  • 기타
  • 종교
  • 단어장
  • 자료창고
  • 운영
  • 공지사항
  • 오유운영
  • 게시판신청
  • 보류
  • 임시게시판
  • 메르스
  • 세월호
  • 원전사고
  • 2016리오올림픽
  • 2018평창올림픽
  • 코로나19
  • 2020도쿄올림픽
  • 게시판찾기
  • 오유인페이지
    개인차단 상태
    그래여님의
    개인페이지입니다
    가입 : 12-11-14
    방문 : 1372회
    닉네임변경 이력
    회원차단
    회원차단해제
    게시물ID : programmer_10831
    작성자 : 그래여
    추천 : 0
    조회수 : 1019
    IP : 168.115.***.206
    댓글 : 5개
    등록시간 : 2015/06/04 14:27:11
    http://todayhumor.com/?programmer_10831 모바일
    atmega128 2개의 메인문 사용...
    옵션
    • 본인삭제금지
    오늘 질문만 많이 올려서 죄송해요..
     
    구동하는데 2가지가 안되므로 메인문을 2개를 사용하고싶은데... 하나의 프로젝트에 2개지 c파일을 사용하여 동작하는 형태입니다...
     
    어떤 방식으로 하는건지 알려주세요 ㅜㅜ
     
    - 처음 메인분 -
    #include <avr/io.h> //16MHz
    #define F_CPU 16000000UL // 16 MHz
    #include <util/delay.h>
    #include"ATmega128_v20m.h"
    #define DEBOUNCING_DELAY 20

    void RC_Motor(int angle){ // angle : -90도 ~ +90도
    int i;
    if(angle<-90)angle=-90;
    if(angle> 90)angle= 90;
    i=(angle)*18 + 3000;
    OCR3A=i; //PB5
    OCR3B=i; //PB6
    }
    int angle=0;


    int main(void){

    DDRB=0x00;
    PORTB=0x00;
    PORTE = 0x00;
    //RC서보모터
    DDRE=0x18; // PB5,6 out
    TCCR3A=0xAA; // FAST PWM
    TCCR3B=0x1A; // 8분주=0.5usec
    OCR3A=3000; // 1500usec=0도
    OCR3B=3000; // 1500usec=0도
    ICR3=47999; // 0.5usec*48000=24000usec=41.67Hz

    while(1){

    /* RC_Motor(-90); _delay_ms(6000);
    RC_Motor( 0); _delay_ms(6000);
    RC_Motor( 90); _delay_ms(6000);
    RC_Motor( 0); _delay_ms(6000); */

    if((PINB&0x01)==0){
    if(angle>-90){
    angle--;

    RC_Motor(angle); ;
    }
    }
    if((PINB&0x02)==0){
    if(angle< 0){
    angle ++;

    RC_Motor(angle); ;
    }
    }

    if((PINB&0x04)==0){
    if(angle > 0){
    angle --;

    RC_Motor(angle); ;
    }
    }
    if((PINB&0x08)==0){
    if(angle<90){
    angle++;

    RC_Motor(angle); ;
    }
    }
    _delay_ms(10);

    }
    }
     
     
     
    -- 2번째 메인문 --
     
    #include<avr/io.h>

    #include<util/delay.h>

    #include"ATmega128_v20m.h"

    #define DEBOUNCING_DELAY 20

    #define F_CPU 16000000UL // 16 MHz

    void RC_Motor(int angle){ // angle : -90도 ~ +90도
    int i;
    if(angle<-90)angle=-90;
    if(angle> 90)angle= 90;
    i=(angle)*18 + 3000;
    OCR3A=i; //PB5
    OCR3B=i; //PB6
    }

    int angle=0;


    void msec_delay(int n);

    char pattern1[3] = {1,2,3};
    char pattern2[2] = {2,1};
    char pattern3[3] = {3,2,1};
    char pattern4[2] = {1,2};
    char pattern5[2] = {3,2};
    char pattern6[3] = {1,2,3};
    char pattern7[2] = {2,3};
    char pattern8[2] = {0x11, 0x10};

    int x,z;
    int floor =1;
    int y=8;
    int main()
    {
    PORTB = 0x00;
    DDRB=0xf0;
    PORTE = 0x00;
    //RC서보모터
    DDRE=0x18; // PE 3,4 out 서보모터 연결 핀
    TCCR3A=0xAA; // FAST PWM
    TCCR3B=0x1A; // 8분주=0.5usec
    OCR3A=3000; // 1500usec=0도
    OCR3B=3000; // 1500usec=0도
    ICR3=47999; // 0.5usec*48000=24000usec=41.67Hz

    PORTD = 0xff;
    DDRD = 0xf0;

    MCU_initialize();
    Delay_ms(50);
    LCD_initialize();


    LCD_command(0x83);
    LCD_2d(floor);
    LCD_string(0x85, "Floor");

    while(1)
    {

    if((PINB&0x01)==0){
    if(angle>-90){
    angle--;

    RC_Motor(angle); ;
    }
    }
    if((PINB&0x02)==0){
    if(angle< 0){
    angle ++;

    RC_Motor(angle); ;
    }
    }

    if((PINB&0x04)==0){
    if(angle > 0){
    angle --;

    RC_Motor(angle); ;
    }
    }
    if((PINB&0x08)==0){
    if(angle<80){
    angle++;

    RC_Motor(angle); ;
    }
    }
    _delay_ms(10);


    if((PIND&0x01)==0)
    {
    if(floor==1)
    {
    PORTB=0x10;
    }

    else if(floor==2) //2층에서 1층으로 갈 때
    {
    x=0;
    LCD_string(0xc3, "1");
    while(PIND&0x08);
    LCD_string(0xc3, "CLOSE DOOR");
    Delay_ms(1000);
    LCD_initialize();

    while(1)
    {
    LCD_string(0x88, "<");
    LCD_command(0xc7);
    LCD_2d(pattern2[x]);
    Delay_ms(1000);
    x=x+1;
    LCD_string(0x85, "<");
    LCD_command(0xc7);
    LCD_2d(pattern2[x]);
    if(x==2)break;

    } //

    LCD_initialize();
    LCD_string(0xc3, "OPEN DOOR");
    Delay_ms(1000);
    LCD_initialize();
    floor = 1;
    LCD_command(0x83);
    LCD_2d(floor);
    LCD_string(0x85, "Floor");
    }

    else if (floor==3) //3층에서 1층으로 갈 때
    {
    x=0;
    LCD_string(0xc3, "1");
    while(PIND&0x08);
    LCD_string(0xc3, "CLOSE DOOR");
    Delay_ms(1000);
    LCD_initialize();

    while(1){
    Delay_ms(500);
    LCD_string(0x88, "<");
    LCD_command(0xc7);
    LCD_2d(pattern3[x]);
    Delay_ms(1000);
    x=x+1;
    LCD_string(0x86, "<");
    LCD_command(0xc7);
    LCD_2d(pattern3[x]);
    Delay_ms(1000);
    x=x+1;
    LCD_string(0x84, "<");
    LCD_command(0xc7);
    LCD_2d(pattern3[x]);
    Delay_ms(1000);

    if(x==2)break; //

    }
    LCD_initialize();
    LCD_string(0xc3, "OPEN DOOR");
    Delay_ms(1000);
    LCD_initialize();
    floor = 1;
    LCD_command(0x83);
    LCD_2d(floor);
    LCD_string(0x85, "Floor");
    }
    }

    else if((PIND&0x02)==0)
    {
    if(floor==2)
    {
    PORTB=0x20;
    }

    else if(floor==1) //1층에서 2층으로 갈 때
    {
    x=0;
    LCD_string(0xc5, "2");
    while(PIND&0x08);
    LCD_string(0xc3, "CLOSE DOOR");
    Delay_ms(1000);
    LCD_initialize();

    while(1)
    {
    LCD_string(0x88, ">");
    LCD_command(0xc7);
    LCD_2d(pattern4[x]);
    Delay_ms(1000);
    x=x+1;
    LCD_string(0x8b, ">");
    LCD_command(0xc7);
    LCD_2d(pattern4[x]);
    if(x==2)break;

    }
    LCD_initialize(); //
    LCD_string(0xc3, "OPEN DOOR");
    Delay_ms(1000);
    LCD_initialize();
    floor = 2;
    LCD_command(0x83);
    LCD_2d(floor);
    LCD_string(0x85, "Floor");
    }

    else if (floor==3) //3층에서 2층으로 갈 때
    {
    LCD_command(0x83);
    LCD_2d(floor);
    LCD_string(0x85, "Floor");

    x=0;
    LCD_string(0xc5, "2");
    while(PIND&0x08);
    LCD_string(0xc3, "CLOSE DOOR");
    Delay_ms(1000);
    LCD_initialize();

    while(1)
    {
    LCD_string(0x88, "<");
    LCD_command(0xc7);
    LCD_2d(pattern5[x]);
    Delay_ms(1000);
    x=x+1;
    LCD_string(0x85, "<");
    LCD_command(0xc7);
    LCD_2d(pattern5[x]);
    if(x==2)break;

    } //
    LCD_initialize();
    LCD_string(0xc3, "OPEN DOOR");
    Delay_ms(1000);
    LCD_initialize();
    floor = 2;
    LCD_command(0x83);
    LCD_2d(floor);
    LCD_string(0x85, "Floor");
    }

    }

    else if((PIND&0x04)==0)
    {
    if(floor==3)
    {
    PORTB=0x40;
    }

    else if(floor==1) //1층에서 3층으로 갈 때
    {
    LCD_command(0x83);
    LCD_2d(floor);
    LCD_string(0x85, "Floor");

    x=0;
    LCD_string(0xc8, "3");
    while(PIND&0x08);
    LCD_string(0xc3, "CLOSE DOOR");
    Delay_ms(1000);
    LCD_initialize();

    while(1){
    Delay_ms(500);
    LCD_string(0x88, ">");
    LCD_command(0xc7);
    LCD_2d(pattern1[x]);
    Delay_ms(1000);
    x=x+1;
    LCD_string(0x8a, ">");
    LCD_command(0xc7);
    LCD_2d(pattern1[x]);
    Delay_ms(1000);
    x=x+1;
    LCD_string(0x8c, ">");
    LCD_command(0xc7);
    LCD_2d(pattern1[x]);
    Delay_ms(1000);

    if(x==2)break; //

    }
    LCD_initialize();
    LCD_string(0xc3, "OPEN DOOR");
    Delay_ms(1000);
    LCD_initialize();
    floor = 3;
    LCD_command(0x83);
    LCD_2d(floor);
    LCD_string(0x85, "Floor");
    }

    else if (floor==2) //2층에서 3층으로 갈 때
    {
    LCD_command(0x83);
    LCD_2d(floor);
    LCD_string(0x85, "Floor");

    x=0;
    LCD_string(0xc8, "3");
    while(PIND&0x08);
    LCD_string(0xc3, "CLOSE DOOR");
    Delay_ms(1000);
    LCD_initialize();

    while(1)
    {
    LCD_string(0x88, ">");
    LCD_command(0xc7);
    LCD_2d(pattern7[x]);
    Delay_ms(1000);
    x=x+1;
    LCD_string(0x8b, ">");
    LCD_command(0xc7);
    LCD_2d(pattern7[x]);
    if(x==2)break;

    } //
    LCD_initialize();
    LCD_string(0xc3, "OPEN DOOR");
    Delay_ms(1000);
    LCD_initialize();
    floor = 3;
    LCD_command(0x83);
    LCD_2d(floor);
    LCD_string(0x85, "Floor");
    }

    }


    }
    }
     
    이렇게 2가지 동작을 하나의 프로젝트에서 구현하고 싶은데 섞어 넣으면 컴파일 오류는 없지만 동작을 하나만 해요..ㅜ.ㅠ

    이 게시물을 추천한 분들의 목록입니다.
    푸르딩딩:추천수 3이상 댓글은 배경색이 바뀝니다.
    (단,비공감수가 추천수의 1/3 초과시 해당없음)

    죄송합니다. 댓글 작성은 회원만 가능합니다.

    번호 제 목 이름 날짜 조회 추천
    24
    공부다하가 뜻밖의 심장폭행... [2] 그래여 16/05/23 14:42 151 4
    23
    아아 롤 삭제가 안되는데 어떡하져 ㅠㅠ [8] 본인삭제금지 그래여 16/03/19 22:59 76 1
    22
    안녕하세요 게임개발자가 되고싶은 대학생입니다. [12] 본인삭제금지 그래여 15/09/12 23:41 26 0
    21
    이번주에 일본 오사카 그래여 15/09/03 15:16 32 0
    atmega128 2개의 메인문 사용... [7] 본인삭제금지 그래여 15/06/04 14:27 32 0
    19
    서보 모터 코딩문제 [3] 본인삭제금지 그래여 15/06/04 11:42 42 0
    18
    avr 도와주실 분 계실까요 ㅠㅠ [6] 본인삭제금지 그래여 15/06/03 01:39 30 0
    17
    본삭금] 안드로이드 REST API 사용법좀 알려주세요 ㅠㅠ [3] 그래여 15/05/08 01:03 36 0
    16
    logcat해석좀해주세요.(구글맵이 avd,폰 둘다 안켜지네요) [6] 그래여 15/04/30 20:28 27 0
    15
    안드로이드 구글맵 띄우는것 AVD.폰 둘다안되네요.ㅠㅠㅠㅠ [5] 그래여 15/04/30 02:22 34 0
    14
    쇼핑몰을 하려고하는데요! [11] 그래여 14/08/08 16:22 84 0
    13
    이거 오류인가요?? [6] 그래여 14/07/10 23:35 74 0
    12
    혹시 tizen 쓰시는분 계신가요?? 그래여 14/05/04 22:03 28 0
    11
    주머니가 묵직한게... [3] 그래여 14/02/13 11:56 348 4
    9
    와...전지현... 그래여 13/12/19 23:03 216 0
    8
    신호와 시스템에서요 그래여 13/12/09 17:20 23 0
    7
    와 안현수 선수 정말... 그래여 13/11/18 10:47 87 0
    6
    결국 winner는 그래여 13/10/25 22:48 147 0
    5
    그래여 13/08/12 02:03 12 0
    3
    스냅백 [4] 그래여 13/06/23 15:34 70 0
    2
    추천좀 해주세요 [1] 그래여 13/06/11 11:44 23 0
    1
    진격의 거인 질문요 [1] 그래여 13/05/09 22:18 62 0
    [1]
    단축키 운영진에게 바란다(삭제요청/제안) 운영게 게시판신청 자료창고 보류 개인정보취급방침 청소년보호정책 모바일홈