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] What is the use of UART terminal in proteus?

Status
Not open for further replies.
Re: RF Transmitter and receiver interfacing with PIC16F877a

Yes, use UARTx_Read_Text() function. Tx1 should send "STx1" and Rx1 should check for the delimiter "Tx1". Tx2 should send "PTx2" and Rx2 should use delimiter "Tx2".
 

Re: RF Transmitter and receiver interfacing with PIC16F877a

Sir , i did it but it didn't works
so i here post my simulation for automatic railway gate ,also the code, of my mini project

the idea is i transmit a code to close the gate , if no obstruction , send back the pass signal. transmission is using RF modules.


the problem is, the feedback code is not received by the receiver at initial transmitter side.:-?

transmitter side code is


Code:
 //Tx code

char uart_dat = 83,uart_rct;
int i,j=3,k=0;
int _duty=175;
void main() {
    TRISB = 0;
    TRISA = 0xFF;
    TRISD=1;
    TRISC = 0x00;  //port c as output
    PORTA = 0x00;
    PORTC = 0x00;
    PORTB =0;
    PWM1_Init(1000);
PWM1_start();
PWM1_Set_Duty(_duty);
PORTB = 1;               //Run motor in clockwise
    UART1_Init(9600);
    Delay_ms(100);
    for(i=2;i>=0;i--)
       {
         while(i>0) {
             UART1_Write(uart_dat);       // 83 = S for start
             Delay_ms(2000);
             i--;
           }
    delay_ms(1000); 
        }

    delay_ms(50000);
      TRISC =0xFF;     // port c as input
      
       UART1_Init(9600);                         // initialize UART1 module
       Delay_ms(100);

while (1) {
  /*if (UART1_Data_Ready() == 1) {          // if data is received
    UART1_Read_Text(uart_rct, "$$", 25);    // reads text until $$

        }
            }
    } */




      UART1_Init(9600);
      Delay_ms(100);

          if(UART1_Data_Ready() == 1)
              {
                uart_rct = UART1_Read();



                if(uart_rct == 80)PORTB.F3=1;
                else PORTB.F5=1;

                uart_rct = '\0';
               }
       }
                
    }




the receiver side code is



Code:
char uart_rd = 0;
int i,j,k=2;

void main() {
    TRISB = 0x00;
    TRISA = 0xFF;
    TRISC = 0x80;
    TRISD = 0x00;
    PORTA = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;

    UART1_Init(9600);
    Delay_ms(100);

   do
        {
          if(UART1_Data_Ready() == 1)   //checking for a start command
              {
                uart_rd = UART1_Read();



                if(uart_rd == 83)PORTD.F0=1;
                else PORTD.F0=0;

                uart_rd = '\0';
                }

          }while(PORTD.F0==0);  // start command obtained exit loop
           for(i=5;i>=0;i--)  //msb of counter
             {
               PORTB =i;
               for(j=9;j>0;j--) //Lsb of counter
                  {
                    PORTD =j;       //Lsb from port d
                    delay_ms(1000);
                  }
               PORTD =0;
               delay_ms(1000);
             }
         PWM1_Init(1000);       // setup motor circuit
         PWM1_start();
         PWM1_Set_Duty(160);
    do
    {
    if(PORTD.F0==0);  // if counter completed proceed
      {
          do
          {
             if (PORTD.F0==0) // counter complete check just for convinience
             {PORTB.F4 = 1; //Run motor in clockwise

              delay_ms(1000);
              PORTB.F4 = 0; // stop motor
              TRISB.F6 = 1;  // 6th pin as input for sensor
              if(PORTB.F6==0) continue; // if no object  goes to last of this brace
              else if(PORTB.F6==1) // if object open gate
                {
                  PORTB.F5 = 1; //Run motor in anti-clockwise
                  delay_ms(1000);
                  PORTB.F5 = 0;   //stop motor
                  delay_ms(2000);
                 }
              }
           }while(PORTB.F6==1); // loops this until object is cleared , F6=0
            PORTD.F6=1;   // indication that everything clear
            UART1_Init(9600); // send back pass command
            delay_ms(100);  // stabilise uart
            while(k>0) {         // k is initialized as 2 so send 2 P
                UART1_Write(80);  // send P
                Delay_ms(2000);
                k--;
              }
        }
    } while(PORTD.F0==1);
}
 

