Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
LevenEigenaar
PostPosted: Jan 27, 2012 - 07:22 AM
Hangaround


Joined: Oct 13, 2011
Posts: 165


Code:
 
 ISR(TIMER0_OVF_vect)
{
   count++;
   char buffer[BUF_SIZE];
   int index = 0;
   USART_init(UBRR_9600);
   lcd_init();


   if(count==1)
   {
         while (modem_opstarten == 0)        // was eerst while       
         {
                  while(!(UCSRA & (1<<RXC)));
                  {
                  buffer[index] = UDR;                
                                    
                  lcd_xy( 0, 0 );
                  lcd_puts("0"); 

                  if (buffer[index] == 0x0D)
                  {
                     buffer[index] = 0;
                     index = 0;
      
                     if (strcmp(buffer, "OK") == 0)
                     {
                        lcd_xy( 0, 1 );
                        lcd_puts(">"); //adc value
                        
                        lcd_xy( 2, 1 );
                        lcd_puts(buffer); //adc value
                        lcd_xy( 5, 1 );
                        lcd_puts("<"); //adc value
                        
                        lcd_xy( 7, 1 );
                        lcd_puts("1"); //adc value
                        test1 = 0;
                        _delay_ms(5000);
                          lcd_command( 0x01 );                          // display clear
                        
                        //modem_begin_string = 0;      
                     }            
                     else
                     {
                        lcd_xy( 0, 1 );
                        lcd_puts(buffer); //adc value
                        
                        lcd_xy( 5, 1 );
                        lcd_puts("2"); //adc value
                        test1 = 0;
                        _delay_ms(5000);
                          lcd_command( 0x01 );                          // display clear
                        

                     }          
                  }
                  else
                  {
                     if (++index == BUF_SIZE)
                     {
                        index = 0;
                     }   
                  }               
                  count=0;
               }                  
            }
         }   
      }
   
                              


Hello, i have a problem

How can i make a start bit for this script, example start with 0x0A en stop 0x0D,

I have try many thinks but no results.
Here a example what i tried.
Code:

if ((UDR == 0x0A)||(set ==1))
{
set = 1;

 
 View user's profile Send private message  
Reply with quote Back to top
MBedder
PostPosted: Jan 27, 2012 - 07:47 AM
Raving lunatic


Joined: Nov 02, 2009
Posts: 3239
Location: Zelenograd, Russia

Why on Earth are you stuffing your timer ISR with all that things? Do you have any clue of what the interrupts are for?

_________________
Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.
 
 View user's profile Send private message  
Reply with quote Back to top
LevenEigenaar
PostPosted: Jan 27, 2012 - 08:24 AM
Hangaround


Joined: Oct 13, 2011
Posts: 165


Do not know how else to. You any ideas?
 
 View user's profile Send private message  
Reply with quote Back to top
jan_dc
PostPosted: Jan 27, 2012 - 09:28 AM
Hangaround


Joined: Feb 09, 2011
Posts: 323
Location: Turnhout, Belgium

The problem here is that your Timer ISR blocks all other ISR's (if any). So this is considered to be 'bad practice' but I don't see any harm if you know what you are doing (meaning blocking possible other interrupts).

A 'cleaner' way of doing this is to have the ISR set a veriable to 1. Then in a continous loop you can check this variable and if == 1 procedeed with the code you currently have in your ISR.

F.i. I use a timer to create a more or less 10ms tick. The whole system is synchronised via that tick. Sometimes it waits for 50 ticks, other parts wait less and so on.

You also only have to set the UART settings once.

example of my time ISR:
Code:

ISR(CHRONO_INTERRUPT_VECTOR) {
    #if (CHRONO_10MSVALUE == 1)
      ++CHRONO_Time.tenms;
      ++CHRONO_Timer;
    #else
      if (++CHRONO_tickCounter == CHRONO_10MSVALUE) {
        CHRONO_tickCounter = 0;
        ++CHRONO_Time.tenms;
        ++CHRONO_Timer;
      }
    #endif

    if (CHRONO_Time.tenms == 100) {
      #ifdef CHRONO_TIMEOUTVALUE
        if ((CHRONO_TIMEOUTVALUE) && (++CHRONO_ShutDownCounter > CHRONO_TIMEOUTVALUE)) {
          USER_ShutDownFunction();
        }
      #endif
      CHRONO_Time.tenms = 0;

      #ifdef CHRONO_FLAGS
        CHRONO_Flags.sec_full = 1;
        CHRONO_Flags.sec_half = 1;
        #ifdef USE_DISPLAY
          SDOS_blinkingDot = 1 - SDOS_blinkingDot;
        #endif
      #endif
 
      #ifdef EVENT_CHRONO_HALF_SECOND_VECTOR
        XIRQ_SET(EVENT_CHRONO_HALF_SECOND_VECTOR);
      #endif
      #ifdef EVENT_CHRONO_SECOND_VECTOR
        XIRQ_SET(EVENT_CHRONO_SECOND_VECTOR);
      #endif

      if (++CHRONO_Time.sec == 60) {
        CHRONO_Time.sec = 0;
        #ifdef EVENT_CHRONO_MINUTE_VECTOR
          XIRQ_SET(EVENT_CHRONO_MINUTE_VECTOR);
        #endif
        #if defined(CHRONO_HOURS) || defined(CHRONO_MINUTES)
          if (++CHRONO_Time.min == 60) {
            CHRONO_Time.min = 0;
            #ifdef CHRONO_HOURS
              #ifdef EVENT_CHRONO_HOUR_VECTOR
                XIRQ_SET(EVENT_CHRONO_HOUR_VECTOR);
              #endif
              ++CHRONO_Time.h;
            #endif
          }
        #endif
      }
    }
    #ifdef CHRONO_FLAGS
      else if (CHRONO_Time.tenms == 50) {
        #if (CHRONO_10MSVALUE != 1)
          if CHRONO_tickCounter == 0) {
        #endif

          #ifdef EVENT_CHRONO_HALF_SECOND_VECTOR
            XIRQ_SET(EVENT_CHRONO_HALF_SECOND_VECTOR);
          #endif

          CHRONO_Flags.sec_half = 1;
          #ifdef USE_DISPLAY
            SDOS_blinkingDot = 1 - SDOS_blinkingDot;
          #endif
        #if (CHRONO_10MSVALUE != 1)
        }
        #endif
      }
    #endif

    #ifndef TRAPPED_INTERRUPT_VECTOR
      if ((CommStatus.Trapped) && (CommSettings.EnableTrap)) {
        TRAPPED_CallFunction();
      }
    #endif
  }


