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.

an ambiguous error in this code

Status
Not open for further replies.

Mohamed Slama

Member level 4
Joined
Nov 8, 2013
Messages
72
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
443
Hi all

this code :
when i push button (high) that connected to Portb.F0

the counter will increment as follow ( 1 ,3 ,5,7,9, 11, 13, 15 )

and store these values into a vector of length 8

when Portb.f0 pushed down (low) ( the micro controller supposed to display this vector value by value each 400 ms ,But micro controller display these value correctly in the first time but in the second time it display 0 then 0 then ...... to eight zero

third time it display correctly and so on , what is the problem ??


Code:
// LCD module connections
sbit LCD_RS at RC6_bit;
sbit LCD_EN at RC7_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISC6_bit;
sbit LCD_EN_Direction at TRISC7_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections


 //variables
char Num_txt[7];
unsigned char i =0 ;
unsigned char x =0 ;



  void _Init()
{
  trisd.f0=0;
  trisb=1;
  lcd_init();
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Cmd(_LCD_CLEAR);
}

 void main()
{
   unsigned int s_vector[8];
   _Init();

   for(;;)
   {

       if(portb.f0==1) {

          for (i=0;i<8;i++){
            s_vector[i]=2*i+1 ;
           LongWordToStr(s_vector[i],Num_txt);
           lcd_out(2,1, Num_txt);
               delay_ms(500);
               if (i==9) i==0;
                              }
                              }


                                      else {
                               for(x=0;x<8;x++){
                                                 LongWordToStr(s_vector[x],Num_txt);
                                                  lcd_out(3,1, Num_txt);
                                                  delay_ms(400);
                                                 }
                                                  x=0;
                               }
                               }
                               }
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top