본문 바로가기
코스웨어/12년 내장형하드웨어

[정교한 카운터] 수정본입니다. -정철

by 알 수 없는 사용자 2012. 11. 27.
728x90
반응형
volatile unsigned int ucCnt;
void US_Delay(unsigned int ucUSec)
{
  for(ucCnt=0 ; ucCnt< ucUSec ; ++ucCnt)  //  4 cycle
  {
     asm ("nop");      // +1 cycle
   asm ("nop");      // +1 cycle
   
   asm ("nop");      // +1 cycle
   asm ("nop");      // +1 cycle
   
   asm ("nop");      // +1 cycle
   asm ("nop");      // +1 cycle
   
   asm ("nop");      // +1 cycle
   asm ("nop");      // +1 cycle

    asm ("nop");      // +1 cycle
   asm ("nop");      // +1 cycle

    asm ("nop");      // +1 cycle
   asm ("nop");      // +1 cycle

  }
  
  return ;
}


void LCD_init(void)
{
   MDelay(30);
   DDRC = 0xFF;                              
  DDRA = DDRA | (1 << EN) | (1 << RW) | (1 << RS);      /* 출력 세팅 */      
  
  LCD_INST(FUNC_SET);        //0x38
  MDelay(5);
  LCD_INST(ENTRY_MODE);    //0x06
  US_Delay(1);  //1 usec  
  LCD_INST(CURSOR_DIS);    //0x1C
  US_Delay(1);  //1 usec  
  LCD_INST(DISPLAY_ONOFF);  //0x0C
  US_Delay(1);  //1 usec  
  LCD_INST(CLEAR_DIS);    //0x01
  MDelay(2);
  LCD_INST(RETURN_HOME);    //0x02
  MDelay(2);
    
    return ;
}

void LCD_INST(unsigned char UCinst)
{
  LCD_BUS = 0x00;
  LCD_CTR = 0x00;                       //All Low
  
  US_Delay(220);  //1 usec          //1 usec delay
  
  LCD_CTR = LCD_CTR | (1 << EN);         //EN High : CPU특성생각하셈
  

  US_Delay(220);                //PWeh - Tdsw delay (160 ns)
  
  LCD_BUS = UCinst;              //DATA Exchange
  
  US_Delay(220);                //T_DSW delay (min 60ns)
  
  LCD_CTR = LCD_CTR & (~(1 << EN));      //EN Lows
  
  US_Delay(220);                //tEF + tH delay (max 25 ns + min 10 ns)
  
  return ;
}

void LCD_DATA(unsigned char UCinst)
{
  LCD_BUS = 0x00;
  LCD_CTR = (1 << RS);                       //All Low
  
  US_Delay(220);  //1 usec          //1 usec delay
  
  LCD_CTR = LCD_CTR | (1 << EN);         //EN High : CPU특성생각하셈
  
  US_Delay(220);                //PWeh - Tdsw delay (160 ns)
  
  LCD_BUS = UCinst;              //DATA Exchange
  
  US_Delay(220);                //T_DSW delay (min 60ns)
  
  LCD_CTR = LCD_CTR & (~(1 << EN));      //EN Lows
  
  US_Delay(220);                //tEF + tH delay (max 25 ns + min 10 ns)
  
  return ;
}


728x90