#include "3048f.h" #include "lcd.h" #include "mtask.h" #include "itu.h" #include "wastloop.h" //LCD出力形式 #define LCD_STATUS 0 //LCD・ステータス #define LCD_DATA 1 //LCD・データ #define LCD_REGS 0x10 #define LCD_ENBL 0x20 #define PIO_A_DATA P4DR #define inp(x ) (x) #define outp( x, y ) ( ( x ) = ( y ) ) static void LcdOut( char OutMode , char OutData ) ; //static void E_Strobe( void ) ; static void PortRowOut( char Data ) ; #define E_Strobe() {BitSet( PIO_A_DATA, 5 ) ;BitClr( PIO_A_DATA, 5 );} #define LcdSleep( a ) Sleep( a ) ; //static void LcdSleep( unsigned long a ) ; unsigned long LastAccessTime ; /****************************************************************************** 機能要約 LCDの初期化 機能 同上 引数 無し 戻り値 無し 注意 無し ******************************************************************************/ void ScreenInit( void ) { int i; LastAccessTime = GetTimer() ; BitSet( PIO_A_DATA, 5 ) ; for( i = 0 ; i < 3 ; i ++ ) { PortRowOut( 0x3 ) ; E_Strobe() ; LcdSleep( 5 ) ; } PortRowOut( 0x2 ) ; // set interface 4bit E_Strobe() ; LcdSleep( 5 ) ; LcdOut( LCD_STATUS, 0x28 ) ;// set interface 4bit and line and font LcdSleep( 5 ) ; LcdOut( LCD_STATUS, 0x08 ) ;// display off LcdSleep( 5 ) ; LcdOut( LCD_STATUS, 0x04 ) ;// entry mode LcdSleep( 5 ) ; ClearScreen() ; LcdOut( LCD_STATUS, 0x0c ) ;// display on LcdSleep( 5 ) ; LcdLocate( 0, 0 ) ; return; } /****************************************************************************** 機能要約 文字列を指定の長さ表示する。 機能 同上 引数 String 文字列 Length 文字列の長さ 戻り値 無し 注意 無し ******************************************************************************/ void printlen( char *String , char Length ) { for( ; Length > 0 ; Length -- ) { if( *String == 0 ) { break ; } LcdPutCh( *String ) ; //LcdSleep( 2 ) ; String ++ ; } } /****************************************************************************** 機能要約 文字列を指定の長さ表示する。 機能 同上 引数 String 文字列 Length 文字列の長さ 戻り値 無し 注意 無し ******************************************************************************/ void printlcd( char *String ) { for( ; *String != 0 ; ) { LcdPutCh( *String ) ; //LcdSleep( 2 ) ; String ++ ; } } /****************************************************************************** 機能要約 LCD画面に1文字出力する。 機能 同上 引数 Charactor 文字 戻り値 無し 注意 連続してコールする場合には、WaitMicro(12) を呼び出すこと ******************************************************************************/ void LcdPutCh( char Charactor ) { LcdOut( LCD_DATA , Charactor ) ; } /****************************************************************************** 機能要約 表示位置を指定する。 機能 同上 引数 y 縦の位置 x 横の位置 戻り値 無し 注意 無し ******************************************************************************/ void LcdLocate( char y , char x ) { if( y == 0 ) { LcdOut( LCD_STATUS , x | 0x80 ) ; } else { LcdOut( LCD_STATUS , x | 0xC0 ) ; } LcdSleep( 5 ); } /****************************************************************************** 機能要約 画面をクリアする。 機能 同上 引数 無し 戻り値 無し 注意 無し ******************************************************************************/ void ClearScreen( void ) { LcdOut( LCD_STATUS , 0x01 ) ; LcdSleep( 2 ) ; } /****************************************************************************** 機能要約 LCDにデータ出力を行う。 機能 同上 引数 OutMode 出力モード OutData 出力データ 戻り値 無し 注意 無し ******************************************************************************/ static void LcdOut( char OutMode , char OutData ) { char Ext1Status ; if( isTimeOut( LastAccessTime, 3 ) == 0 ) { LcdSleep( 2 ) ; } LastAccessTime = GetTimer() ; DisableIRQ ; Ext1Status = inp( PIO_A_DATA ) ; if( OutMode == LCD_STATUS ) { Ext1Status = ( Ext1Status & ~LCD_REGS ) ; } else { Ext1Status = ( Ext1Status | LCD_REGS ) ; } Ext1Status &= 0xf0 ; outp( PIO_A_DATA , Ext1Status | ( OutData >> 4 ) ) ; EnableIRQ ; DisableIRQ ; E_Strobe() ; //WaitMicro( 10 ) ; outp( PIO_A_DATA , Ext1Status | ( OutData & 0xf ) ) ; E_Strobe() ; //WaitMicro( 10 ) ; EnableIRQ ; } #if 0 /****************************************************************************** 機能要約 LCDに E strobe を送る 機能 同上 引数 戻り値 無し 注意 割り込み禁止の状態で呼び出すこと ******************************************************************************/ static void E_Strobe( void ) { // outp( PIO_A_DATA , inp( PIO_A_DATA ) | LCD_ENBL ) ; // outp( PIO_A_DATA , inp( PIO_A_DATA ) & ( ~LCD_ENBL ) ) ; BitSet( PIO_A_DATA, 5 ) ; BitClr( PIO_A_DATA, 5 ) ; } static void LcdSleep( unsigned long a ) { Sleep( a * 10 ) ; } #endif /****************************************************************************** 機能要約 LCDに 生のデータをセットする 機能 同上 引数 戻り値 無し 注意 割り込み禁止の状態で呼び出すこと ******************************************************************************/ static void PortRowOut( char Data ) { DisableIRQ ; outp( PIO_A_DATA, ( inp( PIO_A_DATA ) & 0xc0 ) | Data ) ; EnableIRQ ; }