Then in main code there is the following piece of code in an infinite loop:

Code:

do {
  if (KEYBOARD_Button.risingEdge) { /* button pressed */
    KEYBOARD_Button.risingEdge = 0;
    if (KEYBOARD_Button.button == (unsigned char) KEYBOARD_BUTTON_SELECT) { /* CAL pressed */
      MEASUREMENT_VCalibration();
      goto MAIN_loop;
    }

    #ifndef __C5010__
      if (KEYBOARD_Button.button == (unsigned char) KEYBOARD_BUTTON_UP) { /* store value */
        DISPLAYSTRING_LEFT(0);
        MEASUREMENT_STORE_Display();
       DISPLAY_LoadAndDrawTemplate(INDEX_MAIN_MEASURE);
        goto label_MeasureAndDisplay_loop;
      }

      if ((KEYBOARD_Button.button == (unsigned char) KEYBOARD_BUTTON_DOWN) && (!MEASUREMENT.channel[0].measurementStatus.outOfRange)) { /* store value */
        MENU_Parameter.row1 = MAIN_coordinate[0].row+2;
        MENU_Parameter.column1 = MAIN_coordinate[0].column+19;
        MENU_Parameter.wraparound = 1;
        USER_Settings.storeTable[0].position = USER_Settings.storeTable[0].position % (MEASUREMENT_STORE_MAXPOSITION+1);
        MENU_NumberParameter.number = ((long) USER_Settings.storeTable[0].position+1) * NUMBER_FACTOR;
        MENU_NumberParameter.increment = NUMBER_FACTOR;
        MENU_NumberParameter.minimum = NUMBER_FACTOR;
        MENU_NumberParameter.maximum = (MEASUREMENT_STORE_MAXPOSITION+1) * NUMBER_FACTOR;
        NUMBERSFORMAT(3);
        NumbersFormat.zeroOrSpace = 1;
        DISPLAYSTRING_INVERT_RIGHT(0);

        MENU_SetNumber();

        if (MENU_Status.accepted) {
          USER_Settings.storeTable[0].position = (MENU_NumberParameter.number/NUMBER_FACTOR) - 1;
          MEASUREMENT_STORE_Write();
        }
        DISPLAY_LoadAndDrawTemplate(INDEX_MAIN_MEASURE);
        goto label_MeasureAndDisplay_loop;
      }
    #endif

    if (KEYBOARD_Button.button == (unsigned char) KEYBOARD_BUTTON_CANCEL) { /* MODE pressed */
      goto label_MainMenu;
    }
  }
} while (!CHRONO_Flags.sec_half);


