Beginner help!


Closed Thread
Results 1 to 15 of 15

Thread: Beginner help!

  1. #1
    Join Date
    Apr 2012
    Posts
    6

    Default Beginner help!

    Just getting started with micro controllers and programing but I don't know where to start. I have a programer and a PIC12F683, im trying to make it take one simple ground signal and out put it on two different pins alternating back and fourth. So basically take 1 input and output it on two different pins. Where do I start? What pins on the pic do I use? Keep in mind that I have no programming knowledge!

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    Quote Originally Posted by Recognize View Post
    , im trying to make it take one simple ground signal and
    Welcome to the forum. I'm not sure I understand what you mean by a "ground signal". Are you talking about a noise signal?
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    Welcome aboard!

    I'm not sure what you want to accomplish. Do you want to make 2 LEDs blink one after another, you just turn the LEDs ON/OFF directly:

    - PIC wired as in PBP manual (section 2.4 in v2.60).
    - have one LED on pin B0 as in example.
    - have another just like it on pin B1.
    - configure your particular PIC properly.
    - define proper oscillator and then do this:

    Code:
    TRISB = %00000000    ' set all Port B pins as output
    
    LED1 = PortB.0           ' assign LEDs to Port B
    LED2 = PortB.1
    
    LOOP:
    
    LED1 = 1                   ' turn ON LED 1
    LED2 = 0                   ' turn OFF LED 2
    PAUSE 100                ' wait a bit so the human eye can catch the blink
    
    LED1 = 0                  ' alternate the LEDs
    LED2 = 1
    PAUSE 100
    
    GOTO LOOP              ' start over
    If you use Port A, there may be other considerations in the configs (section 2.5.1).

    This is off the top of my head. It's not written for optimization, it's written so you can understand easily what is happening.

    If you dig around in your PBP folder, you will find sample programs. I'm not on my programming PC so I can't tell you exactly where. There is a BLINKY example in there already.

    Robert



    EDIT: I don't get it, code comments used to line up properly before....
    Last edited by Demon; - 24th April 2012 at 19:03. Reason: trying to line up the code properly

  4. #4
    Join Date
    Nov 2009
    Location
    Virginia, USA
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    Quote Originally Posted by Recognize View Post
    Where do I start? What pins on the pic do I use? Keep in mind that I have no programming knowledge!
    Start by downloading the datasheet here http://www.microchip.com/TechDoc.asp...product=12f683 and read it, thats the fastest way to get up to speed on your 12F683.
    Gary-W4GNS
    MicroCode Studio Plus 5.0.0.2 MCSPX
    PBP 3.0 Gold Edition 3.0.5.4

    Tickled Speechless using PBP 3.0

  5. #5
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    Well, I sorta agree with the above. Back off a little and try getting a single LED to blink then work your way up. The PBP book talks about some of the peculiarities of the 12F683 so that's a really good place to start.

    But, there isn't a PORTB on a 12F683 so the above won't work.

    If you look, http://www.picbasic.co.uk/forum/showthread.php?t=14511, here it will explain a few ways to blink an LED.

    As far as pin selection, I'd shy away from using pins 3,6 and 7 on the 12F683 if you are doing ICSP. In Circuit Serial Programming (ICSP) allows you to program the PIC without having to remove it from the circuit. If you don't do this you'll have to pull the chip out of circuit, program it then reinsert it in circuit. At any point you can bend a pin or jiggle the circuit. Pin 3 which is Master Clear (MCLR), also pins 6 and 7 which are used for programming Data and Clock. I don't remember which is which. That leaves pin 5 GPIO.2, pin 3 GPIO.4 and pin2 GPIO.5 to put LEDs on. You can attach the Anode of the LED to any of these pins and attach the Cathode to ground.

    This link, http://members.shaw.ca/picgroup/Reso...Cadilly-13.pdf, will get you to a paper that really helps when using the 12F683.

    Best Wishes

  6. #6
    Join Date
    Apr 2012
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    Thanks for all the help guys! really filled me in alot.

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    Quote Originally Posted by AvionicsMaster1 View Post
    ...
    But, there isn't a PORTB on a 12F683 so the above won't work.
    Gaaaaa, didn't notice the PIC model.


    Quote Originally Posted by AvionicsMaster1 View Post
    ...
    You can attach the Anode of the LED to any of these pins and attach the Cathode to ground.
    ...

    Don't forget the current limitting resistor, most use 330ohms.


    Side note: I learned basic electronics and PIC programming just by using google. Whenever I was faced with a new component, like a LED, I'd google LED TUTORIAL and found everything I needed to know (anode, cathode, current-limitting resistor, etc).

    When I needed extra help, I'd ask on an Electronic 101 forum:
    http://groups.yahoo.com/group/Electronics_101/

    Robert

  8. #8
    Join Date
    Apr 2012
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    Will take that in mind thanks.

  9. #9
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    I have found, the hard way sometimes, the PIC is a pretty robust item. You don't need the current limiting resistors as the PIC will protect itself and only give you 20mA for the LED. It's a better design to have the resistors and if you're looking for a logic hi with only an LED.......well, I'll let you figure that out yourself. Just stick the LEDs onto the outputs and once you've figured out how to make it work you can finesse the design.

    There are several threads in this forum that will help you along the way but don't expect anyone to write code for you. It also helps if you post a schematic of what you're doing. Get one of the free schematic design programs and attach a drawing with your code. As they say, a picture is worth a thousand electrons. Or something like that.

    Best Wishes

  10. #10
    Join Date
    Apr 2012
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    TRISIO = 1000

    SIG1 = GPIO.3
    OUTPUT1 = GPIO.1
    OUTPUT2 = GPIO.2

    LOOP:

    OUTPUT1 = SIG1
    OUTPUT2= 0
    PAUSE 200

    OUTPUT1 = 0
    OUTPUT2 = SIG1
    PAUSE 200

    GOTO LOOP






    Would this work? Im trying to alternate sending sig1 (a negative ground connection from another electronic device) back and fourth between the other two pins. Is there any kind of format I need to do while coding, for ex. does there need to be a space between OUTPUT1 = GPIO.1 or Can i Just do OUTPUT1=GPIO.1 and also can i even name the outputs and inputs to whatever I want as long explain it at the start of the code as I did? Also ive been trying to get started with the basics, But I just havent got a chance to pick up some leds.
    Last edited by Recognize; - 25th April 2012 at 18:18.

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    When you post code, use the Advanced options, you can use the Code icon (looks like #) to post so it looks like this:

    Code:
    TRISB = %00001000
    
    SIG1 = GPIO.3
    OUTPUT1 = GPIO.1
    OUTPUT2 = GPIO.2
    
    LOOP:
    
    OUTPUT1 = SIG1
    OUTPUT2= 0
    PAUSE 200
    
    OUTPUT1 = 0
    OUTPUT2 = SIG1
    PAUSE 200
    
    GOTO LOOP
    You can name variables any name you want, as long as you don't use reserved names (check the manual for naming conventions and reserved names).

    Spacing is irrelevant as long as you don't break up words.

    Comments are optional, but they will help you remember what you are doing, and others go through your code.

    If you post in WYSIWYG format, your code gets messed up, ie: you lose leading % on bits. Hover your mouse over the big A icon, you want to be in Source mode.

    I don't understand the part about alternating a negative ground signal. As explained, your best bet would be to post a schematic of the components you are using and how you plan to wire them up.

    Robert

  12. #12
    Join Date
    Apr 2012
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    Code:
    Trisio = %001000
    
    ground var gpio.3
    pin1 var gpio.1
    pin2 var gpio.2
    
    loop:
    
    Pin1 = ground
    pin2 = 0
    pause 200
    
    pin1 = 0
    pin2 = ground
    pause 200
    
    goto loop
    Name:  Untitled.jpg
Views: 722
Size:  58.0 KBThe switches trigger buttons on a remote control. Thanks for all the help by the way ive really learned alot.
    Last edited by Recognize; - 25th April 2012 at 19:24.

  13. #13
    Join Date
    Apr 2012
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    Would this code send -5v to the switches alternating or is there some other way to do it?

  14. #14
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    Ahhhh, in a word no the code won't work and the schematic doesn't depict a working circuit.

    If I read it correctly, the schematic has gpio.2 hooked up to a switch that will pull the pin high when the switch closes. If by -5V you mean ground then that won't work. The second switch, hooked up to ground and +5V, will either burn out the switch or shut down your power supply, whichever is weaker.

    Your code doesn't take into account switch position. You'll need to use an IF/THEN or CASE SELECT or something like that. You really need to read the PBP manual, page 6, as there is working code to flash an LED. Except for the part about PORTB should be GPIO.x where x is the port where the LED is connected. There is also info in the book on how to hook up LEDs and switches. It's for a bigger PIC but you can see how is should be done.

    Why don't you focus on getting an LED to light then move on to switches? Read the manual and start with a simple program then you can add to it.

  15. #15
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Beginner help!

    Im on cell phone so I can't type details.

    Use IF statement to check if input pins are 1 or 0, then turn on output as desired.


    Check manual, must have example.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts