2011년8월25일_ARM_16*2line CLCD 명령어설명 및 초기화 그리고 문자열 출력




시간나면 정리할 것이나..
과연 시간이 날까? ㅠ.ㅠ



참조(Reference)




DSCN4004 DSCN4005 DSCN4006






DSCN3998 DSCN4002






 




 



 



   1: /*********************************************************
   2:                     PIO (AT91SAM7S256)
   3: *********************************************************/
   4: #define PIOA_PER    (*(volatile unsigned int *)0xFFFFF400)
   5: #define PIOA_OER    (*(volatile unsigned int *)0xFFFFF410)
   6: #define PIOA_PPUDR    (*(volatile unsigned int *)0xFFFFF460)
   7: #define PIOA_CODR    (*(volatile unsigned int *)0xFFFFF434)
   8: #define PIOA_SODR    (*(volatile unsigned int *)0xFFFFF430)
   9:  
  10: /*********************************************************
  11:                     16 * 2line CLCD
  12: *********************************************************/
  13: //7월 13일 추가
  14: #define    CLCD_RS    (1 << 8)
  15: #define    CLCD_RW    (1 << 9)
  16: #define    CLCD_EN    (1 << 10)
  17: #define    CLCD_BS    (0xFF << 16)
  18: //7월 14일 추가
  19: #define    CLCD_INST_CD    (0x01 << 16)        //Clear Display명령
  20: #define    CLCD_INST_RH    (0x02 << 16)        //Return Home명령
  21: #define    CLCD_INST_FS    (0x38 << 16)        //Function Set명령
  22: #define    CLCD_INST_EM    (0x06 << 16)        //Entry Mode Set명령
  23: #define    CLCD_INST_DO    (0x0F << 16)        //Display ON/OFF Control명령
  24: #define    CLCD_INST_CS    (0x14 << 16)        //Cursor Shift명령 - 커서를 right
  25: #define    CLCD_INST_DD    (0x80 << 16)        //DDRAM 0번지선택.
  26: #define    CLCD_DELAY(Z)        for(iCount = 0 ; (Z) > iCount ;++iCount)        //시간지연
  27: #define    LED        (1 << 0)
  28:  
  29: void LCD_INIT(void);
  30: void LCD_Inst(unsigned int);    //LCD에 명령을 내리는 함수.
  31: void LCD_Data(unsigned int uiInst);    //LCD에 명령을 내리는 함수.
  32:  
  33: int main(void)
  34: {
  35:  
  36:     LCD_INIT();
  37:     LCD_Inst(CLCD_INST_FS);        
  38:     LCD_Inst(CLCD_INST_EM);
  39:     LCD_Inst(CLCD_INST_CS);
  40:     LCD_Inst(CLCD_INST_DO);
  41:     LCD_Inst(CLCD_INST_CD);
  42:     LCD_Inst(CLCD_INST_DD);        //첫행으로.
  43:     LCD_Inst(CLCD_INST_RH);        //리턴홈.
  44:     LCD_Data('H'<<16);
  45:     LCD_Data('e'<<16);
  46:     LCD_Data('l'<<16);
  47:     LCD_Data('l'<<16);
  48:     LCD_Data('o'<<16);
  49:     LCD_Data(' '<<16);
  50:     LCD_Data('W'<<16);
  51:     LCD_Data('o'<<16);
  52:     LCD_Data('r'<<16);
  53:     LCD_Data('l'<<16);
  54:     LCD_Data('d'<<16);
  55:     LCD_Data('!'<<16);
  56:     LCD_Data('!'<<16);
  57:     LCD_Inst(0xC0 << 16);        //다음 행.
  58:     LCD_Data('K'<<16);
  59:     LCD_Data('i'<<16);
  60:     LCD_Data('m'<<16);
  61:     LCD_Data(' '<<16);
  62:     LCD_Data('S'<<16);
  63:     LCD_Data('u'<<16);
  64:     LCD_Data(' '<<16);
  65:     LCD_Data('M'<<16);
  66:     LCD_Data('a'<<16);
  67:     LCD_Data('n'<<16);
  68:     
  69:     
  70:  
  71:     
  72:     while(1);        //return되면 안됨. 돌아갈 곳이 없어. 집이 없어. 
  73:  
  74:     return 0;
  75: }
  76:  
  77: void LCD_INIT(void)
  78: {
  79:     // Configure the pin in output
  80:     PIOA_OER    = CLCD_BS | CLCD_RS | CLCD_RW | CLCD_EN | LED;
  81:     // Set the PIO controller in PIO mode instead of peripheral mode
  82:     PIOA_PER    = CLCD_BS | CLCD_RS | CLCD_RW | CLCD_EN | LED;
  83:     // Disable pull-up
  84:     PIOA_PPUDR    = CLCD_BS | CLCD_RS | CLCD_RW | CLCD_EN | LED;
  85:     PIOA_CODR = 0xFF<<16;
  86: }
  87:  
  88:  
  89: //8월25일 추가...LCD관련함수제작.
  90: void LCD_Inst(unsigned int uiInst)    //LCD에 명령을 내리는 함수.
  91: {    
  92:     volatile static unsigned int iCount = 0;        //unsigned가 더 fast
  93:  
  94:     PIOA_CODR = CLCD_EN;    //CLCD 비활성
  95:     PIOA_CODR = CLCD_RS;    //CLCD instruction resgister 선택
  96:     PIOA_CODR = CLCD_RW;    //write모드
  97:     CLCD_DELAY(100000);
  98:  
  99:     PIOA_SODR = CLCD_EN;    //CLCD 활성    
 100:     CLCD_DELAY(100000);
 101:  
 102:     PIOA_SODR = uiInst;        //데이터 버스에 명령 올림.
 103:     CLCD_DELAY(100000);
 104:  
 105:     PIOA_CODR = CLCD_EN;    //CLCD 비활성
 106:     CLCD_DELAY(100000);
 107:     PIOA_CODR = 0xFF<<16;    //databus 초기화 0x00
 108:  
 109:     return ;
 110: }
 111:  
 112: void LCD_Data(unsigned int uiInst)    //LCD에 데이터를 보내는 함수.
 113: {    
 114:     volatile static unsigned int iCount = 0;        //unsigned가 더 fast
 115:  
 116:     PIOA_CODR = CLCD_EN;    //CLCD 비활성
 117:     PIOA_SODR = CLCD_RS;    //CLCD data resgister 선택, 데이터버스의 내용이 화면에 출력됨.
 118:     PIOA_CODR = CLCD_RW;    //write모드
 119:     CLCD_DELAY(100000);
 120:  
 121:     PIOA_SODR = CLCD_EN;    //CLCD 활성    
 122:     CLCD_DELAY(100000);
 123:  
 124:     PIOA_SODR = uiInst;        //데이터 버스에 명령 올림.
 125:     CLCD_DELAY(100000);
 126:  
 127:     PIOA_CODR = CLCD_EN;    //CLCD 비활성
 128:     CLCD_DELAY(100000);
 129:     PIOA_CODR = 0xFF<<16;    //databus 초기화 0x00
 130:  
 131:     return ;
 132: }
 133: