lcm.h File Reference

Go to the source code of this file.

Data Structures

struct  LCM_CONTROL

Defines

#define LCM_COMMAND   0
#define LCM_DATA   1

Functions

void LcmInit (void)
void LcmCommandWrite (INT8U Command)
void LcmDramWrite (INT8U Data)
void LcmIsr (void)
INT8U LcmStateGet (void)
ERROR LcmUpdate (INT8U *pLcmData, INT8U DataType)
void LcmSvc (void)

Variables

INT8U LcmClean []
INT8U LcmInitialCommand0 []
INT8U Lcm1stLineStart []
INT8U Lcm2ndLineStart []
INT8U LcmBuffer []
LCM_CONTROL LcmCtrl


Define Documentation

#define LCM_COMMAND   0

Definition at line 4 of file lcm.h.

#define LCM_DATA   1

Definition at line 5 of file lcm.h.


Function Documentation

void LcmCommandWrite ( INT8U  Command  ) 

Definition at line 137 of file lcm.c.

00137                                    {
00138     LcmRw=0;                // Read 1/ write 0
00139     LcmRw=0; 
00140     LcmRw=0; 
00141     LcmRs=0;                // Select command register 
00142     LcmRs=0;
00143     LcmRs=0;
00144     if(Command&0x01) LcmData0=1;
00145     else LcmData0=0;
00146     if(Command&0x02) LcmData1=1;
00147     else LcmData1=0;
00148     if(Command&0x04) LcmData2=1;
00149     else LcmData2=0;
00150     if(Command&0x08) LcmData3=1;
00151     else LcmData3=0;
00152     LcmEn=1;
00153     LcmEn=1;
00154     LcmEn=1;
00155     LcmEn=0;
00156     LcmEn=0;
00157     LcmEn=0;
00158 }

void LcmDramWrite ( INT8U  Data  ) 

Definition at line 160 of file lcm.c.

00160                              {
00161     LcmRw=0;                // Read 1/ write 0
00162     LcmRw=0; 
00163     LcmRw=0; 
00164     LcmRs=1;                // lcm dram
00165     LcmRs=1;
00166     LcmRs=1;
00167     if(Data&0x01) LcmData0=1;
00168     else LcmData0=0;
00169     if(Data&0x02) LcmData1=1;
00170     else LcmData1=0;
00171     if(Data&0x04) LcmData2=1;
00172     else LcmData2=0;
00173     if(Data&0x08) LcmData3=1;
00174     else LcmData3=0;
00175     LcmEn=1;
00176     LcmEn=1;
00177     LcmEn=1;
00178     LcmEn=0;
00179     LcmEn=0;
00180     LcmEn=0;
00181 }

void LcmInit ( void   ) 

Definition at line 42 of file lcm.c.

00042                   {
00043     TRISJ=0;
00044     TRISB=0;
00045 
00046     LcmData0=1;
00047     LcmData1=1;
00048     LcmData2=1;
00049     LcmData3=1;
00050     LcmBackLightEn=1;
00051     LcmRs=1;
00052     LcmRw=1;
00053     LcmEn=1;
00054 
00055     LcmCtrl.HasData=FALSE;
00056     LcmCtrl.Length=0;
00057     LcmCtrl.Timer=200;
00058     LcmCtrl.State=LcmIdleState;
00059     LcmCtrl.SubState=LcmHigh4bitSubstate;
00060 }

void LcmIsr ( void   ) 

INT8U LcmStateGet ( void   ) 

Definition at line 66 of file lcm.c.

00066                        {
00067     return LcmCtrl.State;
00068 }

void LcmSvc ( void   ) 

Definition at line 106 of file lcm.c.

00106                  {
00107     if(LcmCtrl.HasData==FALSE) return; // prevent previous command not finished
00108     if(LcmCtrl.Timer!=0) return;       // prevent previous command not finished
00109     LcmCtrl.Timer=10;
00110     if(LcmCtrl.DataType==LCM_COMMAND){
00111         if(LcmCtrl.SubState==LcmHigh4bitSubstate){
00112             LcmCommandWrite((*LcmCtrl.pData&0xf0)>>4);
00113             LcmCtrl.SubState=LcmLow4bitSubstate;
00114         }
00115         else{
00116             LcmCommandWrite(*LcmCtrl.pData&0x0f);
00117             LcmCtrl.Length--;
00118             LcmCtrl.pData++;
00119             LcmCtrl.SubState=LcmHigh4bitSubstate;
00120         }
00121     }
00122     else{
00123         if(LcmCtrl.SubState==LcmHigh4bitSubstate){
00124             LcmDramWrite((*LcmCtrl.pData&0xf0)>>4);
00125             LcmCtrl.SubState=LcmLow4bitSubstate;
00126         }
00127         else{
00128             LcmDramWrite(*LcmCtrl.pData&0x0f);
00129             LcmCtrl.Length--;
00130             LcmCtrl.pData++;
00131             LcmCtrl.SubState=LcmHigh4bitSubstate;
00132         }
00133     }
00134     if(LcmCtrl.Length==0) LcmCtrl.HasData=FALSE; 
00135 }

ERROR LcmUpdate ( INT8U pLcmData,
INT8U  DataType 
)

Definition at line 74 of file lcm.c.

00074                                                {
00075     INT8U Length;
00076     const INT8U *pData;     
00077 
00078     if(LcmCtrl.State!=LcmIdleState){
00079          DebugStringPrint("\r\n Lcm0 error");
00080          return IS_ERROR;
00081     }
00082     pData=pLcmData;
00083     for(Length=0;Length<50;){
00084         if(*pData!=0){
00085             Length++;
00086             pData++;
00087         }
00088         else break;
00089     }
00090     if(Length>=50){ // length too long
00091          DebugStringPrint("\r\n Lcm1 error");
00092          return IS_ERROR;
00093     } 
00094     LcmCtrl.DataType=DataType;
00095     LcmCtrl.Length=Length;
00096     LcmCtrl.pData=pLcmData;    
00097     LcmCtrl.SubState=LcmHigh4bitSubstate;
00098     LcmCtrl.State=LcmUpdateState;
00099     TMR1ON=0;                // stop timer 1
00100     LcmCtrl.HasData=TRUE;
00101     TMR1ON=1;                // start timer 1
00102     while(LcmStateGet()!=0) LcmSvc();
00103     return NO_ERROR;
00104 }


Variable Documentation

Definition at line 32 of file lcm.c.

Definition at line 33 of file lcm.c.

Definition at line 35 of file lcm.c.

Definition at line 30 of file lcm.c.

Definition at line 36 of file lcm.c.

Definition at line 31 of file lcm.c.


Generated on Tue Jul 7 20:39:55 2009 for A SIMPLE APPLICATION FOR PIC18F87J10 by  doxygen 1.5.9