void interrupt ()
{
if (PIR1.RCIF)
{
rxchar = UART1_Read();
}
}
//main
if (flag ==1)
{
uart_rd=rxchar;
if(old_uart==100)
{
Display uart_rd on display (pressure)
}
if(old_uart==101)
{
Display uart_rd on display (temperature)
}
old_uart=uart_rd;
flag = 0;
}
if (PIR1.RCIF)
{
rxchar= UART1_Read();
rxarray[ii] = rxchar;
ii++;
if(ii==3) // 4 bytes
flag = 1;
}
if (flag ==1) {
jj=0;
flag=0;
while(jj<ii)
{
uart_rd=rxarray[jj];
if(old_uart==100)
{
Display uart_rd on display (pressure)
}
if(old_uart==101)
{
Display uart_rd on display (temperature)
}
old_uart=uart_rd;
jj++;
}
}
if(input==OFF)
{
uartSTATE=193;
UART1_Write(uartSTATE);
}
the error in this case can be of the low current try adding capacitors to the vdd and vss of the MCU and add free wheeling diodes and caps to alarm circuit too.
Are you using mikroC Pro? Post the full code so that I can study it and write the code for you.
void uartInit()
{
PIE1.RCIE=1; //enable receive interrupt
INTCON.GIE = 1;
INTCON.PEIE = 1;
UART1_Init(9600);
Delay_ms(200); // Wait for UART module to stabilize
}
#define RX_BUFFER_SIZE 11
char volatile rx_buffer[RX_BUFFER_SIZE];
unsigned volatile char rx_wr_index,rx_rd_index,rx_counter;
unsigned volatile char *data__;
void interrupt()
{
if (PIR1.RCIF)
{
flag=1;
data__ =UART1_Read();
rx_buffer[rx_wr_index]=data__;
if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
if (++rx_counter == RX_BUFFER_SIZE)
{
rx_counter=0;
}
}
}
unsigned volatile char newUart;
unsigned volatile char oldUart;
unsigned volatile char stringUart;
char *someText;
void main ()
{
uartInit();
while(1)
{
newUart=getChar();
if(flag==1)
{
flag=0;
if(oldUart==100) //pressure sensor
{
stringUart=newUart;
ByteToStr(stringUart,someText);
Glcd_write_Text(someText,100,0,1);
}
if(oldiUart==101 ) //temperature sensor
{
stringUart=newUart;
ByteToStr(stringUart,someText);
Glcd_write_Text(someText,49,0,1);
}
}
if(oldUart==150 )
{
switch(newUart)
{
case 10:{ animationUart[7]=1; break;} //motor ON
case 20:{ animationUart[7]=0; break;} //motor OFF
case 30:{ animationUart[1]=1; break;} //turbine ON
case 40:{ animationUart[1]=0; break;} //turbine OFF
}
if(oldUart==160)
{
case 10:{ animationUart[4]=1; break;} //pump ON
case 20:{ animationUart[4]=0; break;} //pumpa OFF
case 30:{ animationUart[3]=1; break;} //ventilator ON
case 40:{ animationUart[3]=0; break;} //ventilator OFF
}
if(oldUart==170)
{
case 10:{ animationUart[6]=1; break;} //alarm pressure ON
case 20:{ animationUart[6]=0; break;} //alarm pressure OFF
case 30:{ animationUart[2]=1; break;} //alarm temperature ON
case 40:{ animationUart[2]=0; break;} //alarm temperature OFF
}
oldUart=newUart;
animateProcess();
}
}
}
//get byte from buffer
char getchar(void)
{
char _data;
// while (rx_counter==0);
_data=rx_buffer[rx_rd_index];
if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
--rx_counter;
return _data;
}
//display animation of motor rotating, turbine, ventilator..
void animateProcess()
{
if(animationUart[7]==1) //pump animation
{
switch (animation3)
{
case 1:{ Glcd_PartialImage(39,15, 15, 28, 15, 28, pump1); break; }
case 2:{ Glcd_PartialImage(39,15, 15, 28, 15, 28, pump2); break;}
case 3:{ Glcd_PartialImage(39,15,15, 28, 15, 28, pump3); break; }
case 4:{ Glcd_PartialImage(39,15, 15, 28, 15, 28, pump2); break;}
}
}
if(animationUart[7]==1) //turbine rotating
{
switch (animation1)
{
case 1:{ Glcd_PartialImage(39,15, 15, 28, 15, 28, turbine1); break; }
case 2:{ Glcd_PartialImage(39,15, 15, 28, 15, 28, turbin2); break;}
}
}
.
.
.
.
etc...
}
if(old [B] i [/B] Uart==101 )
if(oldUart==101 )
void interrupt()
{
if (PIR1.RCIF)
{
PIR1.RCIF = 0;
flag=1;
data__ =UART1_Read();
rx_buffer[rx_wr_index]=data__;
if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
if (++rx_counter == RX_BUFFER_SIZE)
{
rx_counter=0;
}
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?