EDF - OnePIC MCU  v1.1.0
source/base/OnePIC_lcd.c
Go to the documentation of this file.
00001 
00011 #include <stdio.h>
00012 #include "OnePIC_lcd.h"
00013 #include "TimeDelay.h"
00014 #include "bsp.h"
00015 #include "OnePIC_int.h" //for disabling interrupts when writing to LCD
00016 
00017 
00018 char LCDBuffer[LCD_LINES][LCD_LINE_LENGTH];
00019 
00023 void LCDStrobeEnable(void)
00024 {
00025     LCD_ENABLE = 1;
00026     Delay10us(5);
00027     //DelayMs(5);
00028     LCD_ENABLE = 0;
00029     Delay10us(5);
00030     //DelayMs(5);
00031 }
00032 
00037 void LCDLowNibPut(uint8_t data)
00038 {
00039     LCD_RS = 0;
00040     LCD_ENABLE = 1;
00041     LCD_D3 = (data & 0x08) >> 3;
00042     LCD_D2 = (data & 0x04) >> 2;
00043     LCD_D1 = (data & 0x02) >> 1;
00044     LCD_D0 = (data & 0x01);
00045     DelayMs(1);
00046     LCD_ENABLE = 0;
00047     DelayMs(1);
00048 }        
00049 
00054 void LCDDataPut(unsigned char data)
00055 {
00056 
00057     LCD_D3 = (data & 0x80) >> 7;
00058     LCD_D2 = (data & 0x40) >> 6;
00059     LCD_D1 = (data & 0x20) >> 5;
00060     LCD_D0 = (data & 0x10) >> 4;
00061     LCDStrobeEnable();
00062     DelayMs(2);
00063 
00064 
00065     LCD_D3 = (data & 0x08) >> 3;
00066     LCD_D2 = (data & 0x04) >> 2;
00067     LCD_D1 = (data & 0x02) >> 1;
00068     LCD_D0 = (data & 0x01);
00069     Delay10us(100);
00070     LCDStrobeEnable();
00071     DelayMs(2);
00072     
00073 
00074 }
00075 
00082 void LCDCommand(unsigned char command)
00083 {
00084     LCD_RS = 0;
00085     LCDDataPut(command);
00086 }
00087 
00092 void LCDPut(unsigned char character)
00093 {
00096 #if defined (__PICC__)
00097     GIE = 0;
00098 #else
00099     EDF_INT_Disable();
00100 #endif
00101     LCD_RS = 1; // Data -- not instruction
00102     LCDDataPut(character);
00103 
00104 #if defined(__PICC__)
00105     GIE = 1;
00106 #else
00107     EDF_INT_Enable();
00108 #endif
00109 }       
00110 
00119 void LCDInit(void)
00120 {
00121     LCD_D0_TRIS = 0;
00122     LCD_D1_TRIS = 0;
00123     LCD_D2_TRIS = 0;
00124     LCD_D3_TRIS = 0;
00125 
00126     LCD_RS_TRIS = 0;
00127     LCD_RS              = 0;    
00128 
00129     LCD_ENABLE_TRIS = 0;
00130     LCD_ENABLE      = 0;
00131 
00132 
00133     LCDLowNibPut(0x03);
00134     LCDLowNibPut(0x03);
00135     LCDLowNibPut(0x03);
00136     LCDLowNibPut(0x02);
00137     LCDLowNibPut(0x02);
00138     LCDLowNibPut(0x0C);
00139     LCDLowNibPut(0x00);
00140     LCDLowNibPut(0x08);
00141     LCDLowNibPut(0x00);
00142     LCDLowNibPut(0x01);
00143     LCDLowNibPut(0x00);
00144     LCDLowNibPut(0x06);
00145 
00146 
00147     LCDCommand( FUNCTION_SET | FOUR_BITS | TWO_LINES | FIVEXEIGHT );
00148     LCDCommand( DISPLAY_CONTROL | DISPLAY_ON | CURSOR_OFF | BLINKING_OFF );
00149     LCDCommand( ENTRY_MODE_SET | INCREMENT | SHIFT_OFF);
00150 
00151 
00152     LCDCommand(CLEAR_DISPLAY);
00153     LCDCommand(RETURN_HOME);
00154 
00155 }
00156 
00163 void LCDUpdate(void)
00164 {
00165 
00166     uint8_t cursPos;
00167     //uint8_t i,j;
00168 
00169     LCDCommand(RETURN_HOME);
00170 
00171     for( cursPos = 0; cursPos < LCD_LINE_LENGTH; cursPos++ )
00172     {
00173         if(LCDBuffer[0][cursPos] == '\0'){break;}
00174         LCDPut(LCDBuffer[0][cursPos]);
00175 
00176     }
00177     LCDCommand(SET_DDRAM_ADDR|40);
00178     for( cursPos = 0; cursPos < LCD_LINE_LENGTH; cursPos++ )
00179     {
00180         if(LCDBuffer[1][cursPos] == '\0'){break;}
00181         LCDPut(LCDBuffer[1][cursPos]);
00182 
00183     }
00184     /*
00185     for( i = 0; i < LCD_LINES; i++)
00186         for( j = 0; j < LCD_LINE_LENGTH; j++)
00187             LCDBuffer[i][j] = '\0';*/
00188 
00189 
00190 } 
00191