PDA

View Full Version : New to PIC



Mike2545
- 24th July 2009, 00:47
Hello, I have been using the Basic Stamp for a few projects and have just recently purchased the PicBasic Pro Compiler. I was wondering if I would also need the MicroCode studio Plus or does that come with the software above.

I am awaiting delivery soon and can't wait to start programming PICs.

Mike2545

mackrackit
- 24th July 2009, 01:56
The free version of MCS that comes with PBP is good enough. The CD will also have MPLAB that you may also like.
Every thing you need to write and compile code comes on the CD.

Welcome to the world of PICs.

Mike2545
- 24th July 2009, 01:59
Thanks for the info. Do you know if I will be able to use a 'JuneBug' for a programmer?

mackrackit
- 24th July 2009, 02:20
Not sure. But if it can take a HEX file and send it to the PIC then it should. Does it come with software?

Mike2545
- 24th July 2009, 02:27
No software, but I can use MPLAB/swordfish to program it so...it should work.
I will know when I get the package.

Mike2545
- 25th July 2009, 05:37
Ok so I got the PICBasic pro compiler today and am having trouble with PORTA on the PIC18F1320.

I have 6 charlieplexed leds on Porta.0, Porta.6 and Porta.7 as seen here http://www.blueroomelectronics.com/downloads/Junebug%20Assembly%20Instructions.pdf

I cannot get a led to light on PORT6 or 7

Here is my code
ADCON1 = 127
input porta.7

led var porta.0
sink var porta.6
low sink
loop:
pause 5
toggle led
pause 5
toggle sink
goto loop
end

Archangel
- 25th July 2009, 06:28
Hi Mike, Welcome to the forum. You have analog stuff to turn off on PortA.
ADCON0 = 0 'disable A/D module disabled
ADCON1 = 127 'AN1 through AN6 as digital
Hmmm no CMCON or CMCON0 . . . . still looking . . . .
Ok now I looked at the Data sheet on the junebug. PortA is used as outputs, so let's start here:


ADCON0 = 0 'disable A/D module disabled
ADCON1 = 127 'AN1 through AN6 as digital
DEFINE OSC 4 ' or some other number as fits you

PortA = %00000000 ' a zero for each pin drives LATA registers all low so when made an output they will all be @ ground
TRISA = %00000000 ' All portA pins as outputs
PortA = %10000001 , Light 1 on
Pause 200
TRISA.7 = 1 ' Tristates PortA.7
PortA = %01000000 'Light2 on
pause 200
TRISA = %00000001 ' Tristates RA0
portA = %01000000 ' Light3 on
and so on, here is untested code

Different methods shown above.
A better way might be to use 2 lookup tables and a for next loop to display this somewhat unusual LED Array.


ADCON0 = 0 'disable A/D module disabled
ADCON1 = 127 'AN1 through AN6 as digital
DEFINE OSC 4 ' or some other number as fits you
TrisVar Var Byte
PortVar Var Byte
index Var Byte
PortA = %00000000 ' a zero for each pin drives LATA registers all low so when made an output they will all be @ ground
TRISA = %00000000 ' All portA pins as outputs
main:
For index = 0 to 5

lookup index,[%00000000,%00000000,%00000001,%00000001,%01000000, %01000000], TrisVar
lookup index,[%00000001,%01000000,%01000000,%10000000,%10000000, %00000001], PortVar
PortA = PortVar
TrisA = TrisVar
Pause 200
next index
GoTo Main
end

savnik
- 25th July 2009, 07:51
You need to set internal oscillator because you use porta.6 and porta.7 as I/O.
See page 17 on datasheet of pic18f1230.

Mike2545
- 25th July 2009, 19:29
Thanks for the input guys, still no luck with the program, maybe its the Junebug... I don't know. Any other suggestions?

mackrackit
- 25th July 2009, 19:37
If you think it might be the "June bug" try a simple hardware setup with one LED on a non analog pine and see it you can make it blink.

