반응형



원래 노키아 핸드폰에서 사용되던 LCD인데 PCD8544 컨트롤러를 사용하고 있습니다. 그래픽 LCD라 간단한 그래픽 출력도 가능한데  가로 x 세로가 84x48의 해상도를 가집니다. 


문자를 출력해보니 가로 12자가 들어가고 6줄이 가능합니다..





아래 5개 핀은 순서대로 아래처럼 연결해주고

아두이노 7번핀 ---- LCD 3번핀

아두이노 6번핀 ---- LCD 4번핀

아두이노 5번핀 ---- LCD 5번핀

아두이노 4번핀 ---- LCD 6번핀

아두이노 3번핀 ---- LCD 7번핀


LCD8번핀과 LCD1번핀은 3.3V에 같이 연결해주고 LCD2번핀은 GROUND에 연결해주었습니다... 



https://github.com/sparkfun/GraphicLCD_Nokia_5110/tree/master/Firmware/Nokia_5110_Arduino_Example에 공개되어 있는 예제를 올려서 태스트 해봤는데.. 대문자는 제대로 나오는데 소문자는 한칸씩 밀리는 현상이 있어서 아래 처럼 한줄을 넣어주었더니...일단 대소문자는  제대로 나 옵니다..


오른쪽 처럼 \ 문자를 지워줘야 제대로 나오네요.. 예제 코드 문제가 아니었습니다.. 




 