Just before this do while loop some functionality is done. This do while is a wait loop until the next 0.5s event occurs. Within this wait loop some things like keyboard are checked and things are done if needed. Some important things are checked in the time ISR (if this functionality is used).
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Kartman
PostPosted: Jan 27, 2012 - 09:45 AM
Raving lunatic


Joined: Dec 30, 2004
Posts: 8786
Location: Melbourne,Australia

Cr and lf are not stop and start bits! The convention is to put cr,lf on the end of the string. I think you want to have a read of my tutorial on multitasking.
 
 View user's profile Send private message  
Reply with quote Back to top
jan_dc
PostPosted: Jan 27, 2012 - 10:37 AM
Hangaround


Joined: Feb 09, 2011
Posts: 323
Location: Turnhout, Belgium

Kartman wrote:
Cr and lf are not stop and start bits! The convention is to put cr,lf on the end of the string. I think you want to have a read of my tutorial on multitasking.


He's asking to start with a certain code and stop with a certain code. LF/CF are just one of the many. Personally I use 0x00 as stop. And any new byte is a start. Much more convenient than LF/CR.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
LevenEigenaar
PostPosted: Jan 27, 2012 - 10:49 AM
Hangaround


Joined: Oct 13, 2011
Posts: 165


Hey!

This is a code too read the rs232 char.

Every word start with 0x0A and ends with 0x0D

How can i start with the char 0x0A ?

Example

0x0A CONNECT! 0x0D
with responds (OK)

Connect will set in the buffer.

But if i send

0x0A POSSIBLECONNECT 0x0D

It will send Error example
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jan 27, 2012 - 10:50 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62341
Location: (using avr-gcc in) Finchingfield, Essex, England

LevenEigenaar,

If I were you I think I'd take a step back from what you are attempting here. Just growing an entire "sub program" inside an ISR() is actually very bad program design. When an ISR() is entered interrupts are disabled so if the ISR() code itself takes 10's or 100's of milliseconds to execute it may block several other interrupting events in the system from being serviced. Doing things like lcd_*() output in an ISR can take several milliseconds alone for each call. The ISR should be designed to only do the absolute minimum work and exit as soon as possible. In the limit this may be as simple as:
Code:
volatile flag;

ISR(TIMER_OVF_vect) {
 flag = 1; // notify main() that the event occurred
}

int main(void) {
  while(1) {
    do_other_stuff();
    if (flag) {
      all_the_stuff_from_the_ISR();
      flag = 0;
    }
  }
}

The best way to go about designing a program like this is to work on small parts in isolation. Test those until you are happy that the function works then finally put all the elements together following an overall high level design (perhaps a flowchart?) that shows how everything should connect together. You need a clear picture of that overall design in your mind before you attempt to integrate the function blocks. In doing that you will be forced to consider whether "two things need to happen" at the same time and that's when you will consider splitting execution flow between main() and ISR()(s) code (again keeping those ISR()s short).

While the other replies here are helpful I fear they may just lead to a further complication of a bit of a rickety design.

BTW the convention is not to read it as:
Code:
0x0A "CONNECT" 0x0D

but as
Code:
"CONNECT" 0x0D 0x0A

which in C is
Code:
"CONNECT\r\n"

Each "line" sent by the modem is terminated with Carriage Return (0x0D) then Line Feed (0x0A)

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
LevenEigenaar
PostPosted: Jan 27, 2012 - 11:13 AM
Hangaround


Joined: Oct 13, 2011
Posts: 165


Code:

