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.

rx tx switching PIC16F877

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, Im using PIC16F877 and transmitter/receiver. but I cant receive signal correctly until my tx level is high. How can I make it low? (In mikroC language)

Receiver Code:

Code:
char receive;

void main() {

       TRISD = 0x00;
       PORTD = 0x00;
       UART1_Init(2400);
       Delay_ms(100);

       while(1) {
              PORTD = 0;
                            Delay_ms(100);

                                               if (UART1_Data_Ready() == 1) {
               receive = UART1_Read();
               if(receive == 0x01)
        {       
                PORTD.F0 = 1;
                PORTD.F2 = 1;
                Delay_ms(2000);
        }
               if(receive == 0x08)
        {   
                PORTD.F1 = 1;
                PORTD.F3 = 1;
                Delay_ms(2000);
        }
        if(receive == 0x06)
        {   
                PORTD.F0 = 1;
                PORTD.F3 = 1;
                Delay_ms(2000);
        }
               if(receive == 0x05)
        {   
                PORTD.F1 = 1;
                PORTD.F2 = 1;
                Delay_ms(2000);

        }
                          }}}

Transmitter Code:

Code:
void main() {

      TRISB=0xFF;
      PORTB=0x00;
      UART1_Init(2400);
        Delay_ms(100);
      while(1) {
                                   if (UART1_Tx_Idle() == 1) {

                if (PORTB.RB2==1){

                            UART1_Write(0x05);

                            }
                   if (PORTB.RB3==1){

                            UART1_Write(0x06);

                            }
                            
                   if (PORTB.RB4==1){

                            UART1_Write(0x01);

                            }
                   if (PORTB.RB5==1){

                            UART1_Write(0x08);

                            }
                            }
                          }}
 

no, it is 2 PIC's and 2 transmitters/receivers (like a toy car and remote control) :)

- - - Updated - - -

problem is, that on the receiver part, transmitter pin is always high, so receiver cannot get the signal correctly...

- - - Updated - - -

if I cut the transmitter wire, receiver works perfectly. So how could I do this with program, not with hardware?
 

in which place i should use it? :)

- - - Updated - - -

and how this will turn off transmitter? :?
 

i guess this remove the internal pull up reisisotr and changes the pin to I/O and could solve your problem try it ., use it after the second line (trisb....)

hope this helps
 

I tried
TRISC = 0x80;
also
TXSTA=0b00000100;

but PORTC TX pin always is +5V... :| how should I make it 0 V?
 

hi
Are you sure, that your connections correct? I mean - tx one has connected to rx second uc.
If all it's ok, could you show to us realization of USART functions?

P.S. Vdd level on tx/rx line is idle state, and for initial conditions rx and tx line must be set as inputs (TRISC7 = 1 and TRISC6 = 1), anyway, show your code for uart functions.
 
Last edited:

Receiver (car):
Code:
char receive;
double volt = 0;
unsigned char svolt[23];

void main() {
       TRISA = 0xFF;
       PORTA = 0x00;
       ADCON0 = 0b01000000;
       ADCON1 = 0b10001110;
       TRISC.RC6 = 1;
       TRISC.RC7 = 1;
       TRISB = 0x00;
       PORTB.RB0 = 1;
       TRISD = 0x00;
       PORTD = 0x00;
     //   TRISC = 0x80;
       UART1_Init(2400);
       Delay_ms(100);

       while(1) {

              volt = ADC_Read(0);
              volt = volt * 0.0048875864003809;  //approx 5V/1023
              PORTD = 0;
           //   Delay_ms(100);

                if (UART1_Tx_Idle() == 1) {

                if((volt >= 1.75) && (volt < 1.85)) {
                            UART1_Write(0x01);
                            }
                   else if((volt >= 1.85) && (volt < 1.9)) {
                            UART1_Write(0x02);
                            }
                   else if((volt >= 1.9) && (volt < 1.95)) {
                            UART1_Write(0x03);
                            }
                   else if((volt >= 1.95) && (volt <= 2.3)) {
                            UART1_Write(0x04);
                            }
                 else
                            {

                              //  TXSTA=0b00000100;

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

               if(receive == 0x01)
        {       
                PORTD.F0 = 1;
                PORTD.F2 = 1;
                Delay_ms(500);
        }
               if(receive == 0x08)
        {   
                PORTD.F1 = 1;
                PORTD.F3 = 1;
                Delay_ms(500);
        }
        if(receive == 0x06)
        {   
                PORTD.F0 = 1;
                PORTD.F3 = 1;
                Delay_ms(500);
        }
               if(receive == 0x05)
        {   
                PORTD.F1 = 1;
                PORTD.F2 = 1;
                Delay_ms(500);

        }
                          }}}
                          }}
