help please in this code

General discussion on mikroC.
Post Reply
Author
Message
Eng_Bandar
Posts: 65
Joined: 04 Jun 2010 01:13

help please in this code

#1 Post by Eng_Bandar » 04 Jun 2010 03:01

I simulated the following circuit by proteus

Image

my project if press the switch the message in LCD will appear but here the message appear before pressing Why? What is the problem ?
this is my code in MikroC

Code: Select all

char *text = "Hello world";
void main(){
TRISD=0xff;
while(1){
       if(portd.f0==0){
                       Lcd_Init(&PORTB);
                       Lcd_Cmd(LCD_CURSOR_OFF);
                       Lcd_Out(2,1,text);
                      }
        }
}

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

Re: help please in this code

#2 Post by Sobrietytest » 04 Jun 2010 13:09

Try this...

Code: Select all

char *text = "Hello world";

void main(){

TRISD = 0xff;
Lcd_Init(&PORTB);
Lcd_Cmd(_LCD_CLEAR);

while(1){
       if(portd.f0 == 0){
					   Lcd_Cmd(LCD_CURSOR_OFF);
                       Lcd_Out(2,1,text);
                      }
		else{
			Lcd_Cmd(_LCD_CLEAR);
			}
        }
}

Eng_Bandar
Posts: 65
Joined: 04 Jun 2010 01:13

Re: help please in this code

#3 Post by Eng_Bandar » 04 Jun 2010 15:35

I tried your code come this error

Image

basicbasic111
Posts: 127
Joined: 26 Jan 2010 17:01

Re: help please in this code

#4 Post by basicbasic111 » 04 Jun 2010 17:43

r u using 16f877?


hmmmmmmmm

I only changed Sobrie's code to c pro 3.8

everything worked perfectly on my latest version of proteus


by the way two of your diagrams are tiny

i cannot see them clearly



I only changed these few parts for c pro 3.8



1

Code: Select all

sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

2

Code: Select all

Lcd_Init();

3.

Code: Select all

Lcd_Cmd(_LCD_CURSOR_OFF);
with a (_) within


that's it


I am sure we can work this out.


Please tell me which pic you are using

and which version of c you are using too


I will try to use the old version of c and make it work for you

Eng_Bandar
Posts: 65
Joined: 04 Jun 2010 01:13

Re: help please in this code

#5 Post by Eng_Bandar » 04 Jun 2010 19:35

^^^^^^^^
Thank guys for your helping

I use pic16f877

about version of mikroc

mikroC, mikroElektronika C compiler
for Microchip PIC microcontrollers
Version: 8.1.0.0

about error

Image

about connection ( may find error from connection )

Image

basicbasic111
Posts: 127
Joined: 26 Jan 2010 17:01

Re: help please in this code

#6 Post by basicbasic111 » 04 Jun 2010 20:30

working code :

Code: Select all

char *text = "Hello world";

void main() {

TRISD = 0xff;
Lcd_Init(&PORTB);
Lcd_Cmd(LCD_CLEAR);

while(1){
       if(portd.f0 == 0){
                  Lcd_Cmd(LCD_CURSOR_OFF);
                       Lcd_Out(2,1,text);
                      }
      else{
         Lcd_Cmd(LCD_CLEAR);
         }
        }
}


settings default 8M external


Change your lcd connections as follows


Lcd_Init(&PORTB);

it means


D7 → portb.f7
D6 → portb.f6
D5 → portb.f5
D4 → portb.f4
E → portb.f3
RS → portb.f2
RW → portb.f0

try to link up the wires without using the bus
I simulated the above code and followed these connections

it worked very well on my latest proteus


hope it helps

Good luck!

:)

Eng_Bandar
Posts: 65
Joined: 04 Jun 2010 01:13

Re: help please in this code

#7 Post by Eng_Bandar » 05 Jun 2010 05:40

Thank basicbasic111 & Sobrietytest for your helping
Thank you so much


the project executed

Post Reply

Return to “mikroC General”