<h2 class="hd-heading lts-narrow p-name" role="heading" style="box-sizing: border-box; font-size: 32px; margin: 0px; padding: 0px 0px 5px; letter-spacing: -1px; font-weight: 500; line-height: 1.3; font-family: &quot;Noto Sans CJK KR&quot;, 본고딕, &quot;Noto Sans Korean&quot;, &quot;맑은 고딕&quot;, &quot;Malgun Gothic&quot;, 돋움, Dotum, sans-serif; color: #555555; text-align: center; background-color: #ffffff;"><a href="https://comocloud.tistory.com/200" style="box-sizing: border-box; background-color: transparent; color: #222222; text-decoration-line: none;" target="_blank">아두이노 EEPROM에 구조체 저장</a></h2>
<p style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">MPU 종류&nbsp; /&nbsp; 용량 크기</p>
<p style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">ATmega128 : 4KiB</p>
<p style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">ATmega328 : 1KiB</p>
<p style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">ATmega2560 :&nbsp;<span style="box-sizing: border-box; color: #333333;">4KiB</span></p>
<p style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">ATmega16u2 : 0.5KiB</p>
<p style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">ATmega32u4 : 1KiB<br style="box-sizing: border-box;" />ATmega4809/4808 : 0.25KiB(256Byte)</p>
<p style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">&nbsp;</p>
<pre id="code_1589208511878" class="c++ arduino" data-ke-language="c++" data-ke-type="codeblock" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; background-color: #f8f8f8;"> 코드<span style="color: #555555; font-size: 14px;"></span>
   <code class="hljs cpp" style="color: #333333; font-size: 0.85em; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; padding: 0.5em; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-radius: 4px; display: block; overflow-x: auto;"><span class="hljs-meta" style="box-sizing: border-box; color: #999999; font-weight: bold;">#<span class="hljs-meta-keyword" style="box-sizing: border-box;">include</span><span class="hljs-meta-string" style="box-sizing: border-box;">&lt;EEPROM.h&gt;</span></span></code>
   <code class="hljs cpp" style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; padding: 0.5em; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-radius: 4px; display: block; overflow-x: auto;"><span class="hljs-class" style="color: #333333; box-sizing: border-box;"><span class="hljs-keyword" style="font-size: 0.85em; box-sizing: border-box; font-weight: bold;">struct</span><span class="hljs-title" style="font-size: 0.85em; box-sizing: border-box; color: #445588; font-weight: bold;">S_test</span><span style="font-size: 0.85em;"> {</span><span style="font-size: 11.9px;"></span></span><span class="hljs-keyword" style="color: #333333; font-size: 0.85em; box-sizing: border-box; font-weight: bold;">    unsigned</span><span class="hljs-keyword" style="color: #333333; font-size: 0.85em; box-sizing: border-box; font-weight: bold;">int</span><span style="color: #333333; font-size: 0.85em;"> num; </span><span class="hljs-comment" style="color: #999988; font-size: 0.85em; box-sizing: border-box; font-style: italic;">// 1 Byte</span><span class="hljs-keyword" style="color: #333333; font-size: 0.85em; box-sizing: border-box; font-weight: bold;">char</span><span style="color: #333333; font-size: 0.85em;"> name[</span><span class="hljs-number" style="color: #008080; font-size: 0.85em; box-sizing: border-box;">24</span><span style="color: #333333; font-size: 0.85em;">]; </span><span class="hljs-comment" style="font-size: 0.85em; box-sizing: border-box;"><font color="#999988"><i>// 24 Byte (한글은 1글자 = 3 Byte이다)</i></font></span><span style="color: #333333; font-size: 0.85em;">};</span></code>
   <code class="hljs cpp" style="color: #333333; font-size: 0.85em; box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; padding: 0.5em; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-radius: 4px; display: block; overflow-x: auto;"><span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">void</span><span class="hljs-title" style="box-sizing: border-box; color: #990000; font-weight: bold;">setup</span><span class="hljs-params" style="box-sizing: border-box;">()</span></span>{
    Serial.begin(<span class="hljs-number" style="box-sizing: border-box; color: #008080;">9600</span>);
    <span class="hljs-comment" style="box-sizing: border-box; color: #999988; font-style: italic;">// 구조체의 크기를 측정</span>
    Serial.println(<span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">sizeof</span>(S_test)); 
    <span class="hljs-comment" style="box-sizing: border-box; color: #999988; font-style: italic;">// 구조체 선언 후 값 할당</span>
    S_test t1 = {<span class="hljs-number" style="box-sizing: border-box; color: #008080;">1</span>, <span class="hljs-string" style="box-sizing: border-box; color: #dd1144;">"테스트글자입니다"</span>};
    S_test t2 = {<span class="hljs-number" style="box-sizing: border-box; color: #008080;">2</span>, <span class="hljs-string" style="box-sizing: border-box; color: #dd1144;">"코모클라우드"</span>};
    S_test t3 = {<span class="hljs-number" style="box-sizing: border-box; color: #008080;">3</span>, <span class="hljs-string" style="box-sizing: border-box; color: #dd1144;">"환영합니다!"</span>};
    <span class="hljs-comment" style="box-sizing: border-box; color: #999988; font-style: italic;">// EEPROM에 구조체 저장 (측정한 구조체의 Byte 크기에 맞게 값을 설정한다)</span>
    EEPROM.put(<span class="hljs-number" style="box-sizing: border-box; color: #008080;">0</span>, t1);
    EEPROM.put(<span class="hljs-number" style="box-sizing: border-box; color: #008080;">26</span>, t2);
    EEPROM.put(<span class="hljs-number" style="box-sizing: border-box; color: #008080;">52</span>, t3);
    <span class="hljs-comment" style="box-sizing: border-box; color: #999988; font-style: italic;">// 저장한 데이터를 받아올 구조체 선언</span><span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">struct</span><span class="hljs-title" style="box-sizing: border-box; color: #445588; font-weight: bold;">S_test</span><span class="hljs-title" style="box-sizing: border-box; color: #445588; font-weight: bold;">a</span>, <span class="hljs-title" style="box-sizing: border-box; color: #445588; font-weight: bold;">b</span>, <span class="hljs-title" style="box-sizing: border-box; color: #445588; font-weight: bold;">c</span>;</span><span class="hljs-comment" style="box-sizing: border-box; color: #999988; font-style: italic;">// EEPROM에서 데이터 읽어온 후 구조체에 저장</span>
    EEPROM.get(<span class="hljs-number" style="box-sizing: border-box; color: #008080;">0</span>, a);    
    EEPROM.get(<span class="hljs-number" style="box-sizing: border-box; color: #008080;">26</span>, b);    
    EEPROM.get(<span class="hljs-number" style="box-sizing: border-box; color: #008080;">52</span>, c);
    <span class="hljs-comment" style="box-sizing: border-box; color: #999988; font-style: italic;">// 구조체 출력</span>
    Serial.println((String) <span class="hljs-string" style="box-sizing: border-box; color: #dd1144;">"00:"</span> + a.num + <span class="hljs-string" style="box-sizing: border-box; color: #dd1144;">", "</span> + a.name);
    Serial.println((String) <span class="hljs-string" style="box-sizing: border-box; color: #dd1144;">"26:"</span> + b.num + <span class="hljs-string" style="box-sizing: border-box; color: #dd1144;">", "</span> + b.name);
    Serial.println((String) <span class="hljs-string" style="box-sizing: border-box; color: #dd1144;">"52:"</span> + c.num + <span class="hljs-string" style="box-sizing: border-box; color: #dd1144;">", "</span> + c.name);
}
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">void</span><span class="hljs-title" style="box-sizing: border-box; color: #990000; font-weight: bold;">loop</span><span class="hljs-params" style="box-sizing: border-box;">()</span></span>{
}</code>
   <span style="color: #555555; font-size: 14px;"></span></pre>