int main(void)
{
   USART_init(UBRR_9600);
   modem_opstarten = 1;
   
   char buffer[BUF_SIZE];
   int index = 0;
   lcd_init();

    while(1)
    {
      if (flag == 1)
      {
         while (modem_opstarten == 0)        // was eerst while       
         {
               while(!(UCSRA & (1<<RXC)));
               {
                  buffer[index] = UDR;                
                                    
                  lcd_xy( 0, 0 );
                  lcd_puts("0"); 

                  if (buffer[index] == 0x0D)
                  {
                     buffer[index] = 0;
                     index = 0;
      
                     if (strcmp(buffer, "OK") == 0)
                     {
                        lcd_xy( 0, 1 );
                        lcd_puts(">"); //adc value
                        
                        lcd_xy( 2, 1 );
                        lcd_puts(buffer); //adc value
                        lcd_xy( 5, 1 );
                        lcd_puts("<"); //adc value
                        
                        lcd_xy( 7, 1 );
                        lcd_puts("1"); //adc value
                        test1 = 0;
                        _delay_ms(5000);
                        lcd_command( 0x01 );                          // display clear
                        
                           //modem_begin_string = 0;      
                     }            
                     else
                     {
                        lcd_xy( 0, 1 );
                        lcd_puts(buffer); //adc value

                        test1 = 0;
                        _delay_ms(5000);
                        lcd_command( 0x01 );                          // display clear                        
                        }          
                     }
                     else
                     {
                        if (++index == BUF_SIZE)
                        {
                           index = 0;
                        }   
                     }
                  }                     
               }                           
         flag = 0;
      }

   

   while (modem_opstarten == 1)               
   {
            
               USART_tx_string("AT+IPR=9600");                      //verander baudrate
               USART_Transmit(0x0D);                             //carriage return   
               USART_Transmit(0x0A);                            //nieuwe lijn
               _delay_ms(100);
               
               USART_tx_string("AT+CPIN=");                      //verander baudrate
               USART_Transmit(0x22);
               USART_tx_string("6251");
               USART_Transmit(0x22);
               USART_Transmit(0x0D);                             //carriage return   
               USART_Transmit(0x0A);                            //nieuwe lijn
               _delay_ms(100);

               USART_tx_string("AT+CGATT=1");                     //GPRS Registration
               USART_Transmit(0x0D);                             //carriage return   
               USART_Transmit(0x0A);                            //nieuwe lijn      
               _delay_ms(100);
      
               USART_tx_string("AT+COPS?");                     //GSM Registration bijvoorbeeld (TMOBILE  NL)
               USART_Transmit(0x0D);                             //carriage return      
               USART_Transmit(0x0A);                            //nieuwe lijn   
               _delay_ms(100);
         
               USART_tx_string("AT+CGDCONT?");
               USART_Transmit(0x0D);                             //carriage return
               USART_Transmit(0x0A);                            //nieuwe lijn         
               _delay_ms(1000);
            
               USART_tx_string("AT+CGDCONT=1,");                   //controle gsm modem actief? ok of error
               USART_Transmit(0x22);
               USART_tx_string("IP");   
               USART_Transmit(0x22);
               USART_tx_string(",");   
               USART_Transmit(0x22);
               USART_tx_string("internet");
               USART_Transmit(0x22);
               USART_Transmit(0x0D);                             //carriage return   
               USART_Transmit(0x0A);                            //nieuwe lijn      
               _delay_ms(100);                                 //Vertraging 1 seconden
                  
               USART_tx_string("AT$HOSTIF=2");
               USART_Transmit(0x0D);                             //carriage return   
               USART_Transmit(0x0A);                            //nieuwe lijn               
               _delay_ms(100);
      
               USART_tx_string("AT$ACTIVE=1");
               USART_Transmit(0x0D);                             //carriage return   
               USART_Transmit(0x0A);                            //nieuwe lijn         
               _delay_ms(100);
      
               USART_tx_string("AT$PADDISC=1");
               USART_Transmit(0x0D);                             //carriage return   
               USART_Transmit(0x0A);                            //nieuwe lijn         
               _delay_ms(100);
      
      
               USART_tx_string("AT$PADDST=");   
               USART_Transmit(0x22);
               USART_tx_string("--------");   
               USART_Transmit(0x22);
               USART_tx_string(", ----");   
               USART_Transmit(0x0D);                             //carriage return      
               USART_Transmit(0x0A);                            //nieuwe lijn      
               _delay_ms(100);
      
               USART_tx_string("AT$AREG=2");
               USART_Transmit(0x0D);                             //carriage return   
               USART_Transmit(0x0A);                            //nieuwe lijn         
               _delay_ms(100);
      
               USART_tx_string("AT&W");
               USART_Transmit(0x0D);                             //carriage return   
               USART_Transmit(0x0A);                            //nieuwe lijn         
               _delay_ms(100);
      
               USART_tx_string("AT$RESET");
               USART_Transmit(0x0D);                             //carriage return      
               USART_Transmit(0x0A);                            //nieuwe lijn      
               _delay_ms(100);

               modem_opstarten = 0;
               modem_rs232_check = 1;
   }
}
}               
   