Mike2545
- 25th July 2009, 21:05
I can get the other ports to respond to programming but PORTA.6 and 7 don't do as they should.

mackrackit
- 25th July 2009, 21:11
I can get the other ports to respond to programming but PORTA.6 and 7 don't do as they should.

OK, that rules out the "junebug".

Can you post your current code, configs, and schematic so we can take a look?

Mike2545
- 25th July 2009, 21:29
Here is my code, it flashes leds on PORTA.0 and PORTB.0

ADCON0 = 0
ADCON1= 127
define OSC 4
led var PORTA.0
sink var PORTB.0

loop:
toggle PORTA.6
pause 5
high led
pause 5
low led
pause 5
high sink
pause 5
low sink
goto loop
end


PORTA.6 is just low, it does not toggle or go High if I change the code.

The schematic is simple, I connected VPP, +5, Gnd, PGD and PGC.
I have 470 ohm resistors from the PIC to leds connected to GND.

Could it be the clock output function? How do I set INTRC_OSC_NOCLKOUT?

mackrackit
- 25th July 2009, 21:51
http://www.picbasic.co.uk/forum/showthread.php?t=543
The above talks about how to set the configs.
You can do it in your code or just modify the PICs *.inc file.

Mike2545
- 26th July 2009, 19:18
Well, nothing I have tried with this has worked, I can get it to work in Swordfish Basic but Microcode studio is not what I expected for the Price they charge.

Has anyone else gotten a 18F1320 to work correctly with PICBasic Pro?

I am beginning to regret shelling out good money for a product that does not work as well as a free compiler.

mackrackit
- 26th July 2009, 22:19
Did you get the OSC set correctly ?

Post you config settings.

ChrisHelvey
- 27th July 2009, 00:25
Hi Mike,

Welcome to the forum.

I was reading through this thread and it looked like something Savnik pointed out might not be too clear. (But very correct.)

Porta.6 and a.7 are reserved for an external oscillator, so they can't be used as regular pins unless you put a config line in PicBasic Pro to explicitly enable them as pins. That's probably why the other LEDs work, but those don't.

Since I don't know anything about Swordfish, I can't compare how it does this. For me, once I started understanding the setting of fuses, things started getting smoother.

Hang in there. I find PicBasic Pro to be very powerful. So far, whenever something doesn't go as planned, it is just a little thing I haven't learned yet.

Mike2545
- 27th July 2009, 00:50
OK, I got the OSC set with OSCCON =$60 so its not running at 37khz anymore, which makes sense that the pause statements were way too fast for the result I was getting; pause 5 is way too small for what I was used to in basic, now pause 500 is more like it.

As for setting the fuses, I think I will need help figuring out how to do that.


Mike2545

mackrackit
- 27th July 2009, 01:09
OK, I got the OSC set with OSCCON =$60 so its not running at 37khz anymore, which makes sense that the pause statements were way too fast for the result I was getting; pause 5 is way too small for what I was used to in basic, now pause 500 is more like it.

As for setting the fuses, I think I will need help figuring out how to do that.


Mike2545

First off read the thread I linked to above. Then let's just change the configs in the Inc file. If you were going to change things often then doing it in code is handy.

Go to the PBP directory and find the Inc file with your chips name. There you will see the config settings. You may want to male a backup of the file.

Then go to the MPASM directory in program files and find the coorosponding Inc there. The microchip Inc near the end has all of the possible settings.

Change the PBP Inc to the way you want it.

I am on my phone at the moment so I can not show the exact change.

Mike2545
- 27th July 2009, 01:44
Yep, that did it!!



I just needed to find the .Inc files...On my C: drive (That bit of info might have been helpful) :)

Anyway, I am glad to have solved this, first of many, I'm sure, issue.

Thanks for your help.

Mike2545

mackrackit
- 27th July 2009, 02:14
I thought that info was in the other thread?

Oh well , glad you got it going.

Read you later. Have fun!