My code not work

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
v.sorroche
Posts: 2
Joined: 04 Apr 2018 14:37

My code not work

#1 Post by v.sorroche » 04 Apr 2018 14:43

why my code note work, where is the error

Code: Select all

void main()
{
 uart1_init(9600);
 ddra.B0=1;
 porta.B0=0;
 while(1)
 {
  if(uart1_data_ready()==1)
  {
   if(uart1_read()=='a')
   {
    porta.b0=!porta.b0;
   }
  }
 }
}

niman
Posts: 24
Joined: 06 Dec 2016 00:06

Re: My code not work

#2 Post by niman » 05 Apr 2018 02:18

Can you try with this..

void main()
{
uart1_init(9600);
ddra.B0=1;
porta.B0=0;
while(1)
{
if(uart1_data_ready()==1)
{
if(uart1_read()=='a')
{
porta.b0=~porta.b0;
}
}
}
}

v.sorroche
Posts: 2
Joined: 04 Apr 2018 14:37

Re: My code not work

#3 Post by v.sorroche » 05 Apr 2018 13:07

still not working. :(

but if i change "==" for "!=" works with all keys including 'a'.

i try too

xx='a'
if(uart1_read()==xx)

and too

xx='a'
yy=uart1_read()
if(xx==yy)

in the both not works

i try the compiler in the version 6 and 7.

my uc is atmega128

sorry for the bad english, i am from brazil

any idea for this "bug"

niman
Posts: 24
Joined: 06 Dec 2016 00:06

Re: My code not work

#4 Post by niman » 11 Apr 2018 00:06

try to put filter on your command when you transmit the data like (a) and when you receiving the data you can filter out the data you want.
in your transmit code, put this:

Code: Select all

if (UART1_Tx_Idle() == 1)
  {
  UART1_Write('(');
  UART1_Write('a');
  UART1_Write(')');
  }
and your receiving code put like this :

Code: Select all

if(UART1_Data_Ready())
{
  chk = UART1_Read();

      if(chk=='(')
{
  UART1_Read_Text(txt,")",2);  // reads text until 'enter' is found
if (txt=='a')
{
your code;;;;;;;
}
delay_ms(100);
}
}

please note , should be the format { char chk , txt ; } in your main function

Post Reply

Return to “mikroC PRO for AVR General”