Category/etc

마이크로프로세서 응용회로설계실습 - 임베디드 시스템

sumin 2022. 5. 31. 00:22
728x90
반응형

내 전공은 매 학기 실습을 진행한다. 아직 시험은 보지 않았지만, 프로젝트가 성공적으로 끝나서 회고를 해보려 한다.

 

우선 C언어를 사용해야 하는 수업이여서 걱정이 많았다. 나는 파이썬을 굉장히 좋아하고, 현재에도 가장 많이 쓰는 언어인데 그 이유는 직관적이고, 편리하기 때문이다.

우리 전공 학부생중에 종종 임베디드 시스템으로 진로를 잡는 경우가 있는데, 이 선택지는 고민도 안해봤다. C언어를 사용해야 하기 때문이다.

그럼에도 불구하고, C언어를 이용한 실습인점, 나를 포함한 조원중 코딩을 잘하는 사람이 없었다는 점에서 시간과 감정 소모가 굉장히 많이 됐다.

 

우선 전체적인 플로우를 적어보려한다.

 

0. 플로우 차트

 

코딩을 시작하기 전에, 우리는 용돈지급기를 만들것이며, 어떤 기능을 어떤 순서로 진행할지를 함수를 기준으로 차트를 표현했다.

세세히 보면 바뀐부분이 꽤 있지만, 이 과정이 도움이 된 것을 봐서 차후에 빅데이터 관련 프로젝트를 진행해도 비슷하게 틀을 짜고 시작해야겠다는 걸 배웠다.

 

 

1. 아이디 입력

 

int get_id() {

    int i;

    char clcd_str[20] = "";

    int key_count = 0, key_value = 0;

 

    while (1) {

        

        led_clear();

        clcd_clear_display();

        dot_clear();

 

        usleep(100000);

        led_all();

 

        strcpy(clcd_str, "INPUT ID : ");

        clcd_set_DDRAM(0x00);

        clcd_write_string(clcd_str);

 

        strcpy(clcd_str, ">>>> ____");

        clcd_set_DDRAM(0x40);

        clcd_write_string(clcd_str);

        usleep(100000);

 

        for (i = 0; i < MAX_FND; i++) {

            fnd_write(Money_info[i] - '0', 7 - i);

        }

        usleep(100000);

 

 

        while (key_count != 4) {

 

            while (!keypad_read(&key_value)) { }

            //keyboard_read(&key_value);         // for Ximulator

            dot_write(key_value); 

 

            if ((key_value == DELETE) && (key_count > 0)) {

                key_count--;

                clcd_str[5 + key_count] = '_';

                clcd_set_DDRAM(0x40);

                clcd_write_string(clcd_str);

            }

            else {

                (temp.id)[key_count] = key_value + 48;

                clcd_str[5 + key_count] = (temp.id)[key_count];

                clcd_set_DDRAM(0x40);

                clcd_write_string(clcd_str);

 

                key_count++;

            }

            usleep(300000);    

        }

 

        for (i = 0; i < MAX_USER; i++) {

            if (strcmp(user_info[i], temp.id) == 0) {

                if (i == 0) {

                    admin_select_mode();

                    key_count = 0;

                }

                else {

                    user_select_mode();

                    key_count = 0;

                }

            }

            else {

                continue;

            }

        }

    }

}

 

2. 유저 모드

 

void user_select_mode() {

    int key_value = 0, key_count;

    bool screen_output = false;

 

    char user_select_message[4][20] = { "1. Study        ",

                                        "2. Hobby       >",

                                        "3. Etc          ",

                                        "               <" };

    led_clear();

    usleep(100000);

    led_all();

 

 

    clcd_clear_display();

    set_split_message(user_select_message);

        

    while (1) {       

        while(!keypad_read(&key_value)){  }

 

        //keyboard_read(&key_value);         // for Ximulator

        dot_write(key_value);

 

        if(key_value == 1) {

            strcpy(temp.use, "Study");

            get_user_money();

        }

        else if (key_value == 2) {

            strcpy(temp.use, "Hobby");

            get_user_money();

        }

        else if (key_value == 3) {

            strcpy(temp.use, "Etc");

            get_user_money();

        }

        else if (key_value == LEFT) {

            if (screen_output) {

            switch_screen_left();

            screen_output = false;

            }

        }   

        else if (key_value == RIGHT) {

            if (!screen_output) {

            switch_screen_right();

            screen_output = true;

            }

        }        

    }    

}

 

