treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Jun 02, 2004 7:45 am |
|
|
here is what I came up with. I just made some mods to other dirvers.
drop it in the drivers subdirectory and include it in the *.h files
Code: |
///////////////////////////////////////////////////////////////////////////
//// PICDEM2_LCD.C ////
//// Driver for common PICDEM2 PLUS LCD modules ////
//// ////
//// lcd_init() Must be called before any other function. ////
//// ////
//// lcd_putc(c) Will display c on the next position of the LCD. ////
//// The following have special meaning: ////
//// \f Clear display ////
//// \n Go to start of second line ////
//// \b Move back one position ////
//// ////
//// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1) ////
//// ////
//// lcd_getc(x,y) Returns character at position x,y on LCD ////
//// ////
///////////////////////////////////////////////////////////////////////////
#define use_PICDEM2_lcd TRUE
#if defined use_PICDEM2_lcd
#define lcd_en PIN_A1
#define lcd_rw PIN_A2
#define lcd_rs PIN_A3
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the second line
#define d_cycle 1
#endif
void lcd_send_nibble( BYTE n ) {
n=n&0x0f; //Strip off the top 4 bits.. This only sends bit 3:0
output_d(n);
delay_cycles(d_cycle);
output_high(lcd_en);
delay_us(20);
output_low(lcd_en);
}
BYTE lcd_read_byte() {
BYTE low,high;
output_high(lcd_rw);
delay_cycles(d_cycle);
output_high(lcd_en);
delay_cycles(d_cycle);
high = input_d(); //using d0:d3 for 4 bit data bus
output_low(lcd_en);
delay_cycles(d_cycle);
output_high(lcd_en);
delay_us(1);
low = input_d(); //using d0:d3 for 4 bit data bus
output_low(lcd_en);
return((high<<4) | low);
}
void lcd_send_byte( BYTE A0, BYTE n ) { //A0: 0=instruction, 1=Data
output_low(lcd_rs);
while ( bit_test(lcd_read_byte(),7) ) ; // wait until busy flag is low
if (A0==0){ output_low(lcd_rs);} //0=Instruction and 1=Data
if (A0==1){output_high(lcd_rs);} //0=Instruction and 1=Data
delay_cycles(d_cycle);
output_low(lcd_rw);
delay_cycles(d_cycle);
output_low(lcd_en);
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
void lcd_init() {
BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
// These bytes need to be sent to the LCD for initialization.
BYTE i;
//fprintf(debug,"Init!!\n\r");
output_low(lcd_rs);
output_low(lcd_rw);
output_low(lcd_en);
delay_ms(15);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5);
}
lcd_send_nibble(2);
for(i=0;i<=3;++i){
lcd_send_byte(0,LCD_INIT_STRING[i]);
}
}
void lcd_gotoxy( BYTE x, BYTE y) {
BYTE Data;
if(y!=1)
Data=lcd_line_two;
else
Data=0;
Data+=x-1;
lcd_send_byte(0,0x80|Data);
}
void lcd_putc( char c) {
switch (c) {
case '\f' :
lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n' :
lcd_gotoxy(1,2);
break;
case '\b' :
lcd_send_byte(0,0x10);
break;
default :
lcd_send_byte(1,c);
break;
}
}
char lcd_getc( BYTE x, BYTE y) {
char value;
lcd_gotoxy(x,y);
while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low
output_high(lcd_rs);
value = lcd_read_byte();
output_low(lcd_rs);
return(value);
}
|
|
|