avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] if statement problem


From: David Smead
Subject: Re: [avr-gcc-list] if statement problem
Date: Sun, 24 Mar 2002 11:29:11 -0800 (PST)

Paulo,

Yuu set it to NONE in MAIN, and your interrupt routine doesn't allow it to
be set to anything else.

-- 
Sincerely,

David Smead
http://www.amplepower.com.

On Sun, 24 Mar 2002, Paulo Abreu wrote:

> I am doing this peace of code:
>
> (my problem is expressed in the end)
> *****************************************************************************
> #include <io8535.h>
> #include <io.h>
> #include <interrupt.h>
> #include <sig-avr.h>
>
>
> ///////////////////////////////////////////////////////////////////////////////////////////////////
> // uart
> //#define UART_9BIT          0x00
> //#define UART_8BIT          0x01
> //
> #define F_CPU         6144000     /* 6,144Mhz */
> #define UART_BAUD_RATE       9600     /* 9600 baud */
> #define UART_BAUD_SELECT (F_CPU/(UART_BAUD_RATE*16l)-1)
> #define UART_INSTRUCTION_SIZE     4
>
> #define NONE   0
> #define RECEIVING  1
> #define RESPONDING  2
> #define SHARPS_NUMBER 5
> #define COMMAND_SIZE 1
> #define MY_ID   0x10
>
> uint8_t g_orderStatus;
>
> uint8_t g_sharps[SHARPS_NUMBER]= {'A', 'B', 'C', 'D', 'E'};
> uint8_t g_lastCommand[COMMAND_SIZE]= {0}; // stores last uart command
>
> static uint8_t g_index;     // indice do array a usar
>
>
> // 
> ----------------------------------------------------------------------------
> //  Recepção de caracter
> SIGNAL(SIG_UART_RECV)
> {
>  register uint8_t sreg_temp= inp(SREG);
>  register uint8_t temp= inp(UDR);
>
>  switch (g_orderStatus)
>  {
>   case NONE:
>    if ((temp & 0xf0) == MY_ID)
>    {
>     g_orderStatus= RECEIVING;
>     g_index= 0;
>     g_lastCommand[g_index++]= temp;
>    }
>    break;
>   case RECEIVING:
>    if (g_index <COMMAND_SIZE)
>    {
>     g_lastCommand[g_index++]= temp;
>    }
>    else
>    {
>     cbi(UCR, RXCIE);
>     g_index=0;
>     g_orderStatus= RESPONDING;
>    }
>  }
>  outp(sreg_temp, SREG);
>  sei();
> }
>
>
> int main(void)
> {
>  g_orderStatus= NONE;
>
>  // Inicializações */
>
>  outp( BV(RXCIE) | BV(RXEN) | BV(TXEN), UCR ); // Permite o envio e a 
> recepção e activa a interrupção de recepção
>  outp((unsigned char)UART_BAUD_SELECT, UBRR); // set baud rate
>  sei();
>
>  // inicialmente a uart espera por uma intrução. Após receber uma instrução 
> só volta a receber outra quando a instrução for avaliada
>  while(1)
>  {
>   if (g_orderStatus == RESPONDING)
>   {
>    register uint8_t *p;
>
>    // verifica o comando
>    switch(g_lastCommand[0] & 0x0f)
>    {
>     case 0x01:
>      // enviar os charps todos
>      p=  g_sharps;
>      g_index= SHARPS_NUMBER;
>      break;
>    }
>
>    for(; g_index > 0; --g_index)
>    {
>     outp(*p++, UDR);
>     loop_until_bit_is_set(USR, TXC);
>     g_orderStatus= NONE;
>    }
>
>    sbi(UCR, RXCIE);   // activa a interrupção de recepção
>   }
>
>  }
> }
>
>
> **************************************************************************
>
> In debug mode, sending 0x11, g_orderStatus is set with 0x2 ... gowever when I 
> get to if (g_orderStatus == RESPONDING), the expression is evaluated as false;
>
> register uint8_t temp= inp(UDR);
> +00000039: B12C      IN      R18,0xC
>
> After R18 get RESPONDING something is wrong, when I rich: if (g_orderStatus 
> == RESPONDING)
> debugger points to +0000006F, and LDS     R18,0x0067 never runs ... 
> (+00000069).
>
> Since in interrup routine maques a pop to R18 at the end, and R18 is never 
> restored,  if (g_orderStatus == RESPONDING) is always false ...
>
> I don't get ..... I also tried a break point at +00000069 and never stops ....
>
>  +00000069: 91200067  LDS     R18,0x0067
>    +0000006B: 91300065  LDS     R19,0x0065
>    +0000006D: 91900066  LDS     R25,0x0066
>    +0000006F: 3022      CPI     R18,0x02          ; 0x02 = 0b00000010 = 2
>    +00000070: F7F1      BRNE    -0x02             ; Destination: 0x00006F
>    +00000071: 2F83      MOV     R24,R19
>    +00000072: 708F      ANDI    R24,0x0F          ; 0x0F = 0b00001111 = 15
>    +00000073: 3081      CPI     R24,0x01          ; 0x01 = 0b00000001 = 1
>    +00000074: F059      BREQ    +0x0B             ; Destination: 0x000080
>
> Thanks for your attention,
>
> Paulo Abreu
>

avr-gcc-list at http://avr1.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]