HELP!!! reset variable problem

General discussion on mikroC.
Post Reply
Author
Message
JankoJaridic
Posts: 1
Joined: 09 May 2014 21:45

HELP!!! reset variable problem

#1 Post by JankoJaridic » 22 May 2014 09:36

Hi, i have some troubles resetting variable 'differenza' properly so the result after second iteration has no proper interpretation. The result is below the code(snapshot of usart terminal).

Code: Select all

#include <built_in.h>
int pianoAttuale = 0;
int pianoDesiderato = 0; // piano desiderato
int differenza = 0; // differenza N-S
int flag = 0;

void interrupt(){
        if(PIR1.RCIF){
                     Lo(pianoDesiderato) = UART1_Read();
                     flag = 1;
                          }
                }
void main() {
     PORTC = 0;
     TRISC = 0;
     ADCON0 = 0;
     ADCON1 = 0;
     CMCON = 0;
     INTCON.GIE = 1;
     INTCON.PEIE = 1;
     PIE1.RCIE = 1;
     UART1_Init(1200);
     Delay_ms(100);
        while(1) {
                 if(flag == 1){
                 differenza = 0;
                 differenza = pianoDesiderato - pianoAttuale;
                 pianoAttuale = pianoDesiderato;
                 UART1_Write(Lo(differenza));
                 UART1_Write(Lo(pianoAttuale));
                 flag = 0;
                  }
                 }

}
Attachments
RESULT.JPG
RESULT.JPG (103.56 KiB) Viewed 1753 times

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: HELP!!! reset variable problem

#2 Post by filip » 13 Jun 2014 08:50

Hi,

Have you been able to sort out this issue ?

Regards,
Filip.

Post Reply

Return to “mikroC General”