void get_user_money() {

                   

    int a, b, i;

    char clcd_str[20] = "";

    int key_count = 0, key_value;

 

 

    strcpy(temp.money, "000000");

 

    while(1) {

        led_clear();

        usleep(100000);

        led_all();

 

 

        clcd_clear_display();

        strcat(clcd_str, "INPUT Money : ");

        clcd_set_DDRAM(0x00);

        clcd_write_string(clcd_str);

 

        strcpy(clcd_str, ">>>> ______");

        clcd_set_DDRAM(0x40);

        clcd_write_string(clcd_str);

        

 

        while (key_count != 6) {

 

            while(!keypad_read(&key_value)){ }       // for X-Hyper

            //keyboard_read(&key_value);         // for Ximulator

            dot_write(key_value);

 

            if ((key_value == DELETE) && (key_count > 0)) {

                key_count--;

                clcd_str[5 + key_count] = '_';

                clcd_set_DDRAM(0x40);

                clcd_write_string(clcd_str);

            }

            else if (key_value == BACK) {

                next++;

                return;

            }

            else{

                (temp.money)[key_count] = key_value + 48;

 

                clcd_str[5 + key_count] = (temp.money)[key_count];

                clcd_set_DDRAM(0x40);

                clcd_write_string(clcd_str);

 

                key_count++;

            }

 

            usleep(300000);

        }

 

        a = atoi(temp.money);    //use money

        b = atoi(Money_info);   //total money

 

 

        if (b >= a) {               

            b -= a;

            sprintf(Money_info, "%d", b);

 

            history[count] = temp;           

            count++;

 

            print_user_money();

            

            break;

        }

        else {

            clcd_clear_display();

            strcpy(clcd_str, "Lack of Money");

            clcd_set_DDRAM(0x00);

            clcd_write_string(clcd_str);

            *clcd_str = 0;

 

        for (i = 0; i < MAX_FND; i++) {

               fnd_write(Money_info[i] - '0', 7 - i);

        }

 

        sleep(2);

        get_id();

        }

    }

}

    

void print_user_money() {

    int i;

    char totalmoney_message[2][40] = { "Total Money->FND",

                                        "complete" };

    clcd_clear_display();

    set_message(totalmoney_message);

    led_clear();

    usleep(100000);

    led_all();

 

 

    for (i = 0; i < MAX_FND; i++) {       

        

        fnd_write( (Money_info[i] - '0'), 7- i);

        

    }

 

    sleep(2);

    get_id();

}

 

3. 관리자 모드

 

void admin_select_mode() {

 

    bool screen_output = false;

    int key_value = 0 , key_count;

 

    char admin_select_message[4][20] = { "1. Locked       ",

                                         "2. History     >",

                                         "3. Input Money  ",

                                         "               <" };

 

    clcd_clear_display();

    set_split_message(admin_select_message);

    led_clear();

    usleep(100000);

    led_all();

 

    while (1) {

        while(!keypad_read(&key_value)){ }

        //keyboard_read(&key_value);         // for Ximulator

        dot_write(key_value);

 

            if (key_value == 1) {

                locked_get_id();                

                }

            else if (key_value == 2) { 

                select_history();

                }

            else if (key_value == 3) {

                get_admin_money();

                }

            else if (key_value == LEFT) {

                if (screen_output) {

                switch_screen_left();

                screen_output = false;

                }

            }

        else if (key_value == RIGHT) {

            if (!screen_output) {

                switch_screen_right();

                screen_output = true;

            }

        }        

     }             

}

 

int locked_get_id() {

    int i;

    char clcd_str[20] = "";

    char locked[5];

    int key_count = 0, key_value;

 

    while (1) {

        *clcd_str = 0;

 

        strcat(clcd_str, "[LOCKED]INPUT ID : ");

        clcd_set_DDRAM(0x00);

    clcd_clear_display();

        clcd_write_string(clcd_str);

 

        strcpy(clcd_str, ">>>> ____");

        clcd_set_DDRAM(0x40);

        clcd_write_string(clcd_str);

        

 

    *locked = 0;

    key_count = 0;

 

        while (key_count != 4) {

 

            while(!keypad_read(&key_value)){ };         // for X-Hyper

            //keyboard_read(&key_value);         // for Ximulator

            dot_write(key_value);

 

            if ((key_value == DELETE) && (key_count > 0)) {

                key_count--;

                clcd_str[5 + key_count] = '_';

                clcd_set_DDRAM(0x40);

                clcd_write_string(clcd_str);

            }

            else {

                locked[key_count] = key_value + 48;

                clcd_str[5 + key_count] = locked[key_count];

                clcd_set_DDRAM(0x40);

                clcd_write_string(clcd_str);

 

                key_count++;

            }

            usleep(300000);

        }

        for (i = 0; i < MAX_USER; i++) {

            if (strcmp(user_info[i], locked) == 0) {

                get_id();

            }

            else {

                locked_get_id();

        }

    }

    }

}

 

void select_history() {

   

    while (1) { 

int key_count = 0, key_value, a;

 

        char sel_history_message[2][40] = { "Select Number",

                                            "" };

        

        clcd_clear_display();

        fnd_clear();

        dot_clear();

        set_message(sel_history_message);

 

   

       while(!keypad_read(&key_value)){ };         // for X-Hyper

        //keyboard_read(&key_value);         // for Ximulator        

        

        a = key_value;

        

 

 

        if (((history[key_value]).id[0] != '\0') && (key_value >= 0) && (key_value <= 10)) {

 

            print_history(a);

                        

        }

        

        else if ((key_value > 10) || (history[key_value].id[0] = '\0')) {

            print_error();

            

        }

    }

}

 

