Jump to content

driving two relays with 12c508a


Recommended Posts

Hi Steve;

there you have a very simple example to do that. Relays are connected to gpio0 and gpio1, and they are turning one and off once every second (when one is on the other is off). Take a look...

 

#include "system.h"

 

 

main()

{

   trisio = 00001000b; // ( Output=0;Input=1 GP5,GP4,GP3[input Ever],GP2,GP1,GP0)

   cmcon = 7;    

   gpio = 0x00;

   

   while (1)

   {

set_bit (gpio,0);

clear_bit (gpio,1);

delay_s(1);

clear_bit (gpio,0);

set_bit (gpio,1);

delay_s(1);

   }

   

}

 

Best Regards;

Joan

Link to post
Share on other sites

HI,

 

   In addition to the fine code that Joan provided may I suggest the following link:

 

http://www1.jaycar.com.au/images_uploaded/relaydrv.pdf

 

This is for the hardware part of things, It tells you how to drive  relay with a npn transistor. you don't want to drive a relay directly with you pic. Plus the diode shown will protect you pic from back bfm or what ever that means. I have use this circuit myself and it has work thus far. (knock on wood).

Link to post
Share on other sites

Good point moyoyoyo.

 

The back EMF (electro motive force) is the voltage produced when turning off an inductive load, such as a relay.

 

This voltage can be very high, high enough to damage semiconductor devices, that aren't designed to withstand them.

 

An inductor tries to resist the change in current, producing a voltage using energy stored in the inductor. The protection diode (or flywheel diode) allow the energy to be safely dissapated, without the back EMF becoming dangerously large.

 

 

Regards

Dave

Link to post
Share on other sites

Thanks guys!  You've been a lot of help for me.  I'm awesome with the hardware end of things but not from the software.  I must be doing something wrong because when I try and compile the code I get all kinds of errors.

 

Anyway, do you guys have a good link or resource for guys who are just starting out with programming ?  Should I learn ASM or C?  Not really sure where to start and how to start?  I have all the hardware to program but I'm just not sure on the C side of things.

 

Thanks again for all your help!

 

Cheers!

-sp :)

Link to post
Share on other sites
  • 7 months later...
trisio = 00001000b; // ( Output=0;Input=1 GP5,GP4,GP3[input Ever],GP2,GP1,GP0)

trisio is now undefined for the 12C5xx parts, no idea why. Use this instead:

 

asm

{

   MOVLW 0x80  ; trisio = 00001000b; // ( Output=0;Input=1 GP5,GP4,GP3[input Ever],GP2,GP1,GP0)

   TRIS  0x06

}

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...