Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Trying to get started with my Junebug.. :)

Status
Not open for further replies.

Fordy

New Member
I want to start by saying thanks to Bill/blueroomelectronics. I may have come across as an angry hater in one thread here when I was basically just concerned as it had been a few weeks and my Junebug hadn't arrived - I was having a lot of issues with buying/selling at the time which didn't help.

I received it a while ago, and yesterday I finally had the time to put it together - I'd been saving it for something to do in all my time off now that I've finished GCSEs (for around a month..)


My next task, was obviously to get something working on it.

I've used the version of BASIC in Circuit Wizard before, to program CW's rebranded "Genie" chips (they're PICs).


I also kind of understand Assembly - or the basics of it. And I was all set to use it for my first LED blinker program - when I ran into my first brick wall:

I can't find a register file map for the 18F1x20 anywhere. Not even in the datasheet.


So how do I know the addresses of STATUS, PORTA, TRISB etc.? How do I know when to switch bank if there's no mention of which bank anything's in in the datasheet?



After getting angry with that for a few hours (and thinking that the 3rd LED coming on was an achievement of something, rather than marking activity or whatever) I switched to looking at C.

With C, I thought, I wouldn't need to know the addresses, as it's all stored in another file. I couldn't find that file - MPLAB hadn't installed it.

Not wanting to uninstall and reinstall MPLAB (and not liking C anyway), I hti another brick wall.


I then downloaded Swordfish BASIC.

I'm now looking at a (very very slightly) modified version of Bill's LED chaser sequence.



So I'm glad that worked out. But I'm left with several questions.


1) Where can I find out th addresses of registers such as PORTA, TRISA on the 18F1x20?
2) Where can I find out what's on which bank on the 18F1x20?
3) Should I use Swordfish, Assembly, or C? Any will have a learning curve - so I need to look to what will be most helpful as I progress really.
4) A good tutorial for using <answer from 3> on the Junebug?
5) Is there a list somewhere of which pin on the 18F1320 on the Junebug is connected to which LED? Only the inputs (switches, IR1, pots etc.) seem to be labelled on the board.


Thanks in advance for any help!
 
read page 47
Its a 12 bit address system for this chip. yes it has lots of banks.

Please read the datasheet in detail it contains all the information you need. If you encounter a specific problem come back to us. But for the info you requested here the devices are well documented.
 
I'm almost completely new to PIC programming - my knowledge is not enough to read more than a sentence of that datasheet before being utterly lost.

On page 47 it mentions bank 0 and 15 only. Assuming there are none higher than 15 - that's 16 banks altogether.

My understanding of a 2-banked 16F is that you switch between banks by "BSF STATUS,5" and "BCF STATUS,5". The very nature of a bit is that it can only have two states - set or cleared, so how do you alter STATUS,5 for 16 different banks? By using the other bits within STATUS?


I can't come back with a specific problem because I can't understand enough to start.


Without a diagram like this:
**broken link removed**

For the 18F1x20 I don't understand how I'll know which registers are in which bank.
 
OK i understand everyone needs to start somewhere, but this is quite an advanced PIC for a beginner and not one that is usually recommended for learning. so please explain:
Why have you chosen this device?
Are you able to change PIC to a simple one?
I'm not trying to criticise you here but these are sensible questions you should ask yourself.

Now to give you some help.
This PIC has a 12bit address system so that explains the 3digit hex address.
Also this chip has 16 banks, most of these are general purpose registers (GPR) (RAM memory) - remember this is volatile meaning it will lose its data on reset - EEPROM offers non-volatile memory.
The last bank, bank 16, is where the special function registers (SFR) are and these control all the chip functions - timers, ADC, EEPROM, Interrupts and IO

Now they have very kindly provided you with an access bank, this makes talking to the SFR and some of the GPR very easy. With the 'a' bit you can select a=0 to address all the SFRs (80-FF) or (00-7F) of the GPR in bank0. Alternativly you set a=1 and you can address any bank you like by setting the bank select bits (all 4 of them 0-3).
I suggest you probably wont need more than the 128 GPRs provided by a=0.

Now your going to ask what or where 'a' is. Its simply a part of the code instruction (look at page 191 onwards). So for example you want to move the working register to a file you use the MOVWF instruction as usual. But now you need to provide the instruction with an 'a' bit (if you leave it blank it will assume 1 for a). so MOVWF MYREG, 0 (if myreg is in GPR 000h-07Fh)
 
To answer your specific question, you select banks by loading the Bank Select Register (BSR). There is an instruction to load the BSR, movlb 3 will put 3 in the BSR register.

Edit, on the 1320 you won't really need to worry about banking. Just include the P18F1320.inc to get the register definitions and put your variables in the 0-0x7f area.

Mike.
 
Last edited:
on the 1320 you won't really need to worry about banking. Just include the P18F1320.inc to get the register definitions and put your variables in the 0-0x7f area.

exactly, just have the register definitions and you'll be fine. To see how this work you should make a simple code and get some register addresses working in simulations
 
Thank you for your help, I think I may have bitten off more than I can chew to begin with.

I'm using the 18F1320 because it's what comes with the Junebug - a later question was going to be can I program any PIC that has <=18 pins in the Junebug.


Do you think it would be best to learn Swordfish BASIC first, as it's a higher level language and should be easier to get to grips with?
 
Yes the Junebug will support 16F and 18F chips. I'm not sure how to do it as i dont have a Junebug. google it and you'll probably find the answer quite soon.

Dont give up on this chip, yes it is a bit advanced but if you dont have to use the advanced bits of it. And with the access bank you can almost pretend its a 16F chip, in fact its easier, you dont worry about banking at all.

