부산IT학원/스마트컨트롤러

20140421 (LCD 제어 화면 출력, Single Linked List)

EHOzlO 2014. 4. 21. 10:27

46일차








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

ATMega128 LCD 제어

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





- Clear Display

화면 지우기


- Excution time

명령 실행까지 걸리는 시간

이 시간이 흐르기 전에 명령을 보내면 실행이 불가능하다.


- Return Home

커서를 맨 앞으로 옴김. DB0 자리에 - 는 아무 값이나 상관 없다는 뜻.


- Entry Mode

I/D (Increase/Decrease) 커서가 움직이는 방향 설정

(A_ 글자 오른쪽으로 움직. 1, H, Increase)

(_A 글자 왼쪽으로 움직. 0, L, Decrease)

S 화면이 움직이는 모드

1 set

0 no set (기본값으로 할 것)



LCD 글자 찍기 실습 화면





소스


smart.h

main.c












- C

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

Single Linked List

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





Single Linked List 는 항상 이런 구조를 갖고 있다.

이 안에서 구조 변경, 접근, 삭제등을 생각하는 것이 좋다.



다시 처음부터 Linked List 구조를 짜보자


- LinkedList.h

#ifndef _LinkedList_h_
#define _LinkedList_h_


#include <stdio.h>
#include <stdlib.h>

typedef struct _node
{
  char  data;
  struct _node * next;
}Node;

Node * Node_Insert(Node *, char);
void Node_Print(Node *);
void Node_Free(Node *);


#endif  // _LinkedList_h_


- LinkedList.c

#include "LinkedList.h"

Node * Node_Insert(Node * Head, char cData)
{
  Node * stpNew;
  Node * stpFront;
  Node * stpRear;

  stpFront = Head;
  stpRear = Head;
  stpNew = malloc(sizeof(Node));

  stpNew->data = cData;
  stpNew->next = NULL;

  while(0 != stpRear)  //  삽입 위치 검색
  {
    if(stpNew->data < stpRear->data)  // 삽입 위치 판단
    {
      break;
    }
    stpFront = stpRear;
    stpRear = stpRear->next;
  }

  stpNew->next = stpRear;
  stpFront->next = stpNew;
  
  return Head;
}

void Node_Print(Node * Head)
{
  while(0 != Head)
  {
    printf("%c -> ", Head->data);
    Head = Head->next;
  }
  printf("NULL \n");
}

void Node_Free(Node * Head)
{
  Node * temp;

  for(temp = Head; 0 != temp; temp = Head)
  {
    Head = Head->next;
    free(temp);
  }
}



- main.c

#include "LinkedList.h"

int main()
{
  Node *  Head = 0;

  Head = malloc(sizeof(Node));

  Head->data = 'b';
  Head->next = malloc(sizeof(Node));

  Head->next->data = 'd';
  Head->next->next = NULL;

  Node_Print(Head);

  Head = Node_Insert(Head, 'c');
  Head = Node_Insert(Head, 'e');

  Node_Print(Head);

  Node_Free(Head);
  
  return 0;
}


오늘은 리스트에 중간에, 끝부분에 검색하여 추가하는 것 까지 했고

내일은 앞부분에 추가하는 작업을 하고 삭제하는 것 까지 할 예정.