ISR(TIMER0_OVF_vect)
{
   flag = 1; // notify main() that the event occurred
}
                  



Hi thank you,

The flag will not be a 1?

How can i set the isr?
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Jan 27, 2012 - 11:21 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62341
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

The flag will not be a 1?

Sorry, what do you mean? As long as you defined it as "volatile" then when timer 0 overflows it will be set and the code in main() will then see this.

Having said that I don't see any code that starts timer 0, or enables its interrupt or enables the global interrupt flag?!? Surely you must have had this previously as you already had the code you were using inside the handler for the timer overflow? You still need to have that timer run and interrupt if the execution of the rest of the code is dependent on the timer even occuring (to be honest, if this is a modem, I don't see why it would be dependent on a timed event anyway?)

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
jan_dc
PostPosted: Jan 27, 2012 - 11:22 AM
Hangaround


Joined: Feb 09, 2011
Posts: 323
Location: Turnhout, Belgium

Code:

while (modem_opstarten == 0)


will result in a lock for ever if modem_opstarten != 0

The ISR will never quit and no other interrupts can be serviced.

This should work as long as there are no infinite waits for a software status. When an ISR is running a software status will not change unless it's changed by the ISR.

Code:

#define MODEM_IDLE 0
#define MODEM_DATA 1

char modem_state;

