[SOLVED] microcontoller gone crazy?

Status
Not open for further replies.

tomas

Member level 1
Joined
Dec 16, 2012
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,553
Hi, I was doing my project on real schematic, and after some time it stopped working.



So problem:

when I use these 2 codes it works:

Code:
void main() {
      TRISD = 0x00;
      PORTD = 0x00;
      
      UART1_Init(2400);
      
      while(1) {
               if (UART1_Data_Ready() == 1) {

                          PORTD =  ~UART1_Read();
                           Delay_ms(500);

               }
      }
}

and transmmiter:

Code:
void main() {
TRISB=0xFF;
PORTB=0x00;
       UART1_Init(2400);
       
       while(1) {
                if (UART1_Tx_Idle() == 1) {
                
                if (PORTB.RB0==1){
                            UART1_Write(0x01);
                            }
                   if (PORTB.RB1==1){
                            UART1_Write(0x02);
                            }
                }
       }
}


but when I change receiver code to this:

Code:
unsigned char receive=0;
void main() {
      TRISD = 0x00;
      PORTD = 0x00;
      
      UART1_Init(2400);
      
      while(1) {
               if (UART1_Data_Ready() == 1) {
                          Delay_ms(100);
               receive =  ~UART1_Read();
                         Delay_ms(100);

                          if (receive == 0x01){
                          PORTD =  ~UART1_Read();
                           Delay_ms(500);
                          }
               }
      }
}

it is not working? Where is the problem? What is wrong with this "if" statement? (as I mentioned, some time ago, if statements worked perfectly, also these codes works in proteus, but no longer in real scheme...) :shock:
 

you are doing a UART1-read() two times for a single UART1_Data_Ready()

maybe this is the cause of the prob ?
 

Make it


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
unsigned char receive=0;
void main() {
      TRISD = 0x00;
      PORTD = 0x00;
      
      UART1_Init(2400);
      
      while(1) {
               if (UART1_Data_Ready() == 1) {
                          Delay_ms(100);
               receive =  ~UART1_Read();
                         Delay_ms(100);
 
                          if (receive == 0x01){
                          PORTD =  receive;
                           Delay_ms(500);
                          }
               }
      }
}

 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…