CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Two channel relay control - need some help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Renovatio



Joined: 17 Dec 2016
Posts: 2

View user's profile Send private message

Two channel relay control - need some help
PostPosted: Sat Dec 17, 2016 12:10 pm     Reply with quote

Hi guys, I'm trying to do two channel relay control with two pics (16F88) and I wrote the codes. I used Rs232. It worked on Proteus but it's not working in real life. I mean for example I'm pressing the first button in transmitter but receiver is answering too late or never answering. I tried to close transmit when not in use but I couldn't. I think my transmitter working like jammer. So I don't know what I should to do right now. Can you help me guys? By the way; sorry for my english.

Here is the transmitter codes:
Code:

#include <16F88.h>
#FUSES NOWDT,PUT,XT,EC_IO,NOMCLR,NOBROWNOUT,NOLVP,CPD,WRT
#use delay(clock=4000000)
#use rs232 (baud=1200,xmit=pin_b5, rcv=pin_b2)

#byte TXSTA = getenv("sfr=TXSTA")
#bit TXEN = TXSTA.5


void main()
{

          while(true)
                {
               
                     port_b_pullups(TRUE); 
 
                  if (!input_state(pin_B0))
                       
                       {
                          TXEN=1;
                          putc(0b01010101);
                          putc(0b01010101);
                          putc(0b01010101);
                          putc('X');
                          putc('A');
                          putc('X');
                          putc('A');
                          putc('X');
                          putc('A');
   
                          while(!input(pin_B0));
                       }
                       
                   if (!input_state(pin_B1))
                       {
                          TXEN=1;
                          putc(0b01010101);
                          putc(0b01010101);
                          putc(0b01010101);
                          putc('X');
                          putc('B');
                          putc('X');
                          putc('B');
                          putc('X');
                          putc('B');
                                         
                          while(!input(pin_B1));
                       }   
                       
                       if ((input_state(pin_B0)) && (input_state(pin_B1)))
                            {                   
                                       TXEN=0;
                            }
                }
               
}

And receiver codes:
Code:

#include <16F88.h>
#FUSES NOWDT,PUT,XT,NOMCLR,NOBROWNOUT,NOLVP,CPD,PROTECT
#use delay(clock=4000000)
#use rs232 (baud=1200,xmit=pin_b5, rcv=pin_b2 )

int32 yenibilgisay=0;
byte islemyapildi=0,kesmegeldi=0;

char gelen;
int sayacx=0;

#int_rda    //rs232 kesmesi
void haberlesme()
{
   disable_interrupts(int_rda);     
   gelen = getch();
   kesmegeldi=1;
   clear_interrupt(int_rda);
   yenibilgisay=0;
}


void main()
{
   
   set_tris_a(0x00);
   output_a(0x00);
   kesmegeldi=0;
   enable_interrupts(int_rda);
   enable_interrupts(GLOBAL);
   
  while(1)
   {
   if  ((kesmegeldi)==1)
      {
           delay_ms(1);
           if  ((gelen)=='X') sayacx=sayacx+1;
           
                 if  ((sayacx)>=1)
                         {
                                if ((islemyapildi)==0)
                                         {
                                                if (gelen == 'A')
                                                     {
                                                          output_toggle(pin_a2);
                                                         islemyapildi=1;
                                                      }
                     
                                               if (gelen == 'B')
                                                      {
                                                             output_toggle(pin_a3);
                                                             islemyapildi=1;
                                                      }   
                                          }
                         }             
                 kesmegeldi=0;
                 enable_interrupts (int_rda);
                 enable_interrupts(GLOBAL);
            }
                       
 
          if ((islemyapildi)==1) yenibilgisay=yenibilgisay+1;

          if (yenibilgisay>250)
             {
                islemyapildi=0;
                yenibilgisay=0;                   
                sayacx=0;
             }
   }
  }

Proteus:
[img] https://postimg.org/image/3pb55mya1/ [/img]

Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Sat Dec 17, 2016 1:22 pm     Reply with quote

Lets step through siome things to start with.

RS232 'idles' driven. The line has to stay high.
Why on earth are you turning off the RS232?. Depending on what is in the output latch this can result in the slave 'seeing' a break. Not what is wanted. Also the characters will still be sending for a couple of mSec after the putc, so switching the UART off, may well result in 'partial' characters being sent.....

Your master chip may not even be running. You have two oscillator fuses set. Proteus doesn't understand fuses, and will 'believe' the chip is clocked even if it isn't. Always start by getting a set of fuses, and prove your chip is actually working by doing a simple 'flash an LED' output using these fuses.

Don't use protection on a chip, until you have your code working. Doing so, means that a full erase of every location in the chip has to be done to change even a single byte. Uses up chip flash memory 'lives' pointlessly.

Look at ex_sisr.c. Don't fiddle around disabling the receive interrupt in the receive device. Doing this means characters could be missed.

Because characters could be missed, you _must_ have 'ERRORS' in your RS232 setup. This adds code to 'unlock' the UART if it gets hung because characters have been missed, Proteus doesn't understand that this will happen to the UART.

As you can see in two ways straight away, Proteus will mislead you about what a real chip will do. It is a complete waste of time, telling you that things 'can work', when they won't. Start with the master chip and get this working without Proteus. Get it sending data at the correct rate. Then once this is working, start on the second chip.
Renovatio



Joined: 17 Dec 2016
Posts: 2

View user's profile Send private message

PostPosted: Sat Dec 17, 2016 4:57 pm     Reply with quote

Ttelmah, at first thank you for your time. As you can see I'm begginer and I want to learn, and improve myself. I have an interest in rf devices and it's my first try. I did what you said and it worked very well. Nobody answered me but you did. Thanks again Smile
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Dec 18, 2016 10:11 am     Reply with quote

If you're interested in RF modems look into the HC-12 devices. SIMPLE to use, cheap to buy, and they work !
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group