Transmitter (remote control) code:
Code:
#define LED1 PORTD.F0
#define LED2 PORTD.F1
#define LED3 PORTD.F2
#define LED4 PORTD.F3

char pirmas;
void main() {
      TRISD = 0x00;
      PORTD = 0x00;
   //         TRISC.RB3 = 0x00;
  //    PORTC.RB3 = 1;
      TRISB=0xFF;
      PORTB=0x00;
      UART1_Init(2400);
        Delay_ms(100);
      while(1) {

               if (UART1_Data_Ready() == 1) {

               pirmas = UART1_Read();

               if(pirmas == 0x01)
        {
                      LED1 = 1;
                Delay_ms(500);
        }
                 LED1 = 0;
               if(pirmas == 0x02)
        {             LED1 = 1;
                      LED2 = 1;
                Delay_ms(500);
        }
                          LED1=0;
                          LED2 = 0;
                 if(pirmas == 0x03)
        {
                      LED1 = 1;
                      LED2 = 1;
                      LED3 = 1;

                Delay_ms(500);
        }
                        LED1 = 0;
                        LED2 = 0;
                        LED3 = 0;
                       if(pirmas == 0x04)
        {
                      LED1 = 1;
                      LED2 = 1;
                      LED3 = 1;
                      LED4 = 1;
                Delay_ms(500);
        }
                      LED1 = 0;
                      LED2 = 0;
                      LED3 = 0;
                      LED4 = 0;
                          }
                          else{
                          if (UART1_Tx_Idle() == 1) {

                if (PORTB.RB2==1){

                            UART1_Write(0x05);

                            }
                   if (PORTB.RB3==1){

                            UART1_Write(0x06);

                            }
                            
                   if (PORTB.RB4==1){

                            UART1_Write(0x01);

                            }
                   if (PORTB.RB5==1){

                            UART1_Write(0x08);

                            }
                            }
                          }}
                          }
 

I need to turn on only receiver, transmitter should be off, ten receiver off, transmitter on. How can I do this switching? :(

- - - Updated - - -

What is these "syntax tags"?
 

code between syntax and /syntax tags. syntax and /syntak should both be inside square brackets and code between those to tags. Click # button and just replace code with syntax.

Post your microC projects file in a zip file. I will check and fix if there is any error.
 

I fear, it's pointless to discuss about software without describing the hardware connection of processor RX and TX pins.
 

there are transmitter and receiver programs (rfsim.mcppi and rfsim_rx.mcppi)

- - - Updated - - -

using these for transmitting/receiving http://www.abacom-tech.com/assets/data_sheets/RTF_L-DATA-SAWuser.pdf and PIC16F877

- - - Updated - - -

everything connected ok ;) checked with oscillograph. Because TX level is always +5V, PIC cannot receive...

- - - Updated - - -

in other words, I need to put tx to sleep :)
 

Attachments

  • RF Sim.rar
    68.3 KB · Views: 35

Thanks for clarifying. The transceiver will transmit CW RF with TX = 1 and block the receiver.

Generally enabling the PIC UART will also override TRI and PORT register bits of the TX and TX pins. According to the datasheet, clearing TXEN should release UART control of RC7, allowing you to set it to low state again. If the transmitter TX pin has a pullup, RC7 must be driven active low.

If the procedure doesn't work (I can't check it presently), you can also place a series resistor at RC7 and use an additional open-drain operated port pin to pull the TX pin low.
 

I need to turn on only receiver, transmitter should be off, ten receiver off, transmitter on. How can I do this switching? :(

if so, why do you use "UART1_Write" functions in your RX?

in other words, I need to put tx to sleep :)

as i said earlier, vdd on line is idle state, if you put it on gnd manually, i'm afraid that you get data on receiver all time and battery will die in small time.

if you have oscilloscope, you can try to seek tx line when data transmitting has a place.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top