void print_history(int a) {

    char clcd_str[20] = "";

    int key_value, i;

    clcd_clear_display();

    

 

    while (1) {

        dot_clear();        

        strcat(clcd_str,history[a].id);

        clcd_set_DDRAM(0x00);

        clcd_write_string(clcd_str);

 

        strcpy(clcd_str,history[a].use);

        clcd_set_DDRAM(0x06);

        clcd_write_string(history[a].use);

 

        for (i = 0; i < MAX_FND; i++) {

            fnd_write(history[a].money[i] - '0', 5 - i);

        }

 

        strcpy(clcd_str, "Y: Done, B: Back");       //Y:COMPLETE, B:BACK

        clcd_set_DDRAM(0x40);

        clcd_write_string(clcd_str);

 

        while(!keypad_read(&key_value)){ };         // for X-Hyper

        //keyboard_read(&key_value);         // for Ximulator         

           

        if (key_value == COMPLETE) {

            get_id();

        }

        else if (key_value == BACK) {

            next++;

            return;

        }

    }

}

 

void print_error() {

    char print_error_message[2][40] = { "Wrong Number",

                                        "" };

    clcd_clear_display();

    set_message(print_error_message);

 

    sleep(2);

}

 

void get_admin_money() {

    int a, b, i;

        char clcd_str[20] = "";

        int key_count = 0, key_value;

    

    while(1){             

 

        clcd_clear_display();

        strcat(clcd_str, "INPUT Money : ");

        clcd_set_DDRAM(0x00);

        clcd_write_string(clcd_str);

 

        strcpy(clcd_str, ">>>> ________");

        clcd_set_DDRAM(0x40);

        clcd_write_string(clcd_str);

                   

        while (key_count != 8) {

 

            while(!keypad_read(&key_value)){ };         // for X-Hyper

            //keyboard_read(&key_value);         // for Ximulator

            dot_write(key_value);

 

            if ((key_value == DELETE) && (key_count > 0)) {

                key_count--;

                clcd_str[5 + key_count] = '_';

                clcd_set_DDRAM(0x40);

                clcd_write_string(clcd_str);

            }

            else {

                (temp.money)[key_count] = key_value + 48;

 

                clcd_str[5 + key_count] = (temp.money)[key_count];

                clcd_set_DDRAM(0x40);

                clcd_write_string(clcd_str);

 

                key_count++;

            }

            usleep(300000);

        }

 

 

        a = atoi(temp.money);

        b = atoi(Money_info);

 

        if ((99999999 - b) >= a) {

            b += a;

            sprintf(Money_info, "%d", b);

 

            print_admin_money();

 

            sleep(4);

        return;

        }

        else if ((99999999 - b) < a){

        clcd_clear_display();

        *clcd_str = 0;

            strcat(clcd_str, "Enough Money");

            clcd_set_DDRAM(0x00);

            clcd_write_string(clcd_str);

 

        for (i = 0; i < MAX_FND; i++) {

               fnd_write(Money_info[i] - '0', 7 - i);

 

        }

 

            sleep(2);

            get_id();

        }

    }    

}

    

void print_admin_money() {

    int i;

    char get_admin_money_message[2][40] = { "Total Money->FND",

                                            "complete" };

    clcd_clear_display();

    set_message(get_admin_money_message);

        

    for (i = 0; i < MAX_FND; i++) {

        fnd_write(Money_info[i] - '0', 7 - i);

 

    }

    sleep(2);

    get_id();

}

 

----------------------------------------------------------------------------------------------------------------------------------

 

배운점 :

 

1. '먼지를 털어라'

 

프로젝트 진행중에 해프닝이 있었다. 예전이였으면 프로젝트보다 이 문제에 더 시간과 감정을 쏟았을텐데, 이제는 큰 감흥이 없었다.

그저, 내가 생각하기에 이게 정말 문제가 있는 사안인지를 생각해봤고, 아니여서 내 할 일을 했는다. 결과적으로 잘됐으니 내 생각이 옳았구나 하고 앞으로도 같은 마음가짐으로 살아가도 될 것 같다. 만약 나중에 다른 일을 경험할 때 문제가 생긴다면, 이번과 같은 생각을 해보고, 고치거나 또 배워나가면 되겠지.

사람은 어떤일을 하던 세부류의 사람을 만난다고한다. 비판적인 사람 / 중립적인 사람 / 수용적인 사람

여기서 대부분의 비판적인 사람은 내가 어떤 노력을 해도 바뀌지 않는다고 한다. 이 사람에 투자할 시간과 감정을 중립적인 사람과 수용적인 사람한테 쓰는게 낫다고 생각한다.

 

2. 부족함은 상대적이다.

 

막상 발표까지 끝나고 되돌아보니, 정작 가장 잘한 프로젝트 조는 우리 조라고 생각한다. 아마 다른조도 비슷한 생각을 가지고 있을 것 같다.

분명히 부족하다고 생각했는데 남들보다는 덜 부족했나보다.

중간에 포기한다면 이런 경험도 못해봤을 거였으니까 꽤나 스트레스는 받았지만 좋은 교훈을 얻을 수 있었다.

 

 

728x90
반응형