What software are you using, i would suggest MPLAB IDE - but i've never used anything else for PICs.

As you getting to understand PICs i would suggest Assembler, this is a machine level language. This means you have to write the code for every single action in the chip - so it really gives you a good idea of how it works and whats happening.

If you use Swordfish BASIC (which is a cut down version of C) this is a more readable language higher level language - but you dont really find out whats happening. For instance you say 'timer on' '1ms' and your computer write severl lines code in the PIC for you (not actual code back there btw). This sounds really nice and easy but when it goes wrong ...and it will... you wont have a clue why.

Start with assembler - make a code to turn an led on (should require <10 lines of program)
then make it come on when you press a switch.
then make it blink
and progress.....
 
Last edited:
BTW all the instructions you need are in the PIC datasheet page 191+, after the initial introduction they give you examples of how each instruction should be used - read this.
 
Thanks again for all the help.

I just plugged in and fired up MPLAB for another go today.


That's when I hit just about the most newbie error around: PK2Error0022: No PicKit2 found.

It was working fine yesterday, I've no idea what's changed. Any suggestions?
 
um, dont have a Junebug, and i usualy use the microchip programers so i'm not really sure.

Is the power on, i guess its powered from USB so most likely.
Is the chip in, and the correct way arround, you most likely haven't moved it since yesterday.
Have you changed the USB port your using?
Do your dip switches have to be in a deffined arangment / have you moved them since yesterday.

The Junebug instructions also have a troubleshooting guide.

Also if you get it working, Junebug instructions also have an example assembler code you can use and modify.
 
Ah, fixed that. The 18F2550 was loose :rolleyes:.


I'm stuck again however... A the top of my program I wrote:

List p=18F1320
include <p18F1320.inc>

But when I can't find where that .inc file is...
 
Good glad you fixed that. But be aware - you have a nice test project there and as my lecturer kept telling me "these devices will blow up if you look at them too closely!". Thats not quite true but you should handle them with some care.

Ok the .inc file should of been included with the MPLAB instalation i belive. You shouldn't have to find the file i dont think


What is the error MPLAB is giving you?
 
Last edited:
Well, I gotta tell you, chasing LEDs have never looked so beautiful.


Just got it running.

I guess my best next step would be to understand each line of code in the Junebug example (I wrote it out, but I don't understand most of it).
 
Congratulations!

And your on the right path - read through the example as much as you can (its always hard to read code other people have writen!)
Then either add a push button control to it to turn it off/on or backwards/forwards. but write it from scratch.

Use the instructions given in the PIC datasheet - this is the best bet for sure
 
So just reading through it logically, I can guess a few things; I'd be greatful if you could tell me if I'm right, or where I'm wrong:

Code:
LED		macro	x,y
		movlw	x
		movwf	LATA
		movlw	y
		movwf	TRISA
		call	Delay
		endm

^ This defines a macro with two values: x and y, and then sets x as LATA, and y as TRISA. I know TRISA defines which pins are inputs and which are outputs, so I'm guessing that LATA sets them high or low? But I thought that was PORTA? Anyway, it then obviously calls a (subroutine?) called Delay, and ends the macro.

Does that sound about right?

Code:
Count	equ 0
		org		0
		bsf		ADCON1, 0

^ The variable count is set to zero. I've no idea what org or baf do - or what ADCON1 is?


Code:
LED1	LED b'00000001', b'10111110'
LED2	LED b'01000000', b'10111110'
LED3	LED b'01000000', b'00111111'
LED4	LED b'10000000', b'00111111'
LED5	LED b'10000000', b'01111110'
LED6	LED b'00000001', b'01111110'
		bra		LED1

^ So this must be the actual sequence, te beginning of each line is labelled LED1-6 (?) and then the LED macro is called and values are assigned for x and y? Is that right? Seems to make sense. I don't know what bra does however?


Code:
Delay	decfsz	Count, f
		bra		Delay
		return
		END

^ Lastly, the Delay (subroutine?) is defined, Count is decreased until it reaches zero in steps of f (how many is that though?!). bra is used again, although still can't work out what that is, on Delay - and I believe return ends a block? END obviously marks the end of the program.


Again, very grateful to know of anything I've got wrong, or the bits I didn't know!
 
Very good, you've got the grip of this.

So 'org 0' is the reset vector, that is it marks the first line of the program and this is the line the chip jumps to in a reset / brownout or other fault. It could be written org 0x000

BRA is an unconditional branch. I belive this is basicly 'GOTO' so GOTO delay, GOTO LED1.

The count is interesting, at reset its 00000000 (an 8bit variable). The comand is to decrement then see if its zero - if zero skip next comand.
so we decrement 00000000 and we get and overflow of the data giving us FFFFFFFF which is >0
so the counter keep counting down until zero where it is returned.

It returns to the last line of the macro - (the line after delay is called) which happens to be 'end macro'. this returns it to the main program which changes to the next LED.

So a question for you - how would you decrease the count (and thus increase the led speed)? and after that how would you increase it to greater than it is now?
 
Last edited:
Thanks, glad I wasn't completely off the ball.


I can think of two ways to change the speed - firstly by changing the line Count equ 0, say to 500 or something. So it would start at 500 rather than FFFFFFFF.

Or alternatively, by changing the stepping of the decrement - f is hex for 15, so it could be made twice as fast by changing the stepping to 1e (30) - I assume?


To increase the count greater than it is now, you could either chang the stepping to <f (<15) or after the decfsz line, simply do it again - so it would take twice as long.


Would that work? I'll go ahead and try..
 
Status
Not open for further replies.

Latest threads

Back
Top