Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

plz help me in mikroC programm

Status
Not open for further replies.

muza1988

New Member
dear all,
the problem with the code is that when i press the switch at C0 it displays the count but wen i press switch at B0 it doesnt go out of the previous loop and still displays the count. i want that wen C0 is pressed it shud display the count and wen B0 is pressed it should clear the count and only display the text.
plz help me in this code



int i ;
char txt[5];
void main()

{

i = 0;
PORTB = 0;
TRISB = 0b00000001;
PORTC = 0;
TRISC = 0b00000001;


PORTD = 0;
LCD_Config(&PORTD,1,0,2,7,6,5,4); // LCD pins that are connected to PIC at PORTD
while(1)
{
if (!PORTC.F0 == 1)
{
i=i+1;
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);
IntToStr(i, txt);
Lcd_Out(2,2 ,txt);
delay_ms(1000);
}

if(!PORTB.F0 == 1)
{
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);
LCD_Out(1,1, "DINNAR BOX");
LCD_Out(2,1,"FOR HAJJ!");

}



}

} // for void
 
That is what your code does so it must be something else. Try posting complete code and include which chip you are using. Note, it may take up to 1 second before it changes due to the delay.

BTW, when you post code type
Code:
 before it and
after it so it keeps it's formating like this,
Code:
int i ;
char txt[5];
void main(){
    i = 0;
    PORTB = 0;
    TRISB = 0b00000001;
    PORTC = 0;
    TRISC = 0b00000001;
    PORTD = 0;
    LCD_Config(&PORTD,1,0,2,7,6,5,4); // LCD pins that are connected to PIC at PORTD
    while(1){
        if (!PORTC.F0 == 1){
            i=i+1;
            Lcd_Cmd(Lcd_CLEAR);
            Lcd_Cmd(Lcd_CURSOR_OFF);
            IntToStr(i, txt);
            Lcd_Out(2,2 ,txt);
            delay_ms(1000);
        }
        if(!PORTB.F0 == 1){
            Lcd_Cmd(Lcd_CLEAR);
            Lcd_Cmd(Lcd_CURSOR_OFF);
            LCD_Out(1,1, "DINNAR BOX");
            LCD_Out(2,1,"FOR HAJJ!");
        }
    }
}

Mike.
 
thanks for reply Mike.
i am using PIC 16F877A... i think there is problem with the integer to string conversion...i tried another code. the switches are working but when count button is pressed it displays the following ...
coin dropped = $ (some symbolic values and keeps on changing)

Code:
int i;
char txt[5];
void main()

{

  i = 0;
  PORTD = 0;
  LCD_Config(&PORTD,1,0,2,7,6,5,4);
  PORTB = 0;
  TRISB = 0b00000001;
  
 {
 do
 {
   if(PORTB.F0 == 0)
   {
  LCD_Cmd(LCD_CLEAR);
  Lcd_Cmd(Lcd_CURSOR_OFF);
  i=i+1;
  LCD_Out(1,1,"Coin dropped = ");
  LCD_Chr_Cp(i);
  delay_ms(1000);


  }

  else
  {
  LCD_Cmd(LCD_CLEAR);
  Lcd_Cmd(Lcd_CURSOR_OFF);
  LCD_Out(1,1, "DINNAR BOX");
  LCD_Out(2,1,"FOR HAJJ!");
  Delay_ms(1000);
  i = 0;
  }
   
  
  }while(1);
  }


  }
 
Last edited:
It is doing what you have told it to do, display character i where i goes from 0 to 255 and so it displays all the ascii characters. What you need is a function like atoi() - look it up in the help file.

Mike.
 
help needed again in code

hi,

i have problem with my code again:(
i make a program in which, when switch at B0 is pressed it will display count and when switch B0 is off it will display welcome text. the problem is that for my coin counter hardware to run correctly i have to reduce the delay to 20ms in the if statement(the welcome text display ).as i do so the welcome display, which is meant to scroll as per my code, scrolls very fast and cant be seen. is there any way to reduce the delay so that it can count coins and display the welcome text...
plz help ...its my project...


Code:
int i;
int j;
char txt[2];
void main()

{

  i = 1;
  PORTD = 0;
  LCD_Config(&PORTD,1,0,2,7,6,5,4);
  PORTB = 0;
  TRISB = 0b00000001;

 {
 do
 {
   if(PORTB.F0 == 0)
   {
     for(j=0;j<16;j++)
   {
  LCD_Cmd(LCD_CLEAR);
  Lcd_Cmd(Lcd_CURSOR_OFF);
  LCD_Out(1,j,"WELCOME TO");
  LCD_Out(1,j-8,"GOLD DINNAR BOX");
  Delay_ms(300);
  }


  }


  else
  {

  LCD_Cmd(LCD_CLEAR);
  Lcd_Cmd(Lcd_CURSOR_OFF);
  IntToStr(i, txt);
  Lcd_Out(2,2 ,txt);
  delay_ms(500);
  i=i+1;

  }


  }while(1);

  }


  }
 
Last edited:
hi rajbex

im new at mikroc programming. i dont know muxh abut interrupt. can plz give a basic idea abut it n how to use it. or u can just give me an example

thnks
 
You could break out of the loop(s).
Code:
        if(PORTB.F0 == 0){
            for(j=0;j<16;j++){
                LCD_Cmd(LCD_CLEAR);
                Lcd_Cmd(Lcd_CURSOR_OFF);
                LCD_Out(1,j,"WELCOME TO");
                LCD_Out(1,j-8,"GOLD DINNAR BOX");
[COLOR="red"]	       for(i=0;i<300;i++){
                    Delay_ms(1);
                    if(PORTB.F0!=0)
                        break;
                } 
                if(PORTB.F0!=0)
                    break;[/COLOR]
            }
 
Status
Not open for further replies.

Latest threads

Back
Top