Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help in mikroC code plz

Status
Not open for further replies.

muza1988

Newbie level 5
Joined
Jun 11, 2010
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
Malaysia
Activity points
1,337
dear all,
i want to make a program that when B0 is pressed it should display the count on LCD and wen B1 is pressed it should clear the count and display the text message. the problem with my code is that it displays the count wen i press B0 (switch at B0) but wen i press B1 it doesnt exit the previous loop and still it displays the count on the LCD.
plz help me i am new to mikroC



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

{

     i = 0;
     PORTB = 0;
     TRISB.F0 = 1;        //PORT B0 as input  // RB0 as input switch
     TRISB.F1 = 1;     //PORT B1 as input switch 2
     TRISB.F2 = 0;        //PORT B2 as Output
     TRISB.F3 = 0;        //PORT B3 as Output
     TRISB.F4 = 0;     //PORT B4 as Output
     TRISB.F5 = 0;        //PORT B5 as Output
     TRISB.F6 = 0;     //PORT B6 as output
     TRISB.F7 = 0;     //PORT B7 as output

  PORTD = 0;
  LCD_Config(&PORTD,1,0,2,7,6,5,4);           // LCD pins that are connected to PIC at PORTD

while(1)
{
  LCD_Cmd(LCD_CLEAR);
  LCD_Out(1,1, "DINNAR BOX");           // Print text to LCD, 1st row, 1st column
  Delay_ms(1000);
  LCD_Out(2,1,"FOR HAJJ!");

  if(PORTB.F0 == 1)   // ! coz its input low thats
  {
  i=i+1;
  IntToStr(i, txt);
  Lcd_Out(2,2 ,txt);
  Delay_ms(1000);}

  if(PORTB.F1 == 1)
  {
  LCD_Out(1,1, "DINNAR BOX");           // Print text to LCD, 1st row, 1st column
  Delay_ms(1000);
  LCD_Out(2,1,"FOR HAJJ!");}



} // for while



} // for void
 

I don't know what type of your lcd.
I think your program don't have big problem.
Fisrt, I think you should confirm your hardware is ok. Please press B1, and measure the io port's voltage.
Then, I think when you should really clear count. Just like this:
if(PORTB.F1 == 1)
{
LCD_Out(1,1, "DINNAR BOX");
for (j=0; j<5; j++)
{
txt[j] = ' ';
}
Lcd_Out(2,2 ,txt);
Delay_ms(1000);
LCD_Out(2,1,"FOR HAJJ!");
}

Try it.
 

I don't see where you clear the count... maybe a
Code:
  if(PORTB.F1 == 1) 
  { 
  i=0; // clear counter...
  LCD_Out(1,1, "DINNAR BOX");           // Print text to LCD, 1st row, 1st column 
  Delay_ms(1000); 
  LCD_Out(2,1,"FOR HAJJ!");}
will do the job...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top