|
|
View previous topic :: View next topic |
Author |
Message |
eleceyes Guest
|
ASM and C for LCD |
Posted: Wed Feb 20, 2008 10:31 am |
|
|
I feel strange with code for Lcd
In asm, I found may persons use these codes to write char on lcd
for e.g
movlw 41 ; 'A' character
bsf lcd_rs ; RS to 1
bcf lcd_rw ; RW to 0
movwf port_b ; Put character on data lines
call pulse_e ; lcd enable line on then off
call short_delay ; 5ms for example
I almost do the same in C, like this
void WrDat2Lcd(int data)
{
output_high(lcd_rs);
output_low(lcd_rw);
output_d(data);
LcdEnable();
delay_ms(5);
}
but the lcd doesn't show anything, unless I add more code for it (and lcd run), like this
void WrDat2Lcd(int data)
{
output_low(lcd_rs); //added
output_high(lcd_rs);
output_low(lcd_rw);
output_d(data);
LcdEnable();
output_high(lcd_e); //added
delay_ms(5);
}
While wondering, I try to view .lst file
I saw these
.................... output_high(lcd_rs);
002F: BSF 03.5
0030: BCF 06.0
0031: BCF 03.5
0032: BSF 06.0
I just think that it only need one line like "bsf lcd_rs ; RS to 1"
try to replace by output_bit(lcd_rs,1) then
.................... output_bit(lcd_rs,1);
0023: BSF 06.0
0024: BSF 03.5
0025: BCF 06.0
I don't sure about 06 or 03, maybe they are stand for PORT B and PORT ?, bit 0 and bit 5 ???
But could you tell me why it need 3 to 4 commands like that ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 20, 2008 1:42 pm |
|
|
The compiler inserts code to set the correct TRIS automatically.
That's what those lines are doing. That's why the compiler is
popular with students and professors. The student doesn't have
to figure out how to set the TRIS. The compiler does it.
If you want to handle the TRIS by yourself, then specify fast i/o mode,
and set the TRIS with a line of code. See the CCS manual. |
|
|
smiles
Joined: 20 Feb 2008 Posts: 33
|
|
Posted: Wed Feb 20, 2008 7:13 pm |
|
|
eleceyes is me, could you tell me what are they stand for, 03 and 06 ?
This is the first time I saw them
Thanks !!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
smiles
Joined: 20 Feb 2008 Posts: 33
|
|
Posted: Thu Feb 21, 2008 3:17 am |
|
|
Thanks, I think they are the same now.
And here is the problem that I get at the moment, you can see it in comment part of main function void main(){...}
If you know the reason for it, please let me know, thanks so much
Code: |
// MNEMONICS FOR BUTTONS
// MNEMONICS FOR LCD
#define lcd_rs PIN_B0
#define lcd_rw PIN_B1
#define lcd_e PIN_B2
#define lcd_cmd_wri 0x00
#define lcd_data_wri 0x01
#define lcd_busy_rd 0x02
#define lcd_set_function 0x38 //8 bit interface, 2 line mode, 5x7 dot format
#define lcd_set_visible 0x0F //Display on, cursor underline on, cursor blink on
#define lcd_set_shift 0x16 //Cursor move, Right shift
#define lcd_set_mode 0x06 //Increment, display shift off
#define lcd_set_cgaddr 0x40
#define lcd_set_ddaddr 0x80
#define lcd_clr 0x01
#define lcd_init 0x30
#include "D:\Pic\Doit\Doit.h"
void InitPic();
void LcdEnable();
void WrCmd2Lcd(int cmd);
void WrDat2Lcd(int data);
void InitLcd();
void Speech(int *words,int position);
void LcdWait();
int OnRelease();
void main()
{
//INTRO OR GUIDED WORDS
int hello[]="HELLO WORLD! ";
int keyPressed,key;
int array[17]={0,0x31,0x34,0x37,0x3C,0x32,0x35,0x38,0x30,0x33,0x36,0x39,0x3E,0x43,0x26,0x45,0x4D};
// TODO: USER CODE!!
InitPic();
InitLcd();
delay_ms(500);
WrDat2Lcd(array[1]); // this character appears ok
key=2;
WrDat2Lcd(array[key]); // this character appears ok
WrDat2Lcd('A'); // this character appears ok
WrDat2Lcd('B'); // this character appears ok
Speech(hello,lcd_set_ddaddr+0x40); // this string also appears ok
play:
keyPressed=OnRelease();
if (keyPressed == 0) // if no key is pressed
goto play; // then check again
WrDat2Lcd(array[keyPressed]); // else make it appear on LCD
// but it appear a dark square or strange character
// if I add one line WrDat2Lcd(any char here);
// after available WrDat2Lcd(array[keyPressed]);
// I can see a dark square (or strange character)
// together with the right character as I expect ??? What wrong ???
goto play;
}
//**********************
void InitPic()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
output_b(0x00);
output_d(0x00);
}
//**********************
void LcdEnable()
{
output_high(lcd_e);
output_low(lcd_e);
delay_ms(5);
}
//**********************
void WrCmd2Lcd(int cmd)
{
output_low(lcd_rs);
output_d(cmd);
LcdEnable();
output_high(lcd_rs);
}
//**********************
void WrDat2Lcd(int data)
{
output_low(lcd_rs); //added
output_high(lcd_rs);
output_d(data);
LcdEnable();
output_low(lcd_rs);
output_high(lcd_e); //added
delay_ms(5);
}
//**********************
void InitLcd()
{
delay_ms(125);
WrCmd2Lcd(lcd_init);
delay_ms(20);
LcdEnable();
delay_us(200);
LcdEnable();
delay_us(100);
WrCmd2Lcd(lcd_set_function);
delay_ms(10);
WrCmd2Lcd(lcd_set_visible);
delay_ms(10);
WrCmd2Lcd(lcd_clr);
delay_us(100);
WrCmd2Lcd(lcd_set_ddaddr);
delay_us(100);
}
//*************************
void Speech(int *words,int position)
{
int *textptr;
textptr = words;
WrCmd2Lcd(position);
do
{
WrDat2Lcd(*textptr);
*textptr++;
}
while(*textptr != '\0');
}
//**********************
void LcdWait()
{
int status;
set_tris_d(0xFF);
output_low(lcd_rs);
output_high(lcd_rw);
delay_us(1);
do
{
output_high(lcd_e);
delay_us(1);
status=input_d();
output_low(lcd_e);
delay_us(2);
}
while(status & 0x80); // test busy flag.
}
//*************************
int OnRelease() // check which key of keypad is pressed
{
int i,j,k;
int value[4]={0x07,0x0B,0x0D,0x0E};
set_tris_a(0x0f);
k=1;
for(i=0;i<4;i++)
{
output_d(value[i]);
delay_us(100);
for(j=0;j<4;j++)
{
if(!input(40+j))
{
do
{
delay_ms(400);
}
while(!input(40+j));
return k;
}
else
k++;
}
}
return 0;
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 21, 2008 12:39 pm |
|
|
Please post your #include, #fuses or #use statements, and your
compiler version and the manufacturer and part number of your LCD,
and the list of hardware connections, etc. |
|
|
smiles
Joined: 20 Feb 2008 Posts: 33
|
|
Posted: Thu Feb 21, 2008 7:58 pm |
|
|
Hi I did it last night, don't sure the reason why but I change a little in WrDat2Lcd()
void WrDat2Lcd(int data)
{
output_low(lcd_rs); //added
output_high(lcd_rs);
output_d(data);
LcdEnable();
output_high(lcd_e); //added
output_low(lcd_rs);
delay_ms(1);
}
My LCD is of EPSON manufactor, do you think that it follows HD44780 principles of Hitachi ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 21, 2008 8:01 pm |
|
|
I don't know. I am giving up on this. |
|
|
smiles
Joined: 20 Feb 2008 Posts: 33
|
|
Posted: Thu Feb 21, 2008 10:15 pm |
|
|
anyway, thank you so much |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|