<p style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">* 구조체의 크기가 홀수 바이트인 경우, Padding해서 짝수 바이트로 만든다. 위의 경우도 구조체의 변수는 총 25Byte지만, Padding해서 26Byte로 만들었다.</p>
<p style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">&nbsp;&nbsp;</p>
<p style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">실행 결과&nbsp;</p>
<p style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">&nbsp;</p>
<figure class="imageblock alignCenter" data-filename="캡처.PNG" data-origin-width="722" data-origin-height="333" data-ke-mobilestyle="widthContent" style="box-sizing: border-box; margin: 0px auto 20px; max-width: 100%; clear: both; display: table; position: relative; text-align: center; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;"><span data-url="https://blog.kakaocdn.net/dn/UTfwE/btqD6QEwdN1/L7Flp40pNUV6eSMSzHZ2K1/img.png" data-lightbox="lightbox" data-alt="" style="box-sizing: border-box; cursor: pointer;"><img src="https://blog.kakaocdn.net/dn/UTfwE/btqD6QEwdN1/L7Flp40pNUV6eSMSzHZ2K1/img.png" srcset="https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FUTfwE%2FbtqD6QEwdN1%2FL7Flp40pNUV6eSMSzHZ2K1%2Fimg.png" data-filename="캡처.PNG" data-origin-width="722" data-origin-height="333" data-ke-mobilestyle="widthContent" style="box-sizing: border-box; border: 0px; vertical-align: middle; max-width: 100%; display: inline-block; width: 722px; margin: 0px; height: auto;" /></span></figure>
<p><br style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;" /><br style="box-sizing: border-box; color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;" /><span style="color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">출처:&nbsp;</span><a href="https://comocloud.tistory.com/200?category=865078" style="box-sizing: border-box; background-color: #f8f8f8; color: #222222; text-decoration-line: none; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px;" target="_blank">https://comocloud.tistory.com/200?category=865078</a><span style="color: #555555; font-family: &quot;Malgun Gothic&quot;, &quot;맑은 고딕&quot;, 굴림, gulim, 돋움, dotum, &quot;Microsoft NeoGothic&quot;, &quot;Droid sans&quot;, sans-serif; font-size: 14px; background-color: #f8f8f8;">&nbsp;[Post-IT!]</span></p>