사진은 흐리게 나왔지만 실제로 보면 백라이트가 상당히 밝습니다.. \는 두번 \\ 해주어야 출력이 됩니다. 






  1. /* 
  2.  7-17-2011 
  3.  Spark Fun Electronics 2011 
  4.  Nathan Seidle 
  5.   
  6.  This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). 
  7.   
  8.  This code writes a series of images and text to the Nokia 5110 84x48 graphic LCD: 
  9.  http://www.sparkfun.com/products/10168 
  10.   
  11.  Do not drive the backlight with 5V. It will smoke. However, the backlight on the LCD seems to be  
  12.  happy with direct drive from the 3.3V regulator. 
  13.  
  14.  Although the PCD8544 controller datasheet recommends 3.3V, the graphic Nokia 5110 LCD can run at 3.3V or 5V.  
  15.  No resistors needed on the signal lines. 
  16.   
  17.  You will need 5 signal lines to connect to the LCD, 3.3 or 5V for power, 3.3V for LED backlight, and 1 for ground. 
  18.  */  
  19.   
  20. #define PIN_SCE   7 //Pin 3 on LCD  
  21. #define PIN_RESET 6 //Pin 4 on LCD  
  22. #define PIN_DC    5 //Pin 5 on LCD  
  23. #define PIN_SDIN  4 //Pin 6 on LCD  
  24. #define PIN_SCLK  3 //Pin 7 on LCD  
  25.   
  26. //The DC pin tells the LCD if we are sending a command or data  
  27. #define LCD_COMMAND 0   
  28. #define LCD_DATA  1  
  29.   
  30. //You may find a different size screen, but this one is 84 by 48 pixels  
  31. #define LCD_X     84  
  32. #define LCD_Y     48  
  33.   
  34. //This table contains the hex values that represent pixels  
  35. //for a font that is 5 pixels wide and 8 pixels high  
  36. static const byte ASCII[][5] = {  
  37.   {0x00, 0x00, 0x00, 0x00, 0x00} // 20    
  38.   ,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !  
  39.   ,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "  
  40.   ,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #  
  41.   ,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $  
  42.   ,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %  
  43.   ,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &  
  44.   ,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '  
  45.   ,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (  
  46.   ,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )  
  47.   ,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *  
  48.   ,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +  
  49.   ,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,  
  50.   ,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -  
  51.   ,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .  
  52.   ,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /  
  53.   ,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0  
  54.   ,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1  
  55.   ,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2  
  56.   ,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3  
  57.   ,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4  
  58.   ,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5  
  59.   ,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6  
  60.   ,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7  
  61.   ,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8  
  62.   ,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9  
  63.   ,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :  
  64.   ,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;  
  65.   ,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <  
  66.   ,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =  
  67.   ,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >  
  68.   ,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?  
  69.   ,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @  
  70.   ,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A  
  71.   ,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B  
  72.   ,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C  
  73.   ,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D  
  74.   ,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E  
  75.   ,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F  
  76.   ,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G  
  77.   ,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H  
  78.   ,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I  
  79.   ,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J  
  80.   ,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K  
  81.   ,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L  
  82.   ,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M  
  83.   ,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N  
  84.   ,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O  
  85.   ,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P  
  86.   ,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q  
  87.   ,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R  
  88.   ,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S  
  89.   ,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T  
  90.   ,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U  
  91.   ,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V  
  92.   ,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W  
  93.   ,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X  
  94.   ,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y  
  95.   ,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z  
  96.   ,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [  
  97.   ,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c   
  98.   ,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]  
  99.   ,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^  
  100.   ,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _  
  101.   ,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `  
  102.   ,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a  
  103.   ,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b  
  104.   ,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c  
  105.   ,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d  
  106.   ,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e  
  107.   ,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f  
  108.   ,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g  
  109.   ,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h  
  110.   ,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i  
  111.   ,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j   
  112.   ,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k  
  113.   ,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l  
  114.   ,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m  
  115.   ,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n  
  116.   ,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o  
  117.   ,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p  
  118.   ,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q  
  119.   ,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r  
  120.   ,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s  
  121.   ,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t  
  122.   ,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u  
  123.   ,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v  
  124.   ,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w  
  125.   ,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x  
  126.   ,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y  
  127.   ,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z  
  128.   ,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {  
  129.   ,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |  
  130.   ,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }  
  131.   ,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ~  
  132.   ,{0x78, 0x46, 0x41, 0x46, 0x78} // 7f DEL  
  133. };  
  134.   
  135. //This is the SFE flame in bit form  
  136. char SFEFlame[] = {  
  137.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  138.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  139.   0x00, 0x00, 0x00, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE, 0xFE, 0x1E, 0x0E, 0x02, 0x00,  
  140.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  141.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  142.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  143.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  144.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF,  
  145.   0xFF, 0xFE, 0xFC, 0xF8, 0xF8, 0xF0, 0xF8, 0xFE, 0xFE, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00,  
  146.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  147.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  148.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  149.   0x00, 0x00, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xF3, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0,  
  150.   0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,  
  151.   0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  152.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  153.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  154.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,  
  155.   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,  
  156.   0x3F, 0x1F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  157.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  158.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  159.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,  
  160.   0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x03, 0x03,  
  161.   0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  162.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  163.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  164.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x1F,  
  165.   0x0F, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  166.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  167.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  
  168.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   
  169. };  
  170.   
  171.   
  172.   
  173. void setup(void) {  
  174.   Serial.begin(9600);  
  175.   LCDInit(); //Init the LCD  
  176. }  
  177.   
  178. void loop(void) {  
  179.   LCDClear();  
  180.   LCDBitmap(SFEFlame);  
  181.   delay(1000);  
  182.   
  183.   LCDClear();  
  184.   LCDString("ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz0123456789");  
  185.   delay(1000);  
  186. }  
  187.   
  188. void gotoXY(int x, int y) {  
  189.   LCDWrite(0, 0x80 | x);  // Column.  
  190.   LCDWrite(0, 0x40 | y);  // Row.  ?  
  191. }  
  192.   
  193. //This takes a large array of bits and sends them to the LCD  
  194. void LCDBitmap(char my_array[]){  
  195.   for (int index = 0 ; index < (LCD_X * LCD_Y / 8) ; index++)  
  196.     LCDWrite(LCD_DATA, my_array[index]);  
  197. }  
  198.   
  199. //This function takes in a character, looks it up in the font table/array  
  200. //And writes it to the screen  
  201. //Each character is 8 bits tall and 5 bits wide. We pad one blank column of  
  202. //pixels on each side of the character for readability.  
  203. void LCDCharacter(char character) {  
  204.   LCDWrite(LCD_DATA, 0x00); //Blank vertical line padding  
  205.   
  206.   Serial.println( character );  
  207.     
  208.   for (int index = 0 ; index < 5 ; index++)  
  209.     LCDWrite(LCD_DATA, ASCII[character - 0x20][index]);  
  210.     //0x20 is the ASCII character for Space (' '). The font table starts with this character  
  211.   
  212.   LCDWrite(LCD_DATA, 0x00); //Blank vertical line padding  
  213. }  
  214.   
  215. //Given a string of characters, one by one is passed to the LCD  
  216. void LCDString(char *characters) {  
  217.   while (*characters)  
  218.     LCDCharacter(*characters++);  
  219. }  
  220.   
  221. //Clears the LCD by writing zeros to the entire screen  
  222. void LCDClear(void) {  
  223.   for (int index = 0 ; index < (LCD_X * LCD_Y / 8) ; index++)  
  224.     LCDWrite(LCD_DATA, 0x00);  
  225.       
  226.   gotoXY(0, 0); //After we clear the display, return to the home position  
  227. }  
  228.   
  229. //This sends the magical commands to the PCD8544  
  230. void LCDInit(void) {  
  231.   
  232.   //Configure control pins  
  233.   pinMode(PIN_SCE, OUTPUT);  
  234.   pinMode(PIN_RESET, OUTPUT);  
  235.   pinMode(PIN_DC, OUTPUT);  
  236.   pinMode(PIN_SDIN, OUTPUT);  
  237.   pinMode(PIN_SCLK, OUTPUT);  
  238.   
  239.   //Reset the LCD to a known state  
  240.   digitalWrite(PIN_RESET, LOW);  
  241.   digitalWrite(PIN_RESET, HIGH);  
  242.   
  243.   LCDWrite(LCD_COMMAND, 0x21); //Tell LCD that extended commands follow  
  244.   LCDWrite(LCD_COMMAND, 0xB0); //Set LCD Vop (Contrast): Try 0xB1(good @ 3.3V) or 0xBF if your display is too dark  
  245.   LCDWrite(LCD_COMMAND, 0x04); //Set Temp coefficent  
  246.   LCDWrite(LCD_COMMAND, 0x14); //LCD bias mode 1:48: Try 0x13 or 0x14  
  247.   
  248.   LCDWrite(LCD_COMMAND, 0x20); //We must send 0x20 before modifying the display control mode  
  249.   LCDWrite(LCD_COMMAND, 0x0C); //Set display control, normal mode. 0x0D for inverse  
  250. }  
  251.   
  252. //There are two memory banks in the LCD, data/RAM and commands. This   
  253. //function sets the DC pin high or low depending, and then sends  
  254. //the data byte  
  255. void LCDWrite(byte data_or_command, byte data) {  
  256.   digitalWrite(PIN_DC, data_or_command); //Tell the LCD that we are writing either to data or a command  
  257.   
  258.   //Send the data  
  259.   digitalWrite(PIN_SCE, LOW);  
  260.   shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);  
  261.   digitalWrite(PIN_SCE, HIGH);  
  262. }  


반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts