PDA

View Full Version : Newbie to pic but not electronics



Techbuilder
- 6th July 2007, 11:29
Hi I have stepped into the world of the pics

basicly I have a knowledge of electronics but I just started out using pic micro controllers.

I wanted to use a pic 16f84a to control leds and servos wirelessly

now I know I need a transmitter and a receiver but for the programing what codes would be used to press a button or turn a potentiometer and have a servo move or leds turn on or do a sequence I programed for the leds or the servo.

Would this have to be done through serial and if so is there any other ways?

paul borgmeier
- 6th July 2007, 14:17
Check out Bruce's Website

http://www.rentron.com

or more specifically, pages like this

http://www.rentron.com/ruf-bot.htm

Techbuilder
- 6th July 2007, 19:28
Thank you for replying but I did try that website already the ruf bot source code was not functional. I tryed entering it in microcode studio and it gave me a list of things that were wrong.

SteveB
- 6th July 2007, 19:36
I'm sure you will hear this eventually from someone, so I might was well be the one to say it:

Have you got just a simple LED blinking? Did you get it responding to your button? Have you got the PIC to read the POT and output the value in some way (like a LCD)? Have you been able to TX/RX serial over normal lines, like with a PC?

Here is the point. As most of us have discovered, there is a bit of a learning curve, both with the hardware portion of PICs as well as the firmware. So start small. Take it a one part at a time. Once all the individual parts are functioning, start assembling the parts into a whole application to meet your needs.

In this process you will get a lot of help from the folks on this forum.

SteveB

skimask
- 6th July 2007, 20:23
Thank you for replying but I did try that website already the ruf bot source code was not functional. I tryed entering it in microcode studio and it gave me a list of things that were wrong.

That 'ruf bot' code has been posted at that site for quite some time, and I don't think the author would intentionally leave it posted if it didn't work.
So, since you are just beginning in PICs...
Do you have a PIC programmer? Which one?
Do you have PicBasic or PicBasicPro from MeLabs or one of their distributors? Which version?
Which errors did Microcode Studio give you? Which version of MCS are you using?
Have you built a plain ol' 'Blinky LED' type thing yet?
Have you tried to build anything more complicated than that? More than one LED? Pushbuttons lighting LEDs? Pushbuttons controlling servo's?

Don't try and tackle the whole thing at once from the get-go...you'll get discouraged and quit before you even get started... You didn't learn how to drive in a high-performance sports car...

Break it down, simple stuff first, combine the simple stuff into not-so-simple stuff, then put it all together...