Attachments

  • Proteus RF Template.rar
    26 KB · Views: 54

Re: RF Transmitter and receiver interfacing with PIC16F877a

Zip and post the mikroC project files. Post each project file as a separate zip file. UARTx_Init() has to be called only once before while(1) loop.

I don't know whether bi-directional RF communication works with the Proteus RF Template I gave. I had tried it once but it didn't work for me.

Why there are motors at both circuits? If you want to control only one railway gate then you need only one motor. Explain clearly how your system should work.

Is it not enough if the sensor board sends data to gate opener circuit to close the gate if train is coming and then another sensor board sends data to gate control board to open the gate after the sensor detects train leaving?
 
Last edited:

Re: RF Transmitter and receiver interfacing with PIC16F877a

Sir ,
The first motor represents the running train, and second motor is at gate. where there is a counter display.

I had found such a circuit using IR sensor, but it didn't ensure much security.

shall i proceed without this feedback simulation , in actual circuit? , or wait for this simulation to work?
Since you didn't get the simulation, did you got it in actual circuit?

the attached file contain all the Simulation, transmitter project code, receiver project code
sorry i couldn't post it separately.
 

Attachments

  • Automatic railway gate.zip
    113.4 KB · Views: 64

Re: RF Transmitter and receiver interfacing with PIC16F877a

You didn't answer to my questions. I asked you to explain how your system should work. I didn't use 434 MHz RF module but I used this.

Explain in detail how your system should work. I will write a sample code.

**broken link removed**

It is a better module for your project. It can be configured using simple AT commands after connecting with PC. Once configured it can be used as Transmitter, Receiver or Transreceiver. Try to use this module. It will work in hardware so test in hardware.

The module I mentioned has to be supplied with 9V and connected to PC COM port or PC USB port using RS2322USB adaptor.

The PRG port header has to be connected to COM port and 9V while programming. After that remove from COM port and also remove 9V supply.

Then you have to give 5 to 12V power to PVR port pins and use the TTL port pins or RS (RS232) port pins to interface with microcontroller.

The TTL pins are 3.3V type. You will need a voltage level translator to interface TTL pins of module to 5V PIC UART pins.

If RS port is used then you need a MAX232 between microcontroller and RS port pins of RF module.
 

Attachments

  • RF Modulev4.3 - how to use.pdf
    2.3 MB · Views: 81

Re: RF Transmitter and receiver interfacing with PIC16F877a

the concept is

Initially the position of the train is determined ,either by GPS or by an RF id, then send a code like S [ to start ] to the gate. at the gate counter starts, and at the end, gate closes. now check for any object like car is trapped. if it then re open the gate. if everything goes fine, then send back a pass signal to train and train passes. If there is something get trapped gate will no close and no reply to train then train should slow down to stop.
 

Re: RF Transmitter and receiver interfacing with PIC16F877a

Is this what you want? Your method of closing the gate and then checking if something is trapped is not a good idea.

S is sent from train to gate control board on arrival

After S is received the Gate control board checks if there is any obstacle on the track.

If yes then Gate control board will send F (fail) to train and also keeps the gate opened.

If there is no obstacle then gate closes and then sends P (pass) to train.
 

yes, one more modification- on sending back the fail signal, the train should slow down to stop, If P is the reply , then train passes without any interruption.
 

Ok. I need to know one more thing before writing the code . How Gate re-opens again after Trains passes?
 

I am trying to locate the train using GPS, so we have two locations first some km before the fixed point gate and a point after the gate, at this second point i sends again a signal to the gate to open the gate.
I think that , we could use an RF ID to recognize the second point from where gate open signal could be given.
another way is to use IR sensors to detect the train passage, when train passes, ir ray gets cut, then it will become steady.

Sir , i had these ideas . Actually i was concentrated at those transmission, reception case. I am very sorry to say that, i hadn't thought seriously about this gate opening section. That is a great mistake.
 

