attempt to reduce space usage
- remove unecessary code - ifdef "extra" code - pass data through globals instead of functions accessing static data - functions non-reentrant, locate tmps in xdata
This commit is contained in:
88
src/lcd.c
88
src/lcd.c
@ -29,9 +29,6 @@
|
||||
|
||||
|
||||
static int row, col;
|
||||
static int OpenFlag = 0;
|
||||
static int ErrorTimeout = 0;
|
||||
static int Error = 0;
|
||||
|
||||
#define CLEAR_BIT(port, bit) (port &= ~(_BV(bit)))
|
||||
#define CLEAR_BITS(port, bits) (port &= ~(bits))
|
||||
@ -112,7 +109,6 @@ static char readBusy() {
|
||||
return busy;
|
||||
}
|
||||
|
||||
//sets ErrorTimeout flag if busy signal not cleared in time
|
||||
static void wait_busy() {
|
||||
unsigned int i;
|
||||
for (i = 0; i < 100; i++){
|
||||
@ -122,7 +118,6 @@ static void wait_busy() {
|
||||
_delay_ms(1);
|
||||
}
|
||||
|
||||
ErrorTimeout = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -148,49 +143,39 @@ static void LCD_OutChar(unsigned char c) {
|
||||
}
|
||||
|
||||
void LCD_Open(void) {
|
||||
static int open_error = 0;
|
||||
if (!OpenFlag) {
|
||||
//set ports to push-pull output M[1:0] = b01
|
||||
//P2 entire port
|
||||
P2M1 = 0;
|
||||
P2M0 = 0xff;
|
||||
//P3 pins 7:4
|
||||
P3M1 &= ~(0xf0);
|
||||
P3M0 |= (0xf0);
|
||||
//set ports to push-pull output M[1:0] = b01
|
||||
//P2 entire port
|
||||
P2M1 = 0;
|
||||
P2M0 = 0xff;
|
||||
//P3 pins 7:4
|
||||
P3M1 &= ~(0xf0);
|
||||
P3M0 |= (0xf0);
|
||||
|
||||
_delay_ms(30); // to allow LCD powerup
|
||||
outCsrBlindNibble(0x03); // (DL=1 8-bit mode)
|
||||
_delay_ms(5); // blind cycle 5ms wait
|
||||
outCsrBlindNibble(0x03); // (DL=1 8-bit mode)
|
||||
_delay_us(100); // blind cycle 100us wait
|
||||
outCsrBlindNibble(0x03); // (DL=1 8-bit mode)
|
||||
_delay_us(100); // blind cycle 100us wait (not called for, but do it anyway)
|
||||
outCsrBlindNibble(0x02); // DL=1 switch to 4 bit mode (only high 4 bits are sent)
|
||||
_delay_us(100); // blind cycle 100 us wait
|
||||
//set increment, no shift
|
||||
outCsrBlind(0x4 + LCDINC + LCDNOSHIFT);
|
||||
_delay_ms(30); // to allow LCD powerup
|
||||
outCsrBlindNibble(0x03); // (DL=1 8-bit mode)
|
||||
_delay_ms(5); // blind cycle 5ms wait
|
||||
outCsrBlindNibble(0x03); // (DL=1 8-bit mode)
|
||||
_delay_us(100); // blind cycle 100us wait
|
||||
outCsrBlindNibble(0x03); // (DL=1 8-bit mode)
|
||||
_delay_us(100); // blind cycle 100us wait (not called for, but do it anyway)
|
||||
outCsrBlindNibble(0x02); // DL=1 switch to 4 bit mode (only high 4 bits are sent)
|
||||
_delay_us(100); // blind cycle 100 us wait
|
||||
//set increment, no shift
|
||||
outCsrBlind(0x4 + LCDINC + LCDNOSHIFT);
|
||||
#ifdef DEBUG
|
||||
//set display on, cursor on, blink on:
|
||||
outCsrBlind(0x0c + LCDCURSOR + LCDBLINK);
|
||||
//set display on, cursor on, blink on:
|
||||
outCsrBlind(0x0c + LCDCURSOR + LCDBLINK);
|
||||
#else
|
||||
//set display on, cursor and blink off:
|
||||
outCsrBlind(0x0c + LCDNOCURSOR + LCDNOBLINK);
|
||||
//set display on, cursor and blink off:
|
||||
outCsrBlind(0x0c + LCDNOCURSOR + LCDNOBLINK);
|
||||
#endif
|
||||
//set display shift on and to the right
|
||||
outCsrBlind(0x10 + LCDNOSCROLL + LCDRIGHT);
|
||||
//set 4-bit mode, 2 line, 5x7 display:
|
||||
outCsrBlind(0x20 + LCD2LINE + LCD7DOT);
|
||||
//clear display
|
||||
LCD_Clear();
|
||||
_delay_ms(50);
|
||||
if (!readBusy()) {
|
||||
OpenFlag = 1;
|
||||
} else {
|
||||
open_error = 1;
|
||||
}
|
||||
} else { //display already open
|
||||
open_error = 1;
|
||||
}
|
||||
//set display shift on and to the right
|
||||
outCsrBlind(0x10 + LCDNOSCROLL + LCDRIGHT);
|
||||
//set 4-bit mode, 2 line, 5x7 display:
|
||||
outCsrBlind(0x20 + LCD2LINE + LCD7DOT);
|
||||
//clear display
|
||||
// LCD_Clear();
|
||||
// _delay_ms(50);
|
||||
}
|
||||
|
||||
//row and columns indexed from 0
|
||||
@ -199,8 +184,6 @@ void LCD_GoTo(unsigned int row_to, unsigned int col_to) {
|
||||
outCsr(0x80 + 0x40 * row_to + col_to); //set ddram address to position
|
||||
row = row_to;
|
||||
col = col_to;
|
||||
} else {
|
||||
Error = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,19 +250,8 @@ void LCD_OutNibble(uint8_t x){
|
||||
}
|
||||
|
||||
void LCD_Clear() {
|
||||
if (OpenFlag) {
|
||||
outCsr(0x01);
|
||||
} else {
|
||||
outCsrBlind(0x01);
|
||||
}
|
||||
outCsr(0x01);
|
||||
row = 0;
|
||||
col = 0;
|
||||
}
|
||||
|
||||
unsigned char LCD_Timeout_Error(void) {
|
||||
if (ErrorTimeout != 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user