EDIT: In other words, just what SteveB said (which I would've had notice had I bothered reading...)

Techbuilder
- 6th July 2007, 21:04
I have done the blinking led and I own picbasic pro that I got from microengineering labs. My programmer I bought from ebay and I do not remember what errors I got since it has been months since I tried it.

How do you know rentron didn't just put it on with out trying the firmware out?

Who knows

But anyway I don't get how reading the inputs work yet.


Let's start simple say I wanted two leds to chase eachother

I connect led 1 to RB0and led 2 to RB1

and I guess I would connect the switch to RB2

but would I have to read RB2 Input
then send and output to RB0 and RB1 when RB2 makes contact?

The PIC I am using is a 16F84A

skimask
- 6th July 2007, 21:22
How do you know rentron didn't just put it on with out trying the firmware out?
And throw ANY credibility out the window? I don't think so... Besides, I've seen their work, I've used their products and software. Good stuff...


But anyway I don't get how reading the inputs work yet.
Let's start simple say I wanted two leds to chase eachother
I connect led 1 to RB0and led 2 to RB1
and I guess I would connect the switch to RB2
but would I have to read RB2 Input
then send and output to RB0 and RB1 when RB2 makes contact?
The PIC I am using is a 16F84A

Good example of how to use a button and the BUTTON command in Section 5.2 of the PBP manual. But that's probably too much for your example...
To read a pin, you have to set it to an input (as the datasheet states), you may also need a variable to store the state of that pin so you can work with it elsewhere.

input_pin var portb.2
input input_pin
temp var byte
temp = input_pin

Now "temp" has the state of PortB.2.
Again, break it down to the simplest possible level...
Write a program that reads the portb.2, and have the LED on portb.0 light up if the button on portb.2 is pressed, and the LED on portb.1 light if the button is released.

Techbuilder
- 6th July 2007, 21:36
Ohh I get it that makes perfect sense

So all I would have to do is read the input

but say when I pressed the button I want the RB0 led to flash 4 times and RB1 led to flash 8 times when I press the button once.

How would that work?

ALFRED
- 6th July 2007, 23:55
Do you mean how would you have the different LEDs flash a different number of times depending on how many times you push the button? This could be accomplished by waiting for the input pin to go high then adding 1 to a pre-defined variable. You would then wait for the input pin to go low before monitoring the input for a high signal. After a pre-defined amount of time waiting for the high signal, the number of button pushes would be stored in the variable that holds the count.

skimask
- 7th July 2007, 00:13
Ohh I get it that makes perfect sense

So all I would have to do is read the input

but say when I pressed the button I want the RB0 led to flash 4 times and RB1 led to flash 8 times when I press the button once.

How would that work?

For/Next.....If/Then.....counters in a loop....thousand different ways of doing it.
Write some code, we'll dig thru it all...

sougata
- 7th July 2007, 06:42
Hi,

While PicBasic makes your life real easy I still recommend to study the internals of the PIC micro to get the most out of PBP. To get started try the link here http://techtrain.microchip.com/x14/ and view or download the flash based presentation. IMO it accelerates learning the PIC....

Techbuilder
- 11th July 2007, 23:29
Thank you very much everyone has been helpful

Although I was reading on the button command wouldn't that be the easiest way to go?

skimask
- 12th July 2007, 11:43
Although I was reading on the button command wouldn't that be the easiest way to go?

Not if you're just reading a single switch on a single port performing a single function...
Now if you're looking for functionality like auto-repeat, debouncing, sure, button may be the way to go.

Techbuilder
- 12th July 2007, 21:34
Gotcha I guess I will just go with IF, THEN , GO Statements
How exactly would that work

I know I would have to set LED to HIGH

but is this kind of how it would look

IF port.0=1 THEN
port.1 = high

Something like that?

Techbuilder
- 12th July 2007, 22:45
Here's a better constructed code I made then the one up

Button var PORTB.0 ' Push button
LED1 var PORTB.1 ' Led 1
LED2 var PORB.2 ' Led 2
Pushed var byte ' Variable will contain the byte
If PUSHED =1 Then ' If button is push
High LED1 ' Turn on the LED
IF PUSHED=0 Then
High LED2

Endif

skimask
- 13th July 2007, 00:08
Just so nobody gets the wrong idea...I'm not being a royal a$$ here....

In your program...(and again, not being an a$$, just trying to get you to understand what's what here)

Button var PORTB.0 ' Push button
LED1 var PORTB.1 ' Led 1
LED2 var PORB.2 ' Led 2

Pushed var byte ' Variable will contain the byte

If PUSHED =1 Then ' If button is push
High LED1 ' Turn on the LED
IF PUSHED=0 Then
High LED2
endif

You have 'If Pushed = 1'...Pushed is a variable...Where is 'Pushed' being set to anything, at least anything that is going to be useful to you?

T.Jackson
- 13th July 2007, 01:17
Instead of taunting people, Jeremy, it would be better to directly point out the error. You'll find that most people don't come to forums asking for help as a first resort.

xobx
- 13th July 2007, 17:05
shouldnt it be something like this?


Button var PORTB.0 ' Push button
LED1 var PORTB.1 ' Led 1
LED2 var PORB.2 ' Led 2


If Button=1 Then ' If button is push
High LED1 ' Turn on the LED
IF Button=0 Then
High LED2
endif

Melanie
- 13th July 2007, 17:48
You have two IF's but only one ENDIF, so that would error...

Try this... which includes a few additional things to think about....



ButtonA var PORTB.0
LED1 var PORTB.1
LED2 var PORTB.2

TRISB=%00000001

Loop:
If ButtonA=1 then
High LED1
LOW LED2
else
LOW LED1
HIGH LED2
endif
Goto Loop

End


Finally, check your PBP manual - BUTTON is a reserved word, you can't use it as a variable.