first of all thanks for your attention sir.
 

Sir I am waiting for your code,also could to tell how to set configuration word in micro c?
 

Try these codes. I have not tested the codes.
 

Attachments

  • Railway Gate Control.rar
    103 KB · Views: 67

i had run the simulation. when i pressed, 'O' at train OTX1 had send , but no further process. motor doesn't runs
to run the simulation, i had changed the name of receiver to ATX2.
as you said, problem may be in the program.
 

Problem is not in the program. Problem is in Proteus file. I told you that it will not simulate more than one pair of RF modules. If you want to test that then write a code for Tx1 to send some data to Rx1 and then if Rx1 receives this data then make Tx2 to send some other data to Rx2. Tx1 and Rx2 will be connected to 1st MCU and Rx1 and Tx2 to 2nd MCU.
 

okey,

I tried my work in hardware. [ used my code ], but when the counter decrements, sometimes it gets stuck at any arbitrary value { wonderfully, they are multiples of ten - 20,40,50} . If i reset the circuit, then mostly it is there in that previous part where it got stuck. why?
 

Post your code (Complete mikroC project files).
 

Sir, here is my receiver side micro c files.

- - - Updated - - -

i had used my codes
 

Attachments

  • rxxxxx.rar
    25.4 KB · Views: 51

Where is the 7 Segment related code? I did not trace your code but made some changes.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
char uart_rd = 0;
unsigned int i = 0, j = 0, k = 2, pwmDuty = 160;
 
void main() {
 
        INTCON = 0x00;
    ADCON0 = 0b11000001;
    ADCON1 = 0b11000110;
 
    T1CON = 0x00;
    T2CON = 0x07;
    
    SSPCON.F5 = 0;
    
    TRISE.F4 = 0;
    
    TRISA = 0xFF;
    TRISB = 0x00;
        
        TRISC = 0x80;
    TRISD = 0x00;
    
    PORTA = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;
        PORTD = 0x00;
 
    UART1_Init(9600);
    Delay_ms(100);
 
    PWM1_Init(1000);                            //setup motor circuit
    PWM1_SetpwmDuty(pwmDuty);
 
    while(1) {
 
        while(1) {
 
            if(UART1_Data_Ready()) {
 
                        uart_rd = UART1_Read();
 
                        if(uart_rd == 'S') {
                    PORTD.F0 = 1;
                    break;              //start command obtained exit loop
                }
                        else PORTD.F0 = 0;
 
                        uart_rd = '\0';
                    }
 
            }  
 
            PORTC = 0x02;                           //caution light starts
 
            for(i = 5; i >= 0; i--) {               //msb of counter  at PORTB
             
                    PORTB = i;
 
                    for(j = 9; j > 0; j--) {            //Lsb of counter at PORTD
                  
                            PORTD = j;                  //Lsb from PORTD
                            Delay_ms(1000);
                    }
 
                    PORTD = 0;
                    Delay_ms(1000);
            }
 
            PORTB = 0x00;                       //set ports to low
            PORTD = 0x00;
         
            PWM1_start();
         
            do {
 
            if(!PORTD) {                    //if counter completed proceed
            
                    while(1) {
          
                            if(!PORTD) {            //counter complete check just for convinience
 
                                PORTB = 0x10;       //Run motor in clockwise
 
                                Delay_ms(3000);
                                PORTB = 0;      //stop motor
                                TRISB.F6 = 1;       //6th pin as input for sensor
                                                
                                if(PORTB.F6) {      //if object open gate
                                
                                    PORTB = 0x20;   //Run motor in anti-clockwise
                                    Delay_ms(3000);
                                    PORTB = 0;      //stop motor
                                    Delay_ms(3000);
                            break;      //break loop
                                }
                            }
 
                    }                   
 
                        PORTC = 0 ;                 //caution light stops
                        PORTD = 0x20;               //indication that everything clear
 
                        while(k > 0) {                  //k is initialized as 2 so send 2 P
                            UART1_Write('P');       //send P
                            Delay_ms(2000);
                            k--;
                        }
                }
 
            }while(PORTD.F0);
 
    }
}

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top