Hi,
I have an LCD connected this way:
PA0 -> DB4
PA1 -> DB5
PA2 -> DB6
PA3 -> DB7
RS -> PB0
E -> PB2
It initializes fine but can't send the Clear Screen command (0x01).
Instead of recognizing it as command it display to the LCD the character 0x01.
if I send a command 0x41 I seen a 'A' letter on LCD.
The procedure to send a command is..
I send a lcd_cmd(0x01) using the following functions.
nodebug void lcd_cmd(char cmd)
{
unsigned char i;
BitWrPortI(PBDR, &PBDRShadow,0,0); //RS=0 it's a command
delay(30);
i=cmd;
cmd>>=4;
lcd_tx4(cmd);
delay(20);
lcd_tx4(i);
delay(20);
}
nodebug void lcd_tx4(char nibble)
{
nibble &= 0x0F;
WrPortI (PADR, &PADRShadow, nibble);
delay(30);
BitWrPortI(PBDR, &PBDRShadow,1,2); // Enable High
delay(30);
BitWrPortI(PBDR, &PBDRShadow,0,2); // Enable Low
delay(30);
}
I am initializing port A as
WrPortI ( PADR,&PADRShadow,0x00 ); // Assure Outputs are Low
WrPortI ( SPCR,&SPCRShadow,0x84 ); // Port A = Outputs
But I have not initialized port B, I tried
WrPortI(PBDDR, &PBDDRShadow, PBDDRShadow & 0x05);
BitWrPortI(PBDDR, &PBDDRShadow,0,0); // RS=0
BitWrPortI(PBDDR, &PBDDRShadow,0,2); // E=0
But it didn't works.
In my init procedure I am sending:
lcd_cmd(0x32); // Switch to 4-bit
lcd_cmd(0x20); // Switch to 4-bit
lcd_cmd(0x28); // Set Dual Line Display
lcd_cmd(0x06); // Disable Display Shift
lcd_cmd(0x0C); // Display On, Cursor Off
I can send any string to the LCD and I can see it but I can't clear the screen and send
the cursor Home. Also, When I send 2 string it is displayed in Line 1 and 3 (skip line
2).
I am using a 20x4 Character LCD.
Any help will be appreciated.
Regards,
Mario
------------------------------------

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )
Hi Mario,
// sample how to access LCD with RCM 2000 (Port D)
// LCD Pin 1( GND ) to Pin1 RCM2000
// 2( +5v ) to Pin2 RCM2000
// 3( Vo ) to 1k2 to +5v
// ( Vo ) to 120 to gnd
// 4( RS ) to Pin3 RCM2000
// 5( R/W ) to Pin4 RCM2000
// 6( E ) to Pin5 RCM2000
// 11( D4 ) to Pin7 RCM2000
// 12( D5 ) to Pin8 RCM2000
// 13( D6 ) to Pin9 RCM2000
// 14( D7 ) to Pin10 RCM2000
// 15( LED ) to anoda diode IN4148 and kathoda to +5v
// 16( GND ) to Pin1 RCM2000
///// delay
void delay(unsigned int wDelay) {
for (;wDelay>0;--wDelay);
}
///// 4-bit lcd command
void lcdCmd4 (char cmd4) {
WrPortI ( PADR,&PADRShadow,(cmd4&0xF8)|(PADRShadow&8) ); // Ready Nibble
WrPortI ( PADR,&PADRShadow,PADRShadow|0x04 );
// Write Nibble
delay ( 1 );
// Wait 40 uSec
WrPortI ( PADR,&PADRShadow,PADRShadow&0xFB );
}
///// 8-bit lcd command
void lcdCmd (int cmd){
lcdCmd4 ( cmd ); // Write Upper Nibble
lcdCmd4 ( cmd<<4 ); // Write Lower Nibble
delay ( 4 ); // Wait 40 uSec
}
///// place cursor at column and row
xmem lcdGoto (unsigned int col, unsigned int row) {
const static char acPos[4] = { 0x80,0xC0,0x94,0xD4 }; //4x20
//const static char acPos[4] = { 0x80,0xC0,0x90,0xD0 }; //4x16
if ((col < 20) && (row < 4))
lcdCmd ( acPos[row]+col );
}
xmem void lcdPutc (char cData){
WrPortI ( PADR,&PADRShadow,(cData&0xF0)|0x01|(PADRShadow&0x08) );
WrPortI ( PADR,&PADRShadow,PADRShadow|0x04 ); // Strobe Write
WrPortI ( PADR,&PADRShadow,PADRShadow&0xFB );
// Ready Lower Nibble
WrPortI ( PADR,&PADRShadow,((cData<<4)&0xF0)|0x01|(PADRShadow&0x08) );
WrPortI ( PADR,&PADRShadow,PADRShadow|0x04 ); // Strobe Write
WrPortI ( PADR,&PADRShadow,PADRShadow&0xFB );
WrPortI ( PADR,&PADRShadow,(PADRShadow&0x08) ); // Restore Contrast
delay ( 4 );
// Wait 40 uSec
}
///// write formatted data to lcd, similar to printf statement
void lcdPrintf (char *pcFormat,...){
doprnt ( lcdPutc,pcFormat,&pcFormat+1,NULL, NULL, NULL );
}
void LCDInit(char op){
WrPortI ( PADR,&PADRShadow,PADRShadow&0x08 ); // Set Contrast at GND
delay ( 1500 ); // Wait 15 mSec (LCD to Stabilize)
lcdCmd4 ( 0x30 ); // Set to 4-Bit Interface
delay ( 410 ); // Wait 4.1 mSec
lcdCmd4 ( 0x30 ); // Set 8-Bit Interface
delay ( 10 ); // Wait 100 uSec
lcdCmd4 ( 0x30 ); // Set 8-Bit Interface
lcdCmd4 ( 0x20 ); // Set 8-Bit Interface
lcdCmd ( 0x28 ); // 001x 1??? x=0->4bit, 1->8bit
//Set Dual Line Display
if (op==0)
lcdCmd ( 0x0c ); // 00001xxx display on, cursor
off, blink off
else
lcdCmd ( 0x0f ); // 00001xxx display On, cursor
on, blink on
lcdCmd ( 0x06 ); // 000001xx entry mode increment,
disable display shift
lcdCmd ( 0x01 ); // sisplay clear, home Cursor, backlight On
delay ( 300 ); // Wait 3 mSec
}
///// initialize port
xmem void initialize_ports() {
#asm
ld a,0x0
ioi ld (PDDCR),a
ld a,0xFF
ioi ld (PDDDR),a
#endasm
int main(){
initialize_ports();
LCDInit(0);
lcdGoto(0,3);
lcdPrintf("Test %d",1);
}
Best regard,
Erwin Yn
2009/5/11, mgonzalezrdz
:
> Hi,
>
> I have an LCD connected this way:
>
> PA0 -> DB4
> PA1 -> DB5
> PA2 -> DB6
> PA3 -> DB7
>
> RS -> PB0
> E -> PB2
>
> It initializes fine but can't send the Clear Screen command (0x01).
> Instead of recognizing it as command it display to the LCD the character
> 0x01.
>
> if I send a command 0x41 I seen a 'A' letter on LCD.
>
> The procedure to send a command is..
> I send a lcd_cmd(0x01) using the following functions.
>
> nodebug void lcd_cmd(char cmd)
> {
> unsigned char i;
> BitWrPortI(PBDR, &PBDRShadow,0,0); //RS=0 it's a command
> delay(30);
> i=cmd;
> cmd>>=4;
> lcd_tx4(cmd);
> delay(20);
> lcd_tx4(i);
> delay(20);
> }
>
> nodebug void lcd_tx4(char nibble)
> {
> nibble &= 0x0F;
> WrPortI (PADR, &PADRShadow, nibble);
> delay(30);
> BitWrPortI(PBDR, &PBDRShadow,1,2); // Enable High
> delay(30);
> BitWrPortI(PBDR, &PBDRShadow,0,2); // Enable Low
> delay(30);
> }
>
> I am initializing port A as
>
> WrPortI ( PADR,&PADRShadow,0x00 ); // Assure Outputs are Low
> WrPortI ( SPCR,&SPCRShadow,0x84 ); // Port A = Outputs
> But I have not initialized port B, I tried
> WrPortI(PBDDR, &PBDDRShadow, PBDDRShadow & 0x05);
> BitWrPortI(PBDDR, &PBDDRShadow,0,0); // RS=0
> BitWrPortI(PBDDR, &PBDDRShadow,0,2); // E=0
>
> But it didn't works.
>
> In my init procedure I am sending:
>
> lcd_cmd(0x32); // Switch to 4-bit
> lcd_cmd(0x20); // Switch to 4-bit
> lcd_cmd(0x28); // Set Dual Line Display
> lcd_cmd(0x06); // Disable Display Shift
> lcd_cmd(0x0C); // Display On, Cursor Off
>
> I can send any string to the LCD and I can see it but I can't clear the
> screen and send the cursor Home. Also, When I send 2 string it is displayed
> in Line 1 and 3 (skip line 2).
>
> I am using a 20x4 Character LCD.
>
> Any help will be appreciated.
>
> Regards,
> Mario
------------------------------------

(You need to be a member of rabbit-semi -- send a blank email to rabbit-semi-subscribe@yahoogroups.com )