ISR(TIMER0_OVF_vect) {
  count++;
  char buffer[BUF_SIZE];
  int index = 0;
  USART_init(UBRR_9600);
  lcd_init();

  if(count==1) {
    while(!(UCSRA & (1<<RXC)));
    buffer[index] = UDR;                 
    lcd_xy( 0, 0 );
    lcd_puts("0"); 

    switch (modem_state) {
    default :
      index = 0;
      if (buffer[0] == 0x0A) {
        modem_state = MODEM_DATA;
      }
      break;

    case MODEM_DATA :
      if (buffer[index] == 0x0D) {
        buffer[index] = 0;
        index = 0;
        lcd_xy( 0, 1 );
        if (strcmp(buffer, "OK") == 0) {
          lcd_puts(">"); //adc value
          lcd_xy( 2, 1 );
          lcd_puts(buffer); //adc value
          lcd_xy( 5, 1 );
          lcd_puts("<"); //adc value
          lcd_xy( 7, 1 );
          lcd_puts("1"); //adc value
        }             
        else  {
          lcd_puts(buffer); //adc value
          lcd_xy( 5, 1 );
          lcd_puts("2"); //adc value
        }           
        test1 = 0;
        _delay_ms(5000);
        lcd_command( 0x01 );
      }

      if (++index == BUF_SIZE) {
        index = 0;
      }   
      break;
    }
  }
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
dksmall
PostPosted: Jan 27, 2012 - 02:49 PM
Raving lunatic


Joined: Apr 16, 2001
Posts: 3522
Location: Phoenix, Arizona

Why are you even using a timer interrupt? From what I see of your code you're simply talking to a modem. Focus on getting your serial routines working and don't worry about timers for now.
 
 View user's profile Send private message  
Reply with quote Back to top
LevenEigenaar
PostPosted: Jan 27, 2012 - 05:31 PM
Hangaround


Joined: Oct 13, 2011
Posts: 165


Thank you all for you responds I will try it tomorrow !!!

And will replay on all you responds

grz
 
 View user's profile Send private message  
Reply with quote Back to top
LevenEigenaar
PostPosted: Feb 02, 2012 - 07:30 AM
Hangaround


Joined: Oct 13, 2011
Posts: 165


Sorry this code doesn't working.
 
 View user's profile Send private message  
Reply with quote Back to top
LevenEigenaar
PostPosted: Feb 02, 2012 - 12:17 PM
Hangaround


Joined: Oct 13, 2011
Posts: 165


Can someone help me with the problem

0x0A is the bit will start the buffer
0x0D is the bit will stop the buffer.

Someone?
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Feb 02, 2012 - 12:19 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62341
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

0x0A is the bit will start the buffer

0x0A is not a "bit", it is at least 4 bits and more usually 8.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
LevenEigenaar
PostPosted: Feb 02, 2012 - 12:34 PM
Hangaround


Joined: Oct 13, 2011
Posts: 165


Ok,

Is here a example script for?

for receive strings?
 
 View user's profile Send private message  
Reply with quote Back to top
LevenEigenaar
PostPosted: Feb 02, 2012 - 12:37 PM
Hangaround


Joined: Oct 13, 2011
Posts: 165


Code:
 ISR(TIMER0_OVF_vect)
{
   char buffer[BUF_SIZE];
   int index = 0;
   USART_init(UBRR_9600);
   lcd_init();

      while (1)
      {
         while(!(UCSRA & (1<<RXC)));
         buffer[index] = UDR;
         
         if((buffer[0] == 0x0A)||(test1 == 1))
         {
            test1 = 1;
            if (buffer[index] == 0x0D)
            {
               buffer[index] = 0;
               index = 0;
      
               if (strcmp(buffer, "CONNECT") == 0)
               {
                  lcd_xy( 0, 0 );
                  lcd_puts("1"); //adc value         
                  
                  lcd_xy( 0, 2 );
                  lcd_puts(buffer); //adc value         
                  
                  
               }            
               else
               {
                  lcd_xy( 1, 0 );
                  lcd_puts("2"); //adc value
                  
                                    lcd_xy( 0, 2 );
                  lcd_puts(buffer); //adc value         
                  
               }          
            }
            else
            {
               if (++index == BUF_SIZE)
               {
                  index = 0;
               }   
            }               
      }
   }
}   


This isn't work at all?

What do i wrong?
 
 View user's profile Send private message  
Reply with quote Back to top
LevenEigenaar
PostPosted: Feb 02, 2012 - 12:45 PM
Hangaround


Joined: Oct 13, 2011
Posts: 165


Is this the right way?

Code:
 ISR(TIMER0_OVF_vect)
{
   char buffer[BUF_SIZE];
   int index = 0;
   USART_init(UBRR_9600);
   lcd_init();

      while (1)
      {
         while(!(UCSRA & (1<<RXC)));
         buffer[index] = UDR;
         
         if((buffer[0] == 0x43)||(test1 == 1))
         {
            test1 = 1;
            if (buffer[index] == 0x0D)
            {
               buffer[index] = 0;
               index = 0;
      
               if (strcmp(buffer, "CONNECT") == 0)
               {
                  lcd_xy( 0, 0 );
                  lcd_puts("1"); //adc value         
                  
                  lcd_xy( 0, 2 );
                  lcd_puts(buffer); //adc value         
                  _delay_ms(5000);
                    lcd_command( 0x01 );                          // display clear
                  test1 = 0;
                  
                  
               }            
               else
               {
                  lcd_xy( 1, 0 );
                  lcd_puts("2"); //adc value
                  
                                    lcd_xy( 0, 2 );
                  lcd_puts(buffer); //adc value      
                  
                  _delay_ms(5000);
                    lcd_command( 0x01 );                          // display clear   
                  test1 = 0;
               }          
            }
            else
            {
               if (++index == BUF_SIZE)
               {
                  index = 0;
               }   
            }               
      }
   }
}   
 
 View user's profile Send private message  
Reply with quote Back to top
Kartman
PostPosted: Feb 02, 2012 - 12:54 PM
Raving lunatic


Joined: Dec 30, 2004
Posts: 8786
Location: Melbourne,Australia

Did you read my tutorial on multitasking? Did you understand what Cliff and I said about CR/LF?

May i suggest you get an Arduino board as there are projects similar to what you want to do. At a minimum look at the arduino code to see how they do it.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Feb 02, 2012 - 12:56 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62341
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

Did you understand what Cliff and I said about CR/LF?

Did you understand my previous point about not putting all the work in the body of an ISR? (whatever anyone else might say it is bad advice even if they do think it is good for you to learn from your mistakes - the issue it creates is so complex that it could floor an expert let alone a beginner!)

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
jan_dc
PostPosted: Feb 02, 2012 - 02:29 PM
Hangaround


Joined: Feb 09, 2011
Posts: 323
Location: Turnhout, Belgium

Start the debugger, set a break point in the ISR and step through the code and see where it's going wrong (and why).

Learn to do debug or else you will never write any code.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits