Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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
Activity points
1,553
Hi, I was doing my project on real schematic, and after some time it stopped working.

scheme.jpg

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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top