CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Please see my sourcecode. it is about lcd.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
a
Guest







Please see my sourcecode. it is about lcd.
PostPosted: Fri Aug 13, 2004 3:40 am     Reply with quote

this code is use for lcd 16*2 char. but when i start my program it isn't stable because sometime lcd show 1 line.sometime show 2 line. but when it show 2 line. it will show 2 line forever. but if it show 1 line. it will show 1 line forever too.
Please see my code and correct it should be. thannk you

i use lcd in mode
#define RS PIN_E0
#define RW PIN_E1
#define EN PIN_E2

and port d0-d7 is also data0-data7 of lcd too.

i think it about void init_lcd(void) procedure but i don't know. where it's not correct.

thank you for your help


#include "C:\Micropro\SourceCode_Picc\Charger\CH6.h"

#ZERO_RAM

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

#define RS PIN_E0
#define RW PIN_E1
#define EN PIN_E2

#define leddison output_high(pin_c0)
#define leddisoff output_low(pin_c0)

char tmpshow[20];
int resetch1=0;

//===============
void busy_strobe(void)
{
OUTPUT_LOW(EN);
delay_us(1);
OUTPUT_HIGH(EN);
delay_us(1);
}

void write_strobe(void)
{
OUTPUT_HIGH(EN);
delay_us(1);
OUTPUT_LOW(EN);
delay_ms(2);
}

void Command(void)
{
OUTPUT_LOW(RS);
OUTPUT_LOW(RW);
}

void wait_for_lcd_ready(void)
{
unsigned char busy_flag;

SET_TRIS_D(0XFF); //PORTD7 INPUT;
OUTPUT_LOW(RS); //SET FOR READ BUSY;
OUTPUT_HIGH(RW); //SET FOR READ BUSY;

busy_strobe();
busy_flag=(input_d() & 0x80);

while( busy_flag == 0x80)
{
OUTPUT_LOW(EN);
busy_flag=(input_d()&0x80);
}

OUTPUT_LOW(EN);

SET_TRIS_D(0x00); //PORTD7 OUTPUT;

}

void clear_lcd(void)
{
Command();
OUTPUT_D(0x01);
write_strobe();
wait_for_lcd_ready();
}

void cursor_off(void)
{
Command();
OUTPUT_D(0x0c);
write_strobe();
wait_for_lcd_ready();
}
void init_lcd(void)
{
Command();
OUTPUT_D(0x38);
write_strobe();
wait_for_lcd_ready();

Command();
OUTPUT_D(0x0f);
write_strobe();
wait_for_lcd_ready();

clear_lcd();

Command();
OUTPUT_D(0x02);
write_strobe();
wait_for_lcd_ready();

cursor_off();
}

void Wchar(unsigned char char_)
{
OUTPUT_HIGH(RS);
OUTPUT_LOW(RW);

OUTPUT_D(char_);
write_strobe();
wait_for_lcd_ready();
}

void gotoxy(unsigned char row,unsigned char col)
{
Command();
if (row==1) OUTPUT_D(0x80+col-1);
else
if (row==2) OUTPUT_D(0xc0+col-1);
write_strobe();
wait_for_lcd_ready();
}

void Wcharxy(unsigned char row,unsigned char col,unsigned char data_)
{
gotoxy(row,col);
Wchar(data_);
}

void string_to_lcd(unsigned char row,unsigned char col,unsigned char *st)
{
unsigned char i,len;

len=strlen(st);
if (len>20) len=20;
gotoxy(row,col);
for(i=0;i<=len-1;i++)
{
Wchar(st[i]);
}
}

void int_to_lcd(unsigned char row,unsigned char col,int data_int)
{
unsigned char str[7];

sprintf(str,"%d",data_int);
string_to_lcd(row,col,str);
}

void long_to_lcd(unsigned char row,unsigned char col,long data_long)
{
unsigned char str[7];

sprintf(str,"%ld",data_long);
string_to_lcd(row,col,str);
}

void hex_to_lcd(unsigned char row,unsigned char col,unsigned char data_hex)
{
unsigned char str[3];

sprintf(str,"%x",data_hex);
string_to_lcd(row,col,str);
}

void float_to_lcd(unsigned char row,unsigned char col,float data_float)
{
unsigned char str[7];

sprintf(str,"%02.1f",data_float);
string_to_lcd(row,col,str);
}
Guest








PostPosted: Fri Aug 13, 2004 5:12 am     Reply with quote

Port E is analog input unless you explicitly set it to NO_ANALOG.
Your output_low() and output_high() calls are never executed.
a
Guest







PostPosted: Fri Aug 13, 2004 7:16 am     Reply with quote

i set port e is output and port d is input/output in wizard. and thank you for your answer
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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