PDA

View Full Version : 12f675_fuse_about_to_blow!



Pages : [1] 2 3 4

LEDave
- 15th February 2010, 21:26
Hi everyone. Oh boy do I need some help here!

I've just purchased a PICkit1 Flash Starter Kit. I've loaded the MPLAB IDE software and the PICkit1 Classic program and been able to load and re-load the demo hex code.

So, time for me to program the 12F675 to turn a single LED on, oh deary me.At this point several questions arise.

1/ I notice that the PICKit demo program has two program files, one .ASM the other a 'C' program and also the Holy grail here an HEX output file. So question:

What program language do I start to learn Assembler code or C programming?

2/ I'd like for starters to write a program whereby I put 5v on input pin 4 and that makes an output pin 7 go +5v and lights an LED,no more complicated than that.

Can anyone point me in the right direction here?

All help really appreciated.

LEDave

BobK
- 16th February 2010, 03:53
Hi LEDave,

Welcome to the PICBasic Pro forum. What language you want to learn? I personally wanted something easy and quick to allow me to turn ideas into actual working projects. Both assembly and C were too complicated for me. I started with PIC Basic with the Basic Stamps and after one great project I was hooked and moved up to PIC Basic (PBC) using PICs and then onto PICBasic Pro. I have made quite a few projects (and lots of money too!) that were relatively easy to create and implement. Ms. Melanie (site adminstrator) once said "as long as your project works the way you want it to what difference does it make what language you use".

If you are interested in assembly or C you might want to check out the Microchip website. I think there are some other sites available also. Google should help you find what you are looking for.

HTH,

BobK

Archangel
- 16th February 2010, 07:38
What program language do I start to learn Assembler code or C programming?
LEDave
1. Assembler . . . zero cost, much brain damage, much tedious typing.
2. C language, Can be High cost to about PBP cost, less typing, less brain damage, still much more of both than PBP.
3. PBP near English syntax, no silly bracketing { . . . } Moderate to low cost, Cheap upgrades, which include new manual, less brain damage. There are things you will have to learn regardless of your choice, like how to interpret a data sheet, which is probably the steeper part of the curve. PBP is available in the UK from Crownhill
Do not buy from an Unauthorized seller (I. E. Ebay ) as you will not be able to upgrade product.


DEFINE OSC 4
GPIO = 0 ' set all outputs low
TRISIO = %00000001 'Set GPIO.0 to input
cmcon = 7 'Disable analog comparators
ANSEL = 0 'disable analog select so ports work as digital i/o


main:
if GPIO.0 = 1 then GPIO.1 = 1 'turn it on
pause 500
gpio.1 = 0 'turn it off
goto main

end

Here go for a test drive:
http://melabs.com/pbpdemo.htm

LEDave
- 16th February 2010, 16:16
First off, many thanks for the replies Bob & Joe, very much appreciated I can assure you.

So programming these devices in 'C' and Assembler is out and using PIC-BASIC seems the way to go right?

A few more questions then if I may.

1/ Can I still use my PICkit1 Flash Starter kit to load / run and test my programs even using PIC-BASIC (I'd hate to think I'd bought the kit for nothing). Or do I have to buy another evaluation board from Melabs as well as the program / compiler?

2/ Just to make sure here, PIC-BASIC isn't included in my Microchip PICkit is it?

3/ Will the PICBASIC PRO™ Compiler Demo from Melabs allow me to run and create a HEX code for the program that Joe posted for me? And can I then load the HEX code into my PICkit Starter Kit and into a 12F675 chip?

I hope all my questions make sense and thanks for your time everyone.

LEDave

mackrackit
- 16th February 2010, 16:29
So programming these devices in 'C' and Assembler is out and using PIC-BASIC seems the way to go right?
Most of us here think PBP is the way to go :) Mix a little ASM in now and then and you will be able to do just about anything you can think of.


1/ Can I still use my PICkit1 Flash Starter kit to load / run and test my programs even using PIC-BASIC (I'd hate to think I'd bought the kit for nothing). Or do I have to buy another evaluation board from Melabs as well as the program / compiler?
All Pic Basic Pro is for is to make a HEX file. You will not need to buy another programmer until you out grow the PICkit1. Then get the PICkit2.


2/ Just to make sure here, PIC-BASIC isn't included in my Microchip PICkit is it?

No, it is not. All the PICkit is for is to take a HEX file and place it on the chip.


3/ Will the PICBASIC PRO™ Compiler Demo from Melabs allow me to run and create a HEX code for the program that Joe posted for me? And can I then load the HEX code into my PICkit Starter Kit and into a 12F675 chip?

Yes. I still use my PICkit1 now and then.

LEDave
- 16th February 2010, 16:44
mackrackit

Thanks for the speedy reply.

Have I got this right? I can use the "PICBASIC PRO™ Compiler Demo from Melabs" and make some simple 12F675 projects without having to buy anything else.

And then, when I get more confident I can buy the BASIC or PRO-programmer / compiler.

Or do I have to buy the BASIC-programmer / compiler now before I can go any further.

LEDave

mackrackit
- 16th February 2010, 17:03
Unfortunately the demo will not work with the 675, but the PICkit1 will work with most any 14oin or 8pin PIC.


Demo version PIC® MCU support:

PIC12F683, 16F627(A), 16F628(A), 16F84(A), 16F688, 16F690, 16F87, 16F88, 16F870, 16F871, 16F872, 16F873(A), 16F874(A), 16F876(A), 16F877(A), 16F882, 16F883, 16F884, 16F886, 16F887

And the demo is limited to 31 lines of code.

Yes, try before you buy. That is what the demo is for.
In my opinion if you are going to stay with MCU programming, get the pro version.

LEDave
- 16th February 2010, 17:37
mackrackit

So if I buy the 'pro version' I can use my PICkit1 to load the hex file into my projects?

mackrackit
- 16th February 2010, 17:46
Yes.

PBP will generate the HEX. Then you will use the PICkit1 software to load the HEX onto the PIC. The PICkit does not care who or what makes the HEX.

LEDave
- 16th February 2010, 17:48
mackrackit

So if I buy the 'pro version' I can use my PICkit1 to load any HEX files I create into my projects?

What about the program Joe S wrote for me in this thread (Is it written in PICBASIC) how do I turn that into a HEX file and run it on my PICkit?

Oop's sorry for double posting I lost my way there for a second.

Also interesting website of yours.

All very confusing right now but I'll get there.

LEDave

LEDave
- 16th February 2010, 18:01
So if I buy the 'pro version' I can use my PICkit1 to load any HEX files I create into my projects?

What about the program Joe S wrote for me in this thread (Is it written in PICBASIC) how do I turn that into a HEX file and run it on my PICkit? Will my MPLAB IDE convert it?

Oop's sorry for double posting I lost my way there for a second.

Also interesting website of yours.

All very confusing right now but I'll get there.

LEDave

mackrackit
- 16th February 2010, 18:01
Yes, the code Joe wrote is in done in PBP.

BASICS....
When you get your PBP CD there will be a program there called Micr Code Studio (MCS). This is where you will write your code. You can use other editors but MCS is probably best for starters.

Copy Joe's code into MCS or write your own. There are config fuses that need set, Joe did not include that but we can go over that when you are ready.

Once you are happy with the code there is e a "button" in MCS to click and PBP runs to compile the code into HEX. The HEX is saved in your project directory.

The PICkit1 has software of its own. Open that and open the HEX created by PBP using MCS. There will be a "Write" button in the PICkit software. ( you already know about that I guess).

My web site is a work in progress. I hope it will help someone along the way.

LEDave
- 16th February 2010, 18:09
"There will be a "Write" button in the PICkit software. ( you already know about that I guess)."

Yes I've managed to load / erase and reload the demo HEX programs.

So I need to save up some pennies then for the pro-version, all fascinating stuff though and I will get there.

Like Arni, I will be back.........!

Many thanks

LEDave

HenrikOlsson
- 16th February 2010, 18:33
Hi Dave,
I'll expand a bit on what's already been said. Not because any of it is wrong, just trying to help you get the picture.

This is basically how the code gets from PBP syntax to a .hex file in your chip:
IDE -> Compiler -> assembler -> device programmer -> PIC

1) IDE. Integrated Development Enviroment (a fancy word for a text editor on steroids) This is where you actually write your PBP program, it can be Notepad or MicroCode Studio, which is included with PicBasicPRO when you buy it. The later is recomended but not needed.

2) Compiler. This is PicBasicPro - it compiles or "translates" your BASIC statements and commands into assembly language that can then be converted to a .hex file by the...

3) Assembler. There are two assemblers available, one comes with PBP and one comes with MPLAB. There are times when one needs to use the one over the other but lets not get into that at the moment. The assembler is what takes the assembler listing that the compiler produced and generates a .hex file that can be programmed into the PIC by the....

4) Device programmer. This is the hardware devices and it's associated software used to get the .hex file fromt tha harddrive on the computer into the actual PIC chip. As you probably can see here it doesn't know or care how you got that .hex file.


This may sound like a lot but if you use the MicroCodeStudio IDE it all happens behind the scene. You type in your BASIC program and hit the compile button and out comes a .hex file ready to be programmed into your PIC by the PICKit1 or any other device programmer supporting the PIC-chip you're using.

If you're lucky the PicKit1 is even directly supported by MicroCodeStudio. IF that is the case you don't even need to launch the PicKit1 software to get the .hex file into the chip - MicroCodeStudio handles that for you as well. One single click get you from BASIC code in the IDE to a programmed chip.

/Henrik.

LEDave
- 16th February 2010, 18:59
Thanks for that Henrik, very informative.

What would you suggest I do now? Buy the PicBasicPRO and start learning or go another route in the interim.

Dave

HenrikOlsson
- 16th February 2010, 21:14
Well, it depends on what your goal is. If all you want to do is turn an output on when an input goes high you can get away with the demo but I guess you're ultimately looking to do more (way more) than that.

If you are taking this seriously then by all means buy PBP, it's worth every penny. There are other compilers, both BASIC and other languages (C, PASCAL etc) available but since this forum is aimed at the products from Melabs (PBC and PBP) specifically that is what we like to use and discuss "around here".

As you know, it IS associated with a learning curve though so you SHOULD start small, just like with the example you posted. Blink a LED, blink two LEDs, get a LCD up an running etc etc - small steps. Trying to bite off too much at one time will only get you frustrated.

Good luck!
/Henrik.

Bruce
- 16th February 2010, 21:32
Hi Dave,

Get PBP. You'll never regret the investment. I own/use 3 high-end C compilers, and do a lot of commercial work. I can push 99.9% of my embedded controls work out of here, all done with with PBP, and never have to worry about it working as expected 20 years down the road.

It's rock solid, and a lot easier than using C. There's only 1 other basic compiler for the PIC that's worth a look, but it hasn't had anything but beta updates for the last several years. And you have to jump through hoops just to install each new beta version.

LEDave
- 16th February 2010, 23:03
Once again thanks to everyone for their input and help.

It's looking like PICBASIC PRO Compiler 2.60 is the one to aim for right?

I appreciate the learning curve I have to work through but I am a plodder and will gradually build up my knowledge base (along with one or two questions on here no doubt).

Any other areas I should look into to start the learning process?

Many thanks: Dave

mackrackit
- 17th February 2010, 01:04
Many will buy books to start learning, so far in my opinion there are not any out there worth anything. Bruce is working on one, when it comes out I will change my mind. Until then his site is a good place. Left hand side about half way down.
http://rentron.com/

Examples to work on from MeLabs, along with the PBP manual.
http://www.melabs.com/resources/samples.htm

And of course this forum. Steve put this post together just for this purpose.
http://www.picbasic.co.uk/forum/showthread.php?t=11116

And do not forget to have the data sheet for the PIC you plan to use handy.

That should get you started.

Bruce
- 17th February 2010, 01:21
Download the PBP demo: http://www.melabs.com/pbpdemo.htm

You can make enough, in short order, just by selling nifty things you create with the PBP
demo, to buy the full version. I personally know several college students that have used
the demo version to make a fortune.

Archangel
- 17th February 2010, 05:28
Yes, the code Joe wrote is in done in PBP.

BASICS....
When you get your PBP CD there will be a program there called Micr Code Studio (MCS). This is where you will write your code. You can use other editors but MCS is probably best for starters.

Copy Joe's code into MCS or write your own. There are config fuses that need set, Joe did not include that but we can go over that when you are ready.
Joe did not include those, because the "DEFAULT" config located in the 12F675.inc file will work and I did not want to add to his confusion, rather just to demonstrate how simple PBP really is, but I digress, Dave (mackrackit) is right, Configs are something you will have to deal with, regardless of your choice of compiler.
In a nutshell _ _ _ You write a program in C or PBP and compile it into an assembly program, the Assembler, I E MPASM, turns it into a HEX File and your PICKit stuffs it into the PIC. And If you wrote it right then your PIC is Fat, Dumb and Happy Doing what you ordered it to do. And yeah, I know the demo does not support the 675, so 2 bucks? gets you a 12F683 which it does support. As for your programmer, it will stuff the hex from any of the methods available as long as it supports the chip you have chosen. My first programmer was a JDM clone from an eBay seller in Bulgaria for $8.00 US, used Iprog, or PonyProg or one of those freebie programs to operate it. The best part about PBP is this forum, nobody here will steer you wrong intentionally.

LEDave
- 17th February 2010, 17:11
As ever many thanks to you all for your help and guidance.

I'll download the demo tonight and try and convert the program Joe posted earlier in the thread into a HEX file and load it, Ill let you know how I get on, then take it from there.

I do suspect there could be one or two more questions popping up along the way.

Fascinating subject though with loads of possibilities.

Dave

LEDave
- 17th February 2010, 18:13
I've downloaded the demo program and I'm about to buy 10 of these chips.

They are the right ones for Joe's LED program? Can anyone confirm please.

http://uk.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=6230178

Dave

mackrackit
- 17th February 2010, 18:26
Those are the correct ones.

LEDave
- 17th February 2010, 18:33
Cheers mackrackit.

They should arrive in two or three days time.

In the meantime I'll try and make a HEX program.

Finger X'd

Dave

LEDave
- 17th February 2010, 20:02
5x12F683 PICS order just placed...........!

LEDave
- 17th February 2010, 23:26
I was looking through some of the helpful links that mackrackit posted on this thread earlier and came across this link below:

http://www.melabs.com/resources/samples.htm#12F675pbp

Half way down the page there's a program to blink an LED using a 12F675 PIC so I thought great, I'll copy the HEX file (link below) which I did.

http://www.melabs.com/resources/samples/12F675/PBP/BLINKX4.HEX

I then opened up my PICKit classic programmer and tried to copy the saved HEX code (which I'd saved as a notepad document) into the programmer but I couldn't even find the notepad HEX code, it just doesn't show up in my documents.

Any ideas on how to load this copied HEX code into the programmer so I can load it into my 12F675 PIC.

Starting to feel inadequite (I can't even spell it) right now.

One day when I've cracked the learning curve I'll look back at all this and smile...I hope.

Dave

mackrackit
- 18th February 2010, 04:09
If you copied the HEX and pasted it into notepad... probably why you had problems.

Now, the PICkit1 board has the LEDs in a matrix. So the coding is a little different than just HIGH this and LOW that.

Lesson #1 :)
The PIC has three states a pin can be in.
OUTPUT HIGH
OUTPUT LOW
INPUT

Here is the code to light the first three LEDs on the PICkit1 on and off, in sequence.
The HEX is attached. Save it and re-name it taking the ".txt" off.


'16F676 PICKIT1 TEST
' PORTA 1,2 4, AND 5 ARE THE LED PINS
@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
ANSEL = %00000000
CMCON = %00000111

START:
'D0 HIGH
TRISA = %11001111
PORTA = %00010000
PAUSE 500
'D1 HIGH
TRISA = %11001111
PORTA = %00100000
PAUSE 500
'D2 HIGH
TRISA = %11101011
PORTA = %00010000
PAUSE 500
GOTO START

LEDave
- 18th February 2010, 14:29
Hi mackrackit

The program worked a treat, many thanks for your time and input on this. I saved the HEX code as Blink.HEX just added .HEX to the end (Doh) and it loaded into the PICKIT1 and then loaded into the PIC and away it ran:

D0 - D1 - D2 flashing one after the other, brilliant!

I noticed you wrote the program for the 16F676 PIC yet it ran perfectly on my 12F675 chip, very clever but how does that work? I guess both chips have certain ports and configurations that are common.

Would it have been possible to have copied the program you wrote and pasted that directly into Microcode Studio - demo and created the HEX file that way? I would like to do this if it can be done to get a feel for converting program code to a HEX file.

David

mackrackit
- 18th February 2010, 19:39
It was late, I was tired, I picked the wrong PIC...
Got lucky that it worked...

But yes, the code will compile with the demo version if it is for the correct PIC.

Darn bifocals...

LEDave
- 18th February 2010, 21:36
Couldn't get it to compile, I had:

Symbol not previously defined Ansel (I had five of these).

And one: Overwriting previous address contents.

ANSEL is analogue select right? It's my understanding that your:

ANSEL = %00000000 code line makes all the pins read in digital, or turn any analogue input off (I think) so can't understand a problem here.

Also: CMCON = %00000111 puts out decimal 7 which turns the comparitor off? Is that right? This instruction didn't seem to cause a problem.

Could all this be because the 16F676 PIC wasn't listed when I compiled it? It wasn't in the demo version drop down list.

Plenty of head scratching going on here, great fun all though, I'll be glad to figure the basics out.

Dave

mackrackit
- 18th February 2010, 21:43
What PIC did you pick from th drop down?

LEDave
- 18th February 2010, 22:07
12F683 The nearest one to the 12F675 (probably doesn't work like that does it?).

mackrackit
- 18th February 2010, 22:26
This compiles for the 12F683. May not be the correct pins to do the expected, I did not check that.


ANSEL = %00000000
CMCON0 = %00000111

START:
'D0 HIGH
GPIO = %11001111
GPIO = %00010000
PAUSE 500
'D1 HIGH
GPIO = %11001111
GPIO = %00100000
PAUSE 500
'D2 HIGH
GPIO = %11101011
GPIO = %00010000
PAUSE 500
GOTO START
ANSEL is for turning the ADC on or off. Not clear why it gave an error.
The CMCON should have though.
"Overwriting previous address contents" is because I had the fuses set in code and the fuses commented out in the *.inc.
http://www.picbasic.co.uk/forum/showthread.php?t=543

Now for some data sheet reading :)

LEDave
- 18th February 2010, 22:31
Is there a set of code instructions for THE PBP demo version?

I'm trying to get an understanding of GPIO and the register TRISIO. If you set a TRISIO bit low you make the corresponding GPIO pin an output (I think) Except GP3 which is always an INPUT.

I've got a very blurred picture of how this all fits together, one day the fog will lift.... I hope.

Dave

mackrackit
- 18th February 2010, 22:40
http://www.melabs.com/resources/index.htm#Manuals
http://melabs.com/products/pbpis.htm


I'm trying to get an understanding of GPIO and the register TRISIO. If you set a TRISIO bit low you make the corresponding GPIO pin an output (I think) Except GP3 which is always an INPUT.
Now I see a mess up in my last code


GPIO = %11001111
GPIO = %00010000

should be


TRISIO = %11001111
GPIO = %00010000

I think..... :)
Sorry about that.

LEDave
- 18th February 2010, 22:46
Hi mackrackit

Yes I ran that code and it compiled with no errors.

I loaded the HEX code (confirmed write successful) but the LED's didn't light?

I reloaded you earlier HEX file and all three LED's jogging along nicely.

mackrackit
- 18th February 2010, 22:57
Yup, different code for different PICs.
When do your 12F683s arrive?

LEDave
- 18th February 2010, 22:57
I changed the code from GPIO to TRISIO

RE-compiled, re-loaded the HEX code file and away she ran.....!

Time for me to pause here mackrackit. I need to break your program down and figure out exactly what's going on. That way I can move on.

I'll try and figure it out and if you'd be so kind you can tell me how I got on.

It's the only way for me to learn.

As ever thanks for your help.

Dave

mackrackit
- 18th February 2010, 23:03
I'll try and figure it out and if you'd be so kind you can tell me how I got on.
:)
I like it when someone wants to learn.
I will be here....

LEDave
- 18th February 2010, 23:07
The 12F683's arrived today! I didn't order them until late last night, talk about service, I love the internet....:-)

I changed the 12F675 PIC over to a 12F683 and it ran your program a treat.

I've got a lot to learn still, a huge amount but really enjoying it.

My first project (I'm getting ahead of myself here I know) but my first project will be to make a 12F683 OUTPUT binary coded decimal four bit words and drive a seven segment display. I figure with the 12F683 having six outputs this is a viable project.

Dave

LEDave
- 18th February 2010, 23:16
"I like it when someone wants to learn.
I will be here...."

Thanks for that mackrackit I appreciate it. I hope I don't drive you insane during my learning curve.....!

I'm off to bed now to dream of TRISO's.......

Dave

mackrackit
- 19th February 2010, 05:50
My first project (I'm getting ahead of myself here I know) but my first project will be to make a 12F683 OUTPUT binary coded decimal four bit words and drive a seven segment display. I figure with the 12F683 having six outputs this is a viable project.
Well....
I hate to tell you this but I think there is something wrong with your counting...
Or mine :)

Archangel
- 19th February 2010, 06:03
Hi LEDDave,
16F628A might be easier to drive 7 segment as no driver translator chip required ( because it has enough ports ). Your biggest challange will be due to 31 lines of code limitation, in the Demo program.
I do not know if assembly code is counted in that limitation.
If you have that problem I am sure Mackrackit and I would compile a few programs for you, enough so you believe this compiler is worth it's price.

mackrackit
- 19th February 2010, 06:13
Hi LEDDave,
16F628A might be easier to drive 7 segment as no driver translator chip required ( because it has enough ports ). Your biggest challange will be due to 31 lines of code limitation, in the Demo program.
I do not know if assembly code is counted in that limitation.
If you have that problem I am sure Mackrackit and I would compile a few programs for you, enough so you believe this compiler is worth it's price.
Yup, I will help.
Problem is, I can not find a "large" PIC that will work with the demo and the PICkit1. (14 pins)
So LEDDave may have to get a 16F676 and one of us build the hex for that...

Archangel
- 19th February 2010, 06:34
Yup, I will help.
Problem is, I can not find a "large" PIC that will work with the demo and the PICkit1. (14 pins)
So LEDDave may have to get a 16F676 and one of us build the hex for that...
I know nothing about the PICKit1, can you use ICSP with it ?
OK I just looked at AN258 http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en012103
and it clearly shows PICKit1 using ICSP so he can go OFF BOARD with some jumper wires and program chips.
So is it that the PICKit1 firmware does not support bigger chips ?
This will work, until he get's serious. http://cgi.ebay.com/Microchip-PIC-JDM-Programmer-Free-12F675-No-1_W0QQitemZ130348203905QQcmdZViewItemQQptZLH_Defau ltDomain_0?hash=item1e595bbf81
Probably Won't do 18Fs but will do nearly all 16F & 12F series.

mackrackit
- 19th February 2010, 06:50
An adapter can be made for the socket, but the PICs supported are limited.
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010053

LEDave
- 19th February 2010, 17:38
Feeling rather pleased with myself this afternoon.

I looked at the diode array diagram in my PICkit1 and the program mackrackit had written for me to run D0 - D1 - D2 in sequence and thought I'd like to add D3. So after much head scratching (believe me) I can up with this:

ANSEL = %00000000
CMCON0 = %00000111

START:
'D0 HIGH
TRISIO = %11001111
GPIO = %00010000
PAUSE 500
'D1 HIGH
TRISIO = %11001111
GPIO = %00100000
PAUSE 500
'D2 HIGH
TRISIO = %11101011
GPIO = %00010000
PAUSE 500
'D3 HIGH
TRISIO = %11101011
GPIO = %00000100
PAUSE 500
GOTO START

The D3 bits mine:-) So I compiled it, no errors and whoosh: D0-D1-D2-D3 chugging along in a nice line and not a hint of burning smoke anywhere.

I know it's only a small step, but still really pleased. I'm going to read and try to fully understand the GPIO / TRISIO port register relationship over the weekend. Still much to learn but Rome wasn't built and all that....!

Dave

mackrackit
- 19th February 2010, 20:41
COOL!!!!
Progress...

About future programmers.. I would recommend the PicKit2 over anything else. It is a bit more expensive but worth it.
http://www.microchipdirect.com/productsearch.aspx?Keywords=PG164120

In my shop I have a PicKit1, PicStart+, and two PicKit2's. Guess the ones that get used the most..

I will sometimes build a JDM type circuit into a project if it is something the customer may have to update and they work OK and I have a board I make for kids to learn the basics on so they do have their place but...

Just my opinion... not trying to start a programmer war.

LEDave
- 19th February 2010, 22:24
I do like the PICKit with it's USB connection, early days but I think I'll stick with them for sure.

I've a lot of basics to learn in the meantime, any thoughts on how I should structure my learning?

I'd like to learn how to program the 12F683 to output a binary pattern (xxxx-bin) when a button gets pressed.

Another thing I'm wondering, does the basic principles of one PIC transfer to others (I'm guessing yes, why re-invent the wheel every time) so learning the 683 chip would be a good place to start for a knowledge base.

Question after question from me at the moment, I do apologize for that.

Interesting stuff these PIC's, I can't wait to get a reasonable working knowledge.

Dave

LEDave
- 19th February 2010, 22:49
Just a thought here.

Is there a book on programming in PBP basic?

Archangel
- 19th February 2010, 23:41
Feeling rather pleased with myself this afternoon.
As well you should be. This is a rewarding hobby. I think you will find much pleasure in it.



Just a thought here.

Is there a book on programming in PBP basic?

There are lot's of them, the thing is, before you buy, hang out here and learn what they do not tell you first, then get the books and you can make what they teach work. What they do not really tell you, is how to make configs work, this is only important if you want your code to work :D some books do not bother to explain Port and TrIS register settings, and spend 12 chapters explaining how to install MPASM. Others are so old, they are explaining how to use 16C series, most use 16F84. There is a reason for that. 16F84 has nearly no bells and whistles, and consequently no special function registers like ANSEL, CMCON, CMCON1,CMCON0 ADCON PCON . . . . Easier for the beginner, but at a cost, old chips cost more. John Iovine has a few PBP books and his are not too bad, above exclusions aside. Chuck Hellebuyck, I think has a couple, and you MAY be able to order with a PICKIT2 with demo board, though I am not positive about that. Correct me if wrong Chuck. There ARE others, but I would probably try those first. Still waiting for BRUCE's book, I betcha it will be great, and I am sure HE won't forget to explain the configs either.

Archangel
- 19th February 2010, 23:45
COOL!!!!
Progress...

About future programmers.. I would recommend the PicKit2 over anything else. It is a bit more expensive but worth it.
http://www.microchipdirect.com/productsearch.aspx?Keywords=PG164120

In my shop I have a PicKit1, PicStart+, and two PicKit2's. Guess the ones that get used the most..

I will sometimes build a JDM type circuit into a project if it is something the customer may have to update and they work OK and I have a board I make for kids to learn the basics on so they do have their place but...

Just my opinion... not trying to start a programmer war.
Ha, no war, I paid 8 bucks for my first JDM, that's why I bought it. It works, but I prefer MY PICKit2 over it. I think as cheap as they are it is worthwhile to have as a backup.

mackrackit
- 20th February 2010, 06:54
Another thing I'm wondering, does the basic principles of one PIC transfer to others (I'm guessing yes, why re-invent the wheel every time) so learning the 683 chip would be a good place to start for a knowledge base.
Yes, pretty much all are the same. Some of the registers are different but once you learn one or two chips... The 683 is fine for learning. When you get a full copy of PBP give the 16F676 a try for the next one.


Question after question from me at the moment, I do apologize for that.
Ask all of the questions you want. That is what the forum is for. Several come here looking for a copy/paste solution. You are not so ask away.


I've a lot of basics to learn in the meantime, any thoughts on how I should structure my learning?
Do not buy any books!!!! Exception would be the one Bruce is working on.
I will try to be nice, but the bozos currently with PBP books are just robbing newbees. They basically copy the PBP manual and some of the examples from Melabs web site. If one of the authors started posting here like Bruce does then I would have a different out look. For now I will say they are trying to make a fast buck.
The only place to get real info on PBP is from this forum and the folks like Darrel, Bruce and Melanie.

You are on the right track.
Start with "blinky" then move on to push buttons. Basic I/Os.
The PICkit1 is forcing you to learn about TRIS so that is covered. Try making the LEDs on that board do what you want with HIGH/LOW commands...

Next would be LOOPS. FOR/NEXT WHILE/WEND, flow control.

Then work on some simple serial stuff, have to have a way to "talk" to your chip.
Start with SERIN2/SEROUT2. Send data to a PC to display on a terminal. The send data to the chip that would replace a button.

Then start playing with on-board ADC and other hardware things.

LEDave
- 20th February 2010, 12:31
Thanks for that you two, I really appreciated your help and offers of future help.

I guess part of my problem is I'm not strong in any one area. The last time I did any programming in Basic was using my ZX Spectrum (that dates me lol) and my electronic knowledge is pretty basic and patchy. That said I'm very interested and willing to spend time trying to learn.

It'll be interesting to see how I get on, hey in a few Months a Year or two people could be saying "If LEDave can do it there's hope for anyone".

So: More studying of TRISIO / GPIO followed by HIGH / LOW then a LOOP then a push button..........!

Dave

LEDave
- 21st February 2010, 19:34
This has taken me ages, it's a modification to Joe's program he posted earlier in the thread (with some of mackrackit's mixed in for good measure) plus some of mine.

The thing is this: Is this a valid program in that GPIO.4 goes high & low and lights the LED due to the: THEN GPIO.4 = 1 / LET GPIO.4 = 0 program statements? I'm not sure if I've made another little bit of progress here, or just lucked in (the right LED does blink).

When you guys have a minute could you check it out please.

GPIO = %00000000 ' set all outputs low
TRISIO = %11001111 'Set GPIO.4&5 to input
CMCON0 = %00000111 'Disable analog comparators
ANSEL = %00000000 'disable analog select so ports work as digital i/o

main:
PAUSE 3000
IF GPIO.5 = 0 THEN GPIO.4 = 1 'turn it on by making pin 4 high +5V
pause 500
LET GPIO.4 = 0 'turn it off: Pin 4 goes low 0V
goto main ' Loop

end

Cheers:Dave

Archangel
- 22nd February 2010, 05:00
Good Morning Dave,
I machine a LOT of magnesium, which is done dry. Here is the code for
a little device to keep the chips away. It is presently ported to your
PICKit1 (Thanks BRUCE !). This will flash D7 on your board according to how you adjust the little Pot .


@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
' * * * * * PIC12F675 * * * * * PICKit 1 Demo board
PCON = %00000011 ' BOD off, No POR flag set
DEFINE NO_CLRWDT 1
DEFINE ADC_CLOCK 1

OSCCAL = %1111100 ' SET OSC TO MAXIMUM SET OSC TO 4 MHZ INTERNAL
CMCON = 7 ' Disable Analog Comparators
ANSEL = 1 ' Disable A/D module, all digital except AN 0
WPU.4 = 0 ' Disable weak pull up on GPIO.4

B0 VAR word ' Byte holds 0 - 255 Word 0 - 65535


OPTION_REG = %11111111 ' Dis/Enable internal pull-ups Bit 7
' Bits 0-2 prescaler
' Bit 3 prescaler assignment 1 = WDT 0 = TMR0
' Bit 4 TMR0 source edge select bit
' 1 trigger on High to Low
' 0 trigger on Low to High
' Bit 5 TOCS TMR0 clock source select
' 1 = transition on GP2
' 0 = internal clock (CLKOUT)
' Bit 6 INTEDG Interrupt Edge Select
' 1 = Interrupt on rising edge GP2
' 0 = Interrupt on falling edge GP2
' Bit 7 Pullup resistor enable bit
' 1 = disabled 0 = enabled by individual port
' latch values.





Main:
Adcin 0,B0
b0 = (b0 * 10)
gpio.2 = 0
TRISIO = %11111001
GPIO.1 = 1
pause B0
GPIO.1 = 0
pause 500

GOTO Main

END

you should be able to compile with the demo version, you have. Configs set for MPASM Assembler.

Archangel
- 22nd February 2010, 05:12
Here is some code to do most of what your pic was originally programmed to do.
I think it will run on the demo, if it is too long then just comment out the last couple of statements in the main.


@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
'DEFINE OSC 4
'DEFINE ADC_CLOCK 1
'OSCCAL=%10000000
'GPIO = 0 ' set all outputs low
TRISIO = %00000001 'Set GPIO.0 to input
cmcon = 7 'Disable analog comparators
ANSEL = 1
'PCON = %00000011 ' Bit 0 BOD 0=on 1=off bit 1 POR 0=on 1=off
ADCON0 =%00000011 ' SET CHANNEL 0 RT JUSTIFIED VREF - VDD
' BIT 7 1 LT JUSTIFY 0 RT JUSTIFY
' BIT 6 1 = VREF 0 = VDD
' BIT 5:4 UNIMPLEMENTED
' BIT 3:2 00 CH 0
' 01 CH 1
' 10 CH 2
' 11 CH 3


DELAY VAR WORD

main:
ADCIN 0,DELAY
DELAY = (DELAY * 4)
TRISIO = %11111001
GPIO = %00000010 'LED 7 ON
PAUSE DELAY
GPIO = %00000100 'LED 6 ON
PAUSE DELAY
TRISIO = %11011011
GPIO = %00000100 'LED 5 ON
PAUSE DELAY
GPIO = %00100000 'LED4 ON
PAUSE DELAY
ADCIN 0,DELAY ' RECHECK A/D AND RECALIBRATE
DELAY = (DELAY * 4)
TRISIO = %11101011
GPIO = %00000100 ' led 3 ON
PAUSE DELAY
GPIO = %00010000 'led 2 ON
PAUSE DELAY
TRISIO = %11001111
GPIO = %00100000
PAUSE DELAY
GPIO = %00010000
'PAUSE DELAY
goto main

After you play with these you may be ready to order PBP. Then you can UnComment the rest of this code.

LEDave
- 22nd February 2010, 17:06
Hi Joe

Thanks for the two programs, I'm having problems running them though. They won't won't compile in Micro code studio without errors. I'm guessing the first program won't because it's for the 12F675 which isn't supported. I did try and copy-paste them into MPL-Labs-IDE I'm so hopeless I couldn't even do that!

Could you post up the HEX code files please and I'll see if they run.

I must say though that parts of the programs are beyond me at present (although I do recognise a lot of the terms contained within) I'm still learning to walk as it were. I will get there though. I might not be the brightest diamond in the tiara but I am persistent....lol.

Dave

LEDave
- 22nd February 2010, 22:02
Here's tonight efforts. Two programs that do exactly the same thing only differently, namely flash LED 'D0' on the PICkit1. One prog using: TRISIO/GPIO/HIGH/LOW the other using: OUTPUT statements.


If anyone would care to comment on the accuracy of what I'm doing / saying it would be much appreciated: Dave


PROG 1:

ANSEL = %00000000
CMCON0 = %00000111
TRISIO = %11001111
GPIO = %11011111

Start
main
PAUSE 500 ' wait 500mili_secs
HIGH GPIO.4 ' 'D0' HIGH turns LED-ON +5 volts
PAUSE 500 ' wait 500mili_secs
LOW GPIO.4 ' 'DO' LOW turns LED-OFF zero volts
goto MAIN ' start all over again

---------------------------------------------------------------------
PROG 2:

ANSEL = %00000000
CMCON0 = %00000111
OUTPUT GPIO.4 ' Makes GPIO an output
LOW GPIO.5 ' Makes GPIO.5 zero volts

Start
main
PAUSE 500 ' wait 500mili_secs
HIGH GPIO.4 ' 'D0' HIGH turns LED-ON +5 volts
PAUSE 500 ' wait 500mili_secs
LOW GPIO.4 ' 'DO' LOW turns LED-OFF
goto MAIN ' start all over again

mackrackit
- 22nd February 2010, 22:26
That is the best way to learn, try things.

Let us know the results :)

LEDave
- 22nd February 2010, 22:35
Hi mackrackit.

Both the programs work and do the same thing. Thing is are these programs accurate? Because I don't fully understand what I'm doing (yet) I'm assuming they are because they work. I just have that nagging feeling I've lucked in again.

Dave

mackrackit
- 22nd February 2010, 23:06
I just have that nagging feeling I've lucked in again.
I know what you mean...
I feel the same way when my code works :D

If they work they are "accurate". There is always more than one way to do anything. With MCUs we try to find the way that uses the least amount of code space, but that will come.

The test board you have is a little different than what most people use(I do not hear of many here using the PICkit1) so you have to do things just a bit differently. Every LED you want to turn on you have to deal with two pins. One HIGH and one LOW. To turn on some of the LEDs you will also have to make a third pin an INPUT.

So now try to do the sequence LEDs 1-3 using HIGH/LOW. You will see what I mean.

Another thing about the HIGH/LOW commands. They over ride the TRIS settings.

LEDave
- 22nd February 2010, 23:45
"The test board you have is a little different than what most people use (I do not hear of many here using the PICkit1)"

What do most on here use?

"So now try to do the sequence LEDs 1-3 using HIGH/LOW. You will see what I mean."

Tomorrow's challenge....!

"Every LED you want to turn on you have to deal with two pins. One HIGH and one LOW. To turn on some of the LEDs you will also have to make a third pin an INPUT."

It is strange (to me anyway) how Microchip have configured the LED's on the PICkit1.

I'm off to bed now, see you tomorrow.

Dave

Byte_Butcher
- 23rd February 2010, 00:21
"The test board you have is a little different than what most people use (I do not hear of many here using the PICkit1)"

What do most on here use?

I use the PICkit2, and my first learning platforms were Microchips "low pin count demo board" (16F690) and "44-pin demo board" (16F887). The 44-pin demo kit also came with 2 extra bare boards for experimenting with other 44 pin chips. (If you don't mind soldering TQFP parts)

steve

Archangel
- 23rd February 2010, 02:10
Good Morning Dave,
I machine a LOT of magnesium, which is done dry. Here is the code for
a little device to keep the chips away. It is presently ported to your
PICKit1 (Thanks BRUCE !). This will flash D7 on your board according to how you adjust the little Pot .


@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
' * * * * * PIC12F675 * * * * * PICKit 1 Demo board
PCON = %00000011 ' BOD off, No POR flag set
DEFINE NO_CLRWDT 1
DEFINE ADC_CLOCK 1

OSCCAL = %1111100 ' SET OSC TO MAXIMUM SET OSC TO 4 MHZ INTERNAL
CMCON = 7 ' Disable Analog Comparators
ANSEL = 1 ' Disable A/D module, all digital except AN 0
WPU.4 = 0 ' Disable weak pull up on GPIO.4

B0 VAR word ' Byte holds 0 - 255 Word 0 - 65535


OPTION_REG = %11111111 ' Dis/Enable internal pull-ups Bit 7
' Bits 0-2 prescaler
' Bit 3 prescaler assignment 1 = WDT 0 = TMR0
' Bit 4 TMR0 source edge select bit
' 1 trigger on High to Low
' 0 trigger on Low to High
' Bit 5 TOCS TMR0 clock source select
' 1 = transition on GP2
' 0 = internal clock (CLKOUT)
' Bit 6 INTEDG Interrupt Edge Select
' 1 = Interrupt on rising edge GP2
' 0 = Interrupt on falling edge GP2
' Bit 7 Pullup resistor enable bit
' 1 = disabled 0 = enabled by individual port
' latch values.





Main:
Adcin 0,B0
b0 = (b0 * 10)
gpio.2 = 0
TRISIO = %11111001
GPIO.1 = 1
pause B0
GPIO.1 = 0
pause 500

GOTO Main

END

you should be able to compile with the demo version, you have. Configs set for MPASM Assembler.
Here is the hex:

:020000040000FA
:1000000052280F39A0000310A00DA00D1F08E039E1
:10001000200401389F000030A100323023209F14BB
:100020009F181028A1011E084D28A301A200FF302F
:10003000A207031CA307031C4D280330A100DF30D7
:1000400023201728A101E83EA000A109FC30031CD1
:100050002C28A00703182928A0070000A10F292891
:1000600020183228A01C362800003628080010303E
:10007000A800A101A001A70CA60C031C452822087A
:10008000A00723080318230FA107A10CA00CA50C9F
:10009000A40CA80B3B2824084D28831303138312B8
:1000A00000000800831603308E007C30900083121D
:1000B00007309900831601309F001512FF30810030
:1000C000831200300120B8002108B9003808A600CA
:1000D0003908A7000A30A200A3013720B80025087C
:1000E000B90005118316F93085008312851439088B
:1000F000A3003808162085100130A300F430162024
:0601000061286300812864
:02400E00D43F9D
:00000001FF

Archangel
- 23rd February 2010, 02:13
Here is some code to do most of what your pic was originally programmed to do.
I think it will run on the demo, if it is too long then just comment out the last couple of statements in the main.


@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
'DEFINE OSC 4
'DEFINE ADC_CLOCK 1
'OSCCAL=%10000000
'GPIO = 0 ' set all outputs low
TRISIO = %00000001 'Set GPIO.0 to input
cmcon = 7 'Disable analog comparators
ANSEL = 1
'PCON = %00000011 ' Bit 0 BOD 0=on 1=off bit 1 POR 0=on 1=off
ADCON0 =%00000011 ' SET CHANNEL 0 RT JUSTIFIED VREF - VDD
' BIT 7 1 LT JUSTIFY 0 RT JUSTIFY
' BIT 6 1 = VREF 0 = VDD
' BIT 5:4 UNIMPLEMENTED
' BIT 3:2 00 CH 0
' 01 CH 1
' 10 CH 2
' 11 CH 3


DELAY VAR WORD

main:
ADCIN 0,DELAY
DELAY = (DELAY * 4)
TRISIO = %11111001
GPIO = %00000010 'LED 7 ON
PAUSE DELAY
GPIO = %00000100 'LED 6 ON
PAUSE DELAY
TRISIO = %11011011
GPIO = %00000100 'LED 5 ON
PAUSE DELAY
GPIO = %00100000 'LED4 ON
PAUSE DELAY
ADCIN 0,DELAY ' RECHECK A/D AND RECALIBRATE
DELAY = (DELAY * 4)
TRISIO = %11101011
GPIO = %00000100 ' led 3 ON
PAUSE DELAY
GPIO = %00010000 'led 2 ON
PAUSE DELAY
TRISIO = %11001111
GPIO = %00100000
PAUSE DELAY
GPIO = %00010000
'PAUSE DELAY
goto main

After you play with these you may be ready to order PBP. Then you can UnComment the rest of this code.
Here is this hex:


:020000040000FA
:1000000052280F39A0000310A00DA00D1F08E039E1
:10001000200401389F000030A100323023209F14BB
:100020009F181028A1011E084D28A301A200FF302F
:10003000A207031CA307031C4D280330A100DF30D7
:1000400023201728A101E83EA000A109FC30031CD1
:100050002C28A00703182928A0076400A10F29282D
:1000600020183228A01C362800003628080010303E
:10007000A800A101A001A70CA60C031C452822087A
:10008000A00723080318230FA107A10CA00CA50C9F
:10009000A40CA80B3B2824084D28831303138312B8
:1000A0006400080083168030900083128501831657
:1000B00001308500831207309900831601309F00BC
:1000C00003308E00831203309F0000300120B800FF
:1000D0002108B9003808A6003908A7000430A2009A
:1000E000A3013720B8002508B9008316F930850030
:1000F0008312023085003908A30038081620043026
:1001000085003908A300380816208316DB308500E7
:100110008312043085003908A300380816202030E7
:1001200085003908A3003808162000300120B800E7
:100130002108B9003808A6003908A7000430A20039
:10014000A3013720B8002508B9008316EB308500DD
:100150008312043085003908A300380816201030B7
:1001600085003908A300380816208316CF30850093
:100170008312203085003908A3003808162010307B
:1001800085003908A3003808162065286300C628B2
:02400E00DC3F95
:00000001FF

I uncommented that which was commented.

mackrackit
- 23rd February 2010, 04:24
It is strange (to me anyway) how Microchip have configured the LED's on the PICkit1.
In the long run you will be happy that you are learning on the PICkit1. Many do not learn about TRIS until something does not work. Another nice thing about the LEDs this way is that 8 LEDs can be controlled with 4 pins from the PIC.

LEDave
- 23rd February 2010, 15:50
Hi Joe

Very impressed with the two programs you posted, thanks for those and very clever. The coding in parts is way beyond me at present but the effect on my PIC1 board are great and shows what can be done.

I'll try and do the sequence mackrackit suggested today (time permitting).

"So now try to do the sequence LEDs 1-3 using HIGH/LOW."

It sounds straight forward enough (ish) but I've just got a feeling.......!

Dave

LEDave
- 23rd February 2010, 18:02
Hi mackrackit. I've been working like a Beaver this PM and have come up with this program to your: "So now try to do the sequence LEDs 1-3 using HIGH/LOW." exercise. If you get a minute could check my program comments for accuracy please, because I'm making assumptions the conclusions I'm drawing are accurate and they may well not be. The program does work though:Many thanks: Dave


ANSEL = %00000000
CMCON0 = %00000111

Sart
MAIN
OUTPUT GPIO.5 ' Makes GPIO.5 an output
LOW GPIO.4 ' Makes GPIO.4 zero volts
HIGH GPIO.5 ' D1 HIGH turns LED-ON +5 volts
PAUSE 500 ' wait 500mili_secs
LOW GPIO.5 ' D1 LOW turns LED-OFF
PAUSE 500 ' wait 500mili_secs

INPUT GPIO.5 ' Stops cross-feed to other Diodes
OUTPUT GPIO.4 ' Makes GPIO.4 an output
LOW GPIO.2 ' Makes GPIO.2 zero volts
HIGH GPIO.4 ' D2 HIGH turns LED-ON +5 volts
PAUSE 500 ' wait 500mili_secs
LOW GPIO.4 ' D2 LOW turns LED-OFF
INPUT GPIO.2 ' Stops cross-feed to other Diodes
PAUSE 500 ' wait 500mili_secs

OUTPUT GPIO.2 ' Makes GPIO.2 an output
LOW GPIO.4 ' Makes GPIO.4 zero volts
HIGH GPIO.2 ' D3 HIGH turns LED-ON +5 volts
PAUSE 500 ' wait 500mili_secs
LOW GPIO.2 ' D3 LOW turns LED-OFF
INPUT GPIO.2 ' Stops cross-feed to other Diodes
PAUSE 500 ' wait 500mili_secs

goto MAIN ' start all over again

LEDave
- 23rd February 2010, 20:37
So here's a question (or yet another question to be more accurate here).

Is it possible to use multiple OUTPUT & HIGH statements on one line for example:

OUTPUT GPIO.0 GPIO.1 GPIO.2

As opposed to:

OUTPUT GPIO.0
OUTPUT GPIO.1
OUTPUT GPIO.2

Followed by:

HIGH GPIO.0 GPIO.1 GPIO.2

As opposed to:

HIGH GPIO.0
HIGH GPIO.1
HIGH GPIO.2

David

HenrikOlsson
- 23rd February 2010, 21:18
Yes and no, you can use our old friend Skimask's favourite character - the colon - and do

High GPIO.0 : High GPIO.1 : High GPIO.2
But it doesn't make any difference as to how it actually works, it will generate exactly the same code when compiled as having each command on a separate line.

What you usually do is write directly to the register, or port in this case, like this:

TRISIO = %11100000 'Set lower five bits to outputs
GPIO = %00000111 'Set the lower three bits.
PAUSE 1000
GPIO = %00010101 'Set some other bits.


The HIGH and LOW commands automatically sets the pin to an output (by also writing to the TRIS register "behind the scenes" (basically what the OUTPUT command does)) which is handy sometimes but completely unneccessary to do EVERY time you change the state of the pin. By using the more "direct" aproach you'll save code space and execution time.

LEDave
- 23rd February 2010, 21:51
Thanks for that Henrik.

For my first project I'd like to use a 12F683 generate a four bit word to load a
BCD / Seven Segment Display driver. Would the code below work do you think?


TRISIO = %11110000 'Set lower fOUR bits to outputs: 4 bits all you need to create bcd OUTPUT.

GPIO = %00000000 'Set all bits low: Would drive a BCD / 7 SEG to OUTPUT '0'

PAUSE 1000

GPIO = %00000001 'Set BIT.0 High: Would drive a BCD / 7 SEG to OUTPUT '1'

pause 1000

GPIO = %00000010 'Set BIT.1 High: Would drive a BCD / 7 SEG to OUTPUT '2'

pause 1000

GPIO = %00000011 'Set BIT.2 & BIT.1 High: Would drive a BCD / 7 SEG to OUTPUT '3'

PAUSE 1000

GPIO = %00000100 'SET BIT.2 HIGH: Would drive a BCD / 7 SEG to OUTPUT '4'

etc,etc........

David

mackrackit
- 24th February 2010, 00:17
http://www.electronics-tutorials.ws/combination/comb_6.html

Archangel
- 24th February 2010, 03:36
Hi Joe

Very impressed with the two programs you posted, thanks for those and very clever. The coding in parts is way beyond me at present but the effect on my PIC1 board are great and shows what can be done.

I'll try and do the sequence mackrackit suggested today (time permitting).

"So now try to do the sequence LEDs 1-3 using HIGH/LOW."

It sounds straight forward enough (ish) but I've just got a feeling.......!

Dave

Hi Dave,
Really simple and not beyond where you are right now.
Tris is short for TriState. 3 states: in / output H / output L
Port determines if the tristate is high or low.
"Most" of the 12F , 8 pin devices use GPIO as Port name, it stands for General Purpose Input output. the TRIS is TRISIO. Here is the really simple part the letter" I " (for input) looks like a number 1 and the letter" O" (for Output) looks like a 0. so you see GPIO%00000011 means the 2 lowest bits are "set" as inputs. All the other bits are " cleared ". and are Outputs.
The Port register is done in a similar way. 1 is logic HIGH and 0 is logic LOW. Logic high is +5v and Logic Low is 0 volts.
I get that you might know this, but the next newbie may not. No offense intended.
Consider this statement:
TRISIO = %11111001
GPIO = %00000010 'LED 7 ON

TRISIO = %11111001 makes ports 1:2 into outputs
GPIO = %00000010 makes Port 1 Logic high and port 2 logic low.
Pay attention to the terminology "set" & "cleared" as you will see them in the data sheets.
Generally speaking you will set the Port first then the tris, if you have a circuit like this where you have a bidirectional load, you might consider making all tris as inputs, set your port and then set the tris to enable the outputs. Your loads might be something very different than LEDs.

HenrikOlsson
- 24th February 2010, 06:40
Dave,
Sure, that should work. You can also use the value stored in a variable when writing to the register, like this:

i VAR BYTE 'Declare a variable named 'i' as a BYTE
i = 8
GPIO = i 'Will set GPIO to %00001000


This in turn means that to make the display count you can do this:

i VAR BYTE 'Declare a variable named 'i' as a BYTE
MAIN:
FOR i = 0 to 9 'Count up, from 0 to 9
GPIO = i
Pause 500
Next

FOR i = 9 to 0 STEP -1 'Count Down, from 9 to 0
GPIO = 0
Pause 500
Next

Goto Main 'Do it again

May I kindly suggest that you also read thru the PBP manual a lot of what we've gone thru here is available in it, sometimes in a bit more condensed form but if you read thru it you'll get a better picture of "what's available", then we can work on the details and specifics together.

LEDave
- 24th February 2010, 13:11
Once again many thanks for all the INPUT.As always very much appreciated.

mackrackit, I've book marked that link, very useful.

Joe, if I could get my PIC's to dance like that I'll know I've arrived. I'm still adding the building blocks at present, that said there's been a big improvement in what I know and can do in just a week, great stuff.

Henrik, so are we're saying that the program is counting up from 0-9 in bytes? Does it load and output the values $00000000 (LOOP1) $00000001 (LOOP2) ...etc. If that's the case I could directly output to a seven segment display!

So the question is: Is there a PIC for my PICkit1 that has an eight bit wide output GPIO?

Dave

rmteo
- 24th February 2010, 14:59
From here http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010053

PICkit Classic V1.74 supports these mid-range Flash PIC® microcontrollers:
- PIC12F629, 635, 675, 683,
- PIC16F630, 636, 676,

- PIC16F684, 685, 687, 688, 689, 690, 785

- PIC16F913, 914, 916, 917, 946
Any of those in red have at least one 8-bit port. Although, the same page also say this.

The PICkit™ 1 Flash Starter Kit is a low-cost development kit with an easy-to-use interface for programming Microchip’s 8-/14-pin Flash family of microcontrollers.
If that is the case, then you are out of luck as no 8/14-pin devices have a complete 8-bit port.

mackrackit
- 24th February 2010, 15:09
So the question is: Is there a PIC for my PICkit1 that has an eight bit wide output GPIO?

None that I can think of. The 14 pin PICs will have two ports with 6 each.

You migh get creative and shift the bits 4 four places.
Lower four to one port, upper four to the other???

Or...

I think Darrel had a way of re-mapping the pins/ports...

HenrikOlsson
- 24th February 2010, 15:46
Henrik, so are we're saying that the program is counting up from 0-9 in bytes? Does it load and output the values $00000000 (LOOP1) $00000001 (LOOP2) ...etc. If that's the case I could directly output to a seven segment display!
Yes and no, the loop incements the variable i from 0 to 9 (or what ever you want it to) and writes its value to the GPIO-register, the pattern on the GPIO will be the binary representation of the number, ie:

00000000 '0
00000001 '1
00000010 '2
00000011 '3
...
00001000 '8
00001001 '9

This however, can not drive a 7-segment display directly as displaying "1" needs two segments turned on (but only one bit is set on the "count" of 1) and 8 needs all seven segments on but at the "count" of 8 there's again only a single bit set.

However, you can use the LOOKUP command to "translate" the 0-9 count into the "patterns" needed to drive the segments. Lets say you connect the display so that each bit drive the segments as per the attached picture. To display "3" bit 0, 1, 2, 3 and 6 would need to be set, or put another way, you'd need to write %01001111 or 79 to the port. To display a "2" you need to set bits 0, 1, 3, 4 and 6 (%01011011 or 91) and so on.

Now lookup the LOOKUP command in the manual ;-)

Byte_Butcher
- 24th February 2010, 17:07
I think Darrel had a way of re-mapping the pins/ports...

http://www.picbasic.co.uk/forum/showthread.php?t=7038&highlight=lcd_anypin&page=2



steve

LEDave
- 24th February 2010, 17:10
HI Henrik

I've looked lookup in the manual (I found a copy on the net, then realised there's one in the demo-program...doh).

So are we saying that to make the seven segment display show a '3' our loop count would be:00000011 '3' but that would LOOKUP a stored value of :%01001111 and display that?

So we'd have to 'load in' somewhere a table of values:

%01001111 3 b3
%01011011 2 b2
%00000110 1 b1
%00111111 0 b0

So:

FOR B0 = 0 TO 3 ' Count from 0 to 3
LOOKUP B0,[%00111111],B1 ' Get character number B0 from string to variable B1
SEROUT 0,N2400,[B1] ' Send character in B1 to Pin0 serially
NEXT B0 ' Do next character

*Shouldn't SEROUT be something like PAROUT (parallel out) namely display all seven bits on seven pins at once.*

Dave (struggling but trying).

mackrackit
- 24th February 2010, 17:35
*Shouldn't SEROUT be something like PAROUT (parallel out) namely display all seven bits on seven pins at once.*

No,
GPIO = B1
will set the bits to whatever B1 is.

SERIOT is for RS232 type stuff.

Another lesson :)

LEDave
- 24th February 2010, 17:36
Hi mackrackit

"You might get creative and shift the bits 4 four places.
Lower four to one port, upper four to the other???"

How difficult is getting creative for a newbie like me?

My PICkit1 came with a PIC16F684 included.

Dave

rmteo
- 24th February 2010, 17:59
The '<<' and '>>' operators shift a value left or right, respectively, 0 to 15 times. The newly shifted-in bits are set to 0.

B0 = B0 << 3 ‘ Shifts B0 left 3 places, (same as multiply by 8)
W1 = W0 >> 1 ‘ Shifts W0 right 1 position and places result in W1 (same as divide by 2)

HenrikOlsson
- 24th February 2010, 18:03
Hi,
SEROUT is for serial RS232 communication. It's just used as an example in the LOOKUP section of the manual.

i VAR BYTE
Main:
For i = 0 to 9
LOOKUP i, [0, 6, 91, 79, 102, 109, 125, 7, 127, 103], GPIO
Pause 500
Next
Goto Main
See, when i is 0 the first value in the lookup table (0) will get written to GPIO, all bits will be reset, when i is 6 the seventh value (125) in the lookup table will get written to GPIO. 125 is the same as %01111101 which means all segments except the one driven by Bit1 will be on - the display will show "6".

Now, this would work on a PIC with seven or more consecutive GPIO pins, which apparently doesn't exist.... Getting a PIC with a "full" PortB and using that instead of GPIO would do it. It's still possible to do on the '684 (which has 6 bits on PortA and 6 bits on PortB, no GPIO) but then maby the Lookup aproach isn't the most suitable.

There are many many ways to skin the cat, sit down and play a bit with what you have, if you already have the BCD-Seven segment decoder go ahead and use that and play around.

/Henrik.

mackrackit
- 24th February 2010, 18:07
In the Math Operators section of the manual take a look at SHIFT and the Btiwise Operators.

The idea is..
From Henrik

To display a "2" you need to set bits 0, 1, 3, 4 and 6 (%01011011 or 91)
You will have to connect the display so that part is on one port and part on another. half and half...
Take the lower 4 bits in the case of #2 (1011) and send them to the display with Port1.
Take the upper 4 bits (0101) and send that to the display with Port2.

Think of Port1 as being 0-3
Port2 as 4-7

Presto... a whole Port...0-7

LEDave
- 24th February 2010, 22:49
Well plenty to think about today. Maybe a little consolidation from me, drum those basics into my mind (I still have plenty to learn here).

I see what you're saying regards splitting port1 & port1 to drive the display.

Absolutely fascinating stuff though, I think I'm hooked and I've only managed to flash a few LED's.

Again many thanks to you all.

Dave

LEDave
- 25th February 2010, 16:26
Hi everyone. I've been working on a program below which is a modification of Henrik's look up table program. I know if you had a PIC with an eight bit wide output you could store the output words in the lookup table and then drive a seven segment display directly as Henrik explained.

So I thought I'd try and load a lookup table to blink an LED (D0) 3 times using a for-next-loop (I've never used a for-next-loop before). It works except after three cycles it doesn't stop. I read up that after the loop has finished it then moves on down to the next instruction, so I've added STOP / END. IF i = 4 then STOP. None of these work and when any of these lines are added the program only cycles once.

The only thing I can think of is that the 12F683 doesn't support LOOKUP tables.

Any ideas please? Dave

ANSEL = %00000000 'disable analog select so ports work as digital i/o
CMCON0 = %00000111 'Disable analog comparators
TRISIO = %11001111 'Set GPIO.4&5 to input
GPIO = %00000000 ' set all outputs low

i VAR BYTE

START
Main:
pause 500 'pause 500 mili-secs
For i = 1 to 3 ' loop count variable (value i) also number of times to loop.
LOOKUP i, [ 223, 223, 223] ,GPIO '223 = %11011111 D0 switches on (GPIO.4)
Pause 500 'pause 500 mili-secs
LOW GPIO.4 ' DO switches off
Next i ' loop again. ONE is added to count i and prog jumps to FOR

Acetronics2
- 25th February 2010, 16:30
Hi,

I read "somewhere" a program might end by the " END " directive, or loop to a known label in the program...

Alain

rmteo
- 25th February 2010, 16:52
Dave, use <code> tags and format your code - makes it easier to read.

ANSEL = %00000000 'disable analog select so ports work as digital i/o
CMCON0 = %00000111 'Disable analog comparators
TRISIO = %11001111 'Set GPIO.4&5 to input
GPIO = %00000000 ' set all outputs low

i VAR BYTE

START
Main:
pause 500 'pause 500 mili-secs
For i = 1 to 3 ' loop count variable (value i) also number of times to loop.
LOOKUP i, [ 223, 223, 223] ,GPIO '223 = %11011111 D0 switches on (GPIO.4)
Pause 500 'pause 500 mili-secs
LOW GPIO.4 ' DO switches off
Next i ' loop again. ONE is added to count i and prog jumps to FOR

HenrikOlsson
- 25th February 2010, 17:03
Hi Dave,
Two things.... First as you figured out and as Alain also pointed out you will need an END after the loop or the PIC will wonder off to never never land eventually starting over (I think). Second, you need another PAUSE in there or you will not see the LED blink. It will get turned on then 500ms later it will get turned off and then on again almost instantly as the loop goes back to the beginning. I guess that's what you were trying with the PAUSE right after Main but remeber that the loop starts over at the FOR statement.

Main:
pause 500 'pause 500 mili-secs
For i = 1 to 3 ' loop count variable (value i) also number of times to loop.
LOOKUP i, [ 223, 223, 223] ,GPIO '223 = %11011111 D0 switches on (GPIO.4)
Pause 500 'pause 500 mili-secs
LOW GPIO.4 ' DO switches off
Pause 500
Next i
END

LEDave
- 25th February 2010, 17:18
Henrik you are a star.....!

So I was pretty close then? I guess we wouldn't want to be flying in an aeroplane with any PIC'S in it I'd programmed just yet though...

Right, I'm off for some for-next-loop practice.

Cheers: Dave

LEDave
- 25th February 2010, 17:28
Testing 1.2.3.

So that's a code tag then, I really didn't know that...doh.

LEDave
- 26th February 2010, 23:11
Evening everyone.

I've been doing a lot of reading of late some beneficial some confusing.

I've decided to try and make a 12F683 turn an LED on when a button is momentarily pressed, then expand this further. I can see lots of possibilities in being able to make outputs do different things on receipt of an input/s.

Is something like this on the right lines?


IF GPIO.x = HIGH 'Button is pressed.

THEN OUTPUT GPIO.x HIGH 'Turns LED on

I've put the driving a seven segment display using a 16F684 and part of two ports to on hold just for the minute.

David

mackrackit
- 26th February 2010, 23:31
Almost...
Take a look at this. From the manual...
http://www.melabs.com/resources/pbpmanual/5_32-5_35.htm

Archangel
- 27th February 2010, 02:34
Evening everyone.

I've been doing a lot of reading of late some beneficial some confusing.

I've decided to try and make a 12F683 turn an LED on when a button is momentarily pressed, then expand this further. I can see lots of possibilities in being able to make outputs do different things on receipt of an input/s.

Is something like this on the right lines?


IF GPIO.x = HIGH 'Button is pressed.

THEN OUTPUT GPIO.x HIGH 'Turns LED on

I've put the driving a seven segment display using a 16F684 and part of two ports to on hold just for the minute.

DavidHi David,
I think I smell what you are cooking, you want to send power to a port and then have it stay powered after you release the switch. I Used to install gun lock timers that were wired that way.
Try This UNTESTED CODE


GPIO = %00000000 ' set all outputs as low
TrisIo = %00000001 'make all outputs except GPIO.0
main:
If GPIO.0 then unlock
goto main
unlock:
Trisio.0 = 0 'changes to output
GPIO.0 = 1 'sets port latch to high logic
pause 30000 ' wait 30seconds
GPIO.0 = 0 :TRISIO.0 = 1 ' Turn it off
goto main

end

Keep in mind there is no setup code appropriate to your PIC

LEDave
- 27th February 2010, 21:56
Hi Joe,everyone. Sorry for the slow reply, it's been one of those days today.
Before I forget I loved the line: "I think I smell what you are cooking" It's had me smiling all day.

Joe, the program you wrote. I was happy with all of it except line four.I see you've made GPIO.0 an input
but the 'THEN' label hasn't been given a HIGH or LOW statement for the pin



If GPIO.0 then unlock


To my mind (please be gentle with me I'm really green at this) it should be something like:



IF GPIO.0 = HIGH THEN UNLOCK ' GPIO.O goes HIGH (button pressed) jump to
label UNLOCK.


ELSE GOTO MAIN ' button not pressed do the loop again
(not sure if I needed the GOTO here).

Or maybe:

IF GPIO.O = LOW THEN MAIN ' button not pressed, do the loop again


Am I on the right lines here?

* Silly but important question here*: I'm confusing myself, can an INPUT be either HIGH or LOW?
I know an OUTPUT can be.

So your program is maybe a timed latching relay circuit or locking solenoid?

As for my program, I was thinking more along the lines that if GPIO.X goes high (a button is pressed +5v on that input pin) that would make an output on GPIO.Y go high. In other words the pressing of a button makes the program jump to some specified section of code making an output.

Then moving this idea on, if the button was pressed twice (within a certain time period say) you could 'jump' to another section of code and make a different output..

I hope you're all having a pleasant evening,

David

mackrackit
- 27th February 2010, 22:12
Now you will want to look at the COUNT command. Might be what you need for the button presses.

LEDave
- 27th February 2010, 22:35
Cheers mackrackit, will do.

Reading the manual for me isn't such a bad idea after all....lol.

Can you help me with my:

* Silly but important question here*: I'm confusing myself, can an INPUT be either HIGH or LOW? I know an OUTPUT can be.

For the record I think it can be active HIGH or Low (but I'm not 100% sure).

Dave

mackrackit
- 27th February 2010, 22:43
When a pin is an INPUT it will read the pin's state. Either HIGH or LOW.
Yes, active H/L.

LEDave
- 27th February 2010, 23:03
Cheers mackrackit.

Another question (I know but I am trying hard) In my PICkit1 there is a button attached, now I'm thinking that it goes onto pin GPIO.3 is that right.

So I could use that button to try out some programs using IF THEN and COUNT.

David

mackrackit
- 27th February 2010, 23:14
I do not have the PicKit1's docs with me, but yes. What ever pin it goes to you can use it that way.
Also, check the data sheet to see it the pin has anything "special" about it. MCLR??

Archangel
- 27th February 2010, 23:20
Hi Joe,everyone. Sorry for the slow reply, it's been one of those days today.
Before I forget I loved the line: "I think I smell what you are cooking" It's had me smiling all day.

Joe, the program you wrote. I was happy with all of it except line four.I see you've made GPIO.0 an input
but the 'THEN' label hasn't been given a HIGH or LOW statement for the pin



If GPIO.0 then unlock


To my mind (please be gentle with me I'm really green at this) it should be something like:



IF GPIO.0 = HIGH THEN UNLOCK ' GPIO.O goes HIGH (button pressed) jump to
label UNLOCK.


ELSE GOTO MAIN ' button not pressed do the loop again
(not sure if I needed the GOTO here).

Or maybe:

IF GPIO.O = LOW THEN MAIN ' button not pressed, do the loop again


Am I on the right lines here?

* Silly but important question here*: I'm confusing myself, can an INPUT be either HIGH or LOW?
I know an OUTPUT can be.

So your program is maybe a timed latching relay circuit or locking solenoid?

As for my program, I was thinking more along the lines that if GPIO.X goes high (a button is pressed +5v on that input pin) that would make an output on GPIO.Y go high. In other words the pressing of a button makes the program jump to some specified section of code making an output.

Then moving this idea on, if the button was pressed twice (within a certain time period say) you could 'jump' to another section of code and make a different output..

I hope you're all having a pleasant evening,

David
I am always gentle :D
It does seem unintuitive doesn't it?
Got it straight from the manual though. If gpio.0 is set? goto unlock. As I understand it, it is a computed goto.
Where zero and one are representing False and true.
IF GPIO.0 is true, goto Label, without requiring endif or else statements.
Melanie posted some things which will interest you using multiple button presses to do different things:
try looking at these, open the links Melanie posted, especially the Olympic timer PDF:
http://www.picbasic.co.uk/forum/showthread.php?t=3423
http://www.picbasic.co.uk/forum/showthread.php?t=632

Oh yeah, that was for a shotgun lock for a police car, officer would turn a keyswitch, and it would stay energized long enough to access his weapon.

LEDave
- 28th February 2010, 00:04
Cheers Joe, very interesting that regards the GPIO.0 computed GOTO. You can see why a newbie like me got a little confused, very handy piece of code though, thanks for the explanation.

I had a look at Melanie's Olympic timer, very impressive. She's one very clever lady.

I've always been an admirer of clever people.

Right, I'm off to my bed to dream of COUNTER - IF-THEN- ELSE IF commands.

Really enjoying this, I hope I'm not driving you all to mad?

David

mackrackit
- 28th February 2010, 00:18
I hope I'm not driving you all to mad?
Already been there. Had a lot of fun too!!!!

HenrikOlsson
- 28th February 2010, 10:30
Hi,
Just in case this isn't clear already....

IF GPIO.0 = HIGH THEN UNLOCK
This is NOT how you you determine if an input is high or low. HIGH and LOW are commands that both sets the pin in question to "output mode" and then drives it either high or low. To check if a pin (or any bit in any register) is set you do either:

If GPIO.1 = 1 THEN GOTO Unlock
Or

If GPIO.1 THEN GOTO Unlock
Or

If GPIO.1 = 0 THEN
GPIO.2 = 1
Goto DoThis
ELSE
Goto Unlock
ENDIF

Right, back to HIGH and LOW... as have been said already the HIGH and LOW commands first sets the pin to "output mode" and then drives the pin high or low. It's nothing wrong with that except that it sets the pin to "output mode" each and every time either command is used. It doesn't matter if the pin already IS in "output mode" - it still writes to the TRIS register - every time and this wastes both time and codes space. It's much better to set the TRIS register manually and only change it if needed and then simply write to the Port or GPIO register directly.

/Henrik.

LEDave
- 28th February 2010, 20:20
Hi Henrik, thanks for that. Being new to programming it's easy to get confused especially when many of the terms are so similar.

I'm a relatively slow learner too which doesn't help I guess. When I finally get it though, it does stick.

You've got to marvel the complexity contained within an eight pin microchip, staggering.

I can't wait to actually build something either.

Have a nice evening.

David

LEDave
- 1st March 2010, 17:58
Hi everyone.

I'm working on my first circuit using the12F683 and I'd like to add a push button as an input. Would I be right in assuming that:

A pull-up resistor say 10k from the +5v line onto the chosen input GPIO.n and a push button connected from GPIO.n to ground should do the job?

This to my mind would leave GPIO.n at +5v until pressed, momentarily dropping to 0v.

David

mackrackit
- 1st March 2010, 18:05
Yup, that will work.

LEDave
- 1st March 2010, 20:27
Cheers mackrackit.

My project, here's the master plan:

I'm going to use the 12F683 to output 4 bit words to drive a BCD to 7-segment decoder driver: Count up from 0-9 in a continual loop IF the push button is pressed THEN GOTO countdown from 9-0 in a continual loop, IF pressed again count down from 5-0 then stop.

This project covers a lot of the ground we've been over in the last week or two and would give me some much needed practical practice.

Another question: Is this program statement viable / do-able to provide input words into the decoder driver?

i VAR WORD
Main:
For i = 0 to 3 etc
LOOKUP i, [0, 1,2,3], GPIO
NEXT i

Sorry but the code tags didn't work tonight.

This would output from the PIC (I hope):

0000 making the driver display '0'
0001 " " '1'
0010 " " '2'
0011 " " '3'
1000 " " '4'

Also from the output side of the PIC ('words') to the input side of the display driver, I'd like to bleed off a little current to the base of four transistors with LED's in the collector leg to visually see the binary count, just for fun.

So what do we think then guys? Have I learned my lessons well, or am I heading for the books...!

David

HenrikOlsson
- 1st March 2010, 21:13
Hi David,


i VAR WORD
Main:
For i = 0 to 3 etc
LOOKUP i, [0, 1,2,3], GPIO
NEXT i
That will work for exercise purposes but in the above case there's really no need for the LOOKUP table. You can just as well write i directly to GPIO, you'd also want a PAUSE in there or it will count really fast, and don't forget to set the TRIS-register to make the pins in question outputs:

Main:
For i = 0 to 3
GPIO = i
Pause 500
NEXT i

0000 making the driver display '0'
0001 " " '1'
0010 " " '2'
0011 " " '3'
1000 " " '4'
Not quite, it will count (and display) 0, 1, 2 and 3 since 3 is what you have in your FOR statement. Actually i will get incremented one more time, to 4, but when that happens the code will jump to after the NEXT statement so the "4" will never make it to GPIO. (If that last thing didn't make sense never mind, the important thing is that it counts from 0 to 3.)

/Henrik.

LEDave
- 1st March 2010, 21:56
Hi Henrik

So to get the program to count down from 9-0 would this do it:

FOR i = 9 to 0 STEP -1
GPIO = i
Pause 500
NEXT i

*I don't know why but I my code tags still aren't working tonight, sorry*

If GPIO = 9 then out would go 1001 to the driver etc...

Yes, without the pause it would have counted to 3 lightning fast I guess.

The LOOKUP table is excellent for outputting stored values though, really glad we touched on it.

HenrikOlsson
- 2nd March 2010, 06:12
Hi,
Yes, that is correct - all of it. Good job!

All BBTags uses square brackets, ie. [...] and [/...] to turn the option ON and OFF respectively. Seems to work from here. There's a box at the bottom of the page showing if BBCode is ON or OFF, make sure it's ON.

/Henrik.

LEDave
- 2nd March 2010, 14:54
Henrik thanks for that.

I'm trying to use the COUNT command that mackrackit put me onto to jump from one loop to the next after a button is pressed. There are three loops (count up to nine when button pressed once - Jump to second loop and count down from nine if button pressed a second time and to a final third loop, count down from five after button is pressed a third time).

Is this code anywhere near to where I need to be? If I'm close but not quite there please let me carry on thinking. If I'm miles off course then a pointer would be much appreciated.


COUNT PIN.n, 10000, VAR B_P_C WORD 'Set GPIO.n as input, define Button Push
Count as VAR WORD B_P_C, with a loop count time of 10 secs.

Let i = B_P_C

IF B_P_C = i GOTO FIRSTLOOP ' Button pressed once
IF B_p_c = i+i GOTO SECONDLOOP ' Button pressed twice
IF B_P_C = i+i+i Goto THIRDLOOP ' Button pressed a third time


My code tags are working today, I didn't touch anything.

David

HenrikOlsson
- 2nd March 2010, 17:29
Hi,
Not quite sure I understand. Are you saying that you want it to execute one of the three loops depending on how many times the butten is pressed within a certain amount of time? Or are you saying that you want to execute the three loops, one after the other, but to wait for a button press between the loops?

In any case, I'm afraid what you have there ain't gonna work....



B_P_C VAR WORD
COUNT GPIO.5, 10000, P_B_C

The above will define a 16 bit variable called B_P_C and then immediatley start counting how many times the button connected to GPIO.5 is pushed. It will keep counting for 10 seconds (10000mS) after which it continues in the program.



Let i = B_P_C

What this does is to say that i should be assigned whatever value B_P_C is. So, after this is exectued i has the same value as B_P_C, provided i is declared the same size as B_P_C - a WORD in this case.



IF B_P_C = i GOTO FIRSTLOOP ' Button pressed once
IF B_p_c = i+i GOTO SECONDLOOP ' Button pressed twice
IF B_P_C = i+i+i Goto THIRDLOOP ' Button pressed a third time
Now, since i is the same as B_P_C (it is because you told it to be) the only condition that can ever be true is the first one.

/Henrik.

PS. Pushbuttons are quite "bouncy", the COUNT command may register several counts even though you only push the button once.

LEDave
- 2nd March 2010, 18:09
Cheers Henrik. The idea is to run the first loop when the button is pressed, if the button is pressed again the counter would count two button pushes and run / goto loop two, if pressed three times would goto loop three, run that loop then stop.

Somehow I need to get the button pushes to increment a counter: One push = run loop1 two pushes = run loop2 three pushes = run loop3....then Stop until button pressed again.

Is there anyway when a button is pressed to just count how many times that's happened then jump to a given loop without the count timer running?

Thanks for your help.

David

HenrikOlsson
- 2nd March 2010, 19:45
Hi,
You say that if the button is pressed one time it should run the first loop - no problem there. But how fast should you need "double-click" or "tripple-click" it in order to run the second or third loop instead of the first one? Or should it run the first loop as soon as it sees a button press and THEN wait for the button the be pressed again?

With the count command but you need to understand that it counts for a certain amount of time during which nothing else will get executed, once that time has passed (10000ms in your case) the code will continue.

So, your idea was on the right track but the implementation had a couple of problems as explained in my previous message. Here's ONE aproach to the single, double, triple-click solution but remember that it might not work in reallity due to the switch bouncing as described before.

Let's say your button pulls the input low when pushed.

B_P_C VAR BYTE

WaitForButton:
If GPIO.5 = 1 THEN GOTO WaitForButton 'Button is not pressed, go back and check again
PAUSE 10 'Wait a little while for the contact bouncing to die

WaitForRelease:
If GPIO = 0 THEN GOTO WaitForRelease 'Loop here until button is relased

COUNT GPIO.5, 1000, B_P_C 'Count number of presses for during one second

IF B_P_C = 0 THEN GOTO FirstLoop 'Remember, we had to press the button once to get here.
If B_P_C = 1 THEN GOTO SecondLoop
If B_P_C = 2 THEN GOTO ThirdLoop 'First one press, then two more as counted by the COUNT-command.

Goto WaitForButton 'Start over if number of presses is more than 3

FirstLoop:
'Your code here
Goto WaitForButton

SecondLoop
'Your code here
Goto WaitForButton

ThirdLoop:
'Your code here
Goto WaitForButton

END
Now, wire it up, compile the code, program the chip and GIVE IT A TRY! ;-) If there's still "basic" stuff that you don't understand then you need to back up and get that sorted first or you will just be creating more problems for yourself. Perhaps we jumped to the LOOKUP and COUNT commands etc a little too soon(?).

/Henrik.

LEDave
- 2nd March 2010, 23:03
Henrik first of all a big thank you for giving your time to help me along (and everyone else too of course).


If there's still "basic" stuff that you don't understand then you need to back up and get that sorted first or you will just be creating more problems for yourself. Perhaps we jumped to the LOOKUP and COUNT commands etc a little too soon(?).

I agree, I do need to back up and go over some of the basics we've covered, like you say running before you can walk with programming will only compound problems later on.

I think I need to write lots of short programs using the basics and do enough of them to really drive it home.

That said, I do understand the basic principle of the COUNT command and it's timing component also with the LOOKUP command.

When you think that trying to use C and assembler I hadn't even managed to switch an LED on! I've come a long since joining this forum and using PB in the last few weeks thanks to you all, there's absolutely no doubt that this in the language to use!

So no, time to build this circuit (I need to make something work) and I'm sure I'll still have plenty of questions for you about the basics still, so you're not of the hook quite yet....;-)

David

HenrikOlsson
- 3rd March 2010, 06:16
So no, time to build this circuit (I need to make something work) and I'm sure I'll still have plenty of questions for you about the basics still, so you're not of the hook quite yet....;-)
No problems, we're all here to help.

LEDave
- 14th March 2010, 17:52
Hi everyone.

I haven't posted for a wee while but have been busy reading and building my first two circuits.

The first is a 12F683 driving four LED's in a binary pattern 0-9 as per the thread (I've also added a nice little Night_Rider effect). I must say, although simple in what I've achieved, when those four LED's run up that binary pattern it was a real thrill, amazing.

The second circuit marrying the binary counting PIC to the BCD decoder driver then seven segment display is about half way built ( I'm quietly confident about this one fingers x'd).

Once again, thanks for all your help on here. I really wouldn't have got this far without it.

I'll be back when the second circuit is completed (early part of next week).

Hope you're all keeping well.

David

LEDave
- 19th March 2010, 20:56
Hi Everyone.

Just to let you know I've got a a working circuit!!!!! Yippee.

It's a 12F683 into a SN74LS47N display driver and a 1" seven segment display counting up to nine.The PIC output also switches four transistors with collector LED's for a binary output count as well.

Simple stuff for you boys I'm sure but I'm chuffed to bits right now.

Not sure where to go or what to do next (any ideas welcome).

Thanks for your help as ever.

Dave

mackrackit
- 19th March 2010, 22:10
COOL!!!! You are moving right along.

Here is an idea. Setup a hardware timmer to change the display once per second.

LEDave
- 19th March 2010, 23:10
Here is an idea. Setup a hardware timmer to change the display once per second.

Hi mackrackit

Are we saying for example to use the trimmer pot on the PICkit1 to alter the display speed ADC? (ADCIN).

I'm seriously considering buying the the full program version by the way (I'm just trying to convince myself I'm clever enough to figure out how to use / make the most of it...lol).

Really enjoying it though (headaches aside ;-))

Dave

mackrackit
- 20th March 2010, 01:21
No, not trimmer... or timmer .... I really need to get a dictionary :o

Timer as in TMRO.

Many times we will at the beginning of a new project to make sure things are setup correctly we will do a simple "blinky" just like we tell the newbees to do. I will a lot of times leave it running as a "heart beat" type of thing. But if you do this using pauses to blink the LED the pauses will maybe get in the way.

So now comes a basic interrupt based on time.
This may or may not be correct for your chip so verify with the data sheet.


INTCON.5 = 1 'ENABLE TMR0
OPTION_REG = %10000101 '16BIT 1:64 PRESCALE
ON INTERRUPT GOTO TLOOP

MAINLOOP:
'MAIN CODE GOES HERE
GOTO MAINLOOP

DISABLE
TLOOP:
INTCON.2=0:TOGGLE PORTD.4
RESUME: ENABLE

LEDave
- 22nd March 2010, 17:11
Hi mackrackit, everyone.

I've been doing a lot of reading trying to figure out what's actually going within your Timer / Interrupt program. So here's my interpretation (he typed as he makes a fool of himself again).....!


INTCON.5 = 1 'ENABLE TMR0

Setting the Interrupt_Control pin.5 = 1 simply enables the Timer0 interrupt.


OPTION_REG = %10000101 '16BIT 1:64 PRESCALE

First of all you set the Global Interrupt Enable bit.7 =1.
Then bits 0 = 1 & bit 2 = 1 sets the PRESCALE value 1/64 of the system clock.
4MHZ or the instruction clock 1MHZ (not 100% sure on that one) This divided down figure is then sent to the TIMER0 register (incremented count from the prescaler).

When the count goes from FF(HEX) +1 (255 decimal,it over-runs back to zero).

So (wild assumption here) when the count overflows passed 255 the INTERRUPT occurs and the program jumps to the Label TLOOP. The LED blinks, then INTCON.2 pin is the reset to 0 and it does it all again.

So basically to my (small) mind the LED would blink every 1/64th of 1MHZ.

Anywhere warm on this one?

Dave

mackrackit
- 23rd March 2010, 00:59
Warm...


Setting the Interrupt_Control pin.5 = 1 simply enables the Timer0 interrupt.
That is not setting a pin, it is setting bit#5 of the register.


When the count goes from FF(HEX) +1 (255 decimal,it over-runs back to zero).

Correct.


Now for the tricky part.
Running with a 4MHz OSC the chip is actually running at 1MHz.. Or cycles at 1 micro second (ticks).
If the prescaler is set for 1:1 then it will overflow every 256 micro seconds.
If the prescaler is set for 1:2 then it will overflow every 512 micro seconds.
If the prescaler is set for 1:256 then it will overflow every 65536 micro seconds.

LEDave
- 23rd March 2010, 16:10
Hi there.

As ever can I start with a question:

The TIMER program. My reading of it is that with a prescaler of 1:64 the LED
attached to PORTD.4 would blink (toggle) every 16384 microseconds (pretty quick) And that because this is driven by the internal clock runs independently of any code enclosed within 'MAIN'. For example, you could have an LED set within MAIN to say PORTD.3 which would blink every 2 seconds whilst the LED on PORTD.4 would to all intents and purposes show permanently on (like you said a heartbeat indicator that all's running well).

Am I reading this right?

David

HenrikOlsson
- 23rd March 2010, 16:49
Hi Dave,
Yes, the LED would toggle every 16384uS, in other words it would blink at rougly 30.5Hz, youll be hard pressed to see that. If you change the prescaler to 1:256 you'll get 4000000/4/256/256/2 = 7.62Hz.

The problem with PBP's way of handling interrupts is that it can not interrupt the command/statement that it is currently executing. Lets say for example that your main routine looks something like this:

Main:
GPIO.0=1
Pause 500
GPIO.0=0
Pause 500
Goto Main
This would blink a LED connected to GPIO.0 at 1Hz and you would think that the TMR0 interrupts would blink the other LED at 7.62Hz, unfortunatley that's not the case....
In the above code the interrupts generated by TMR0 would only get served between each statement. In other words, during the 0.5 second pauses the 7.62Hz blink would stop.

Basically, what PBP does, under the hood, is to add check after each statement, like:

Main:
GPIO.0=1
IF Interrupt goto TLOOP 'This is not the actual code it adds, it's just to illustrate the principle
Pause 500
IF Interrupt goto TLOOP
GPIO.0=0
IF Interrupt goto TLOPP
Pause 500
IF Interrupt goto TLOOP
Goto Main
IF Interrupt goto TLOOP
As you can see, if an interrupt occurs in the middle of a Pause it won't get serviced until the Pause statement has finished so if you're using PBP's ON INTERRUPT you need be aware of this. There are other ways to do it which doesn't suffer from the issue described above (Darrels Instant Interrupt routines obviously).

Hope it helps.
/Henrik.

LEDave
- 23rd March 2010, 17:40
Hi Henrik


As you can see, if an interrupt occurs in the middle of a Pause it won't get serviced until the Pause statement has finished so if you're using PBP's ON INTERRUPT you need be aware of this.

Very interesting that because I built a little test circuit based on mackrackit's code using a PIC12F683 (program below) with the INTERRUPT toggling an LED on GPIO.4 The MAIN code turned an LED on and off you've guest it using pause statements!

I was expecting the INTERRUPT LED (GPIO.4) to blink really quickly and the LED on GPIO.0 to blink at 500 mili_secs much slower, in reality they were much the same speed.

The manual refers to this as (latency). Like you say it pays to be aware of it. You wouldn't want an interrupt acting as an emergency stop when combined with a long pause statement.....Ouch!



ANSEL = %00000000
CMCON0 = %00000111
TRISIO = %11101110
GPIO = %00000001
INTCON.5 = 1 'ENABLE TMR0
OPTION_REG = %10000101 '16BIT 1:64 PRESCALE

ON INTERRUPT GOTO TLOOP

MAINLOOP:
PAUSE 500
low GPIO.0
PAUSE 500
high GPIO.0
GOTO MAINLOOP


DISABLE
TLOOP:
INTCON.2=0:TOGGLE GPIO.4
RESUME: ENABLE

HenrikOlsson
- 23rd March 2010, 18:42
Hi,
Now that you're aware of how ON INTERRUPT works there are a few things that can be done to help speed up the response (latency). Instead of having a single 500ms long pause, how about 500 pauses, each 1ms long?

i VAR WORD
Main:
GPIO.0 = 1
GOSUB GoToSleep
GPIO.0=0
GOSUB GoToSleep
Goto Main

GoToSleep:
For i = 1 to 500
PauseUs 1000 'Tweak this if timing is critical.
Next
RETURN

Now, you should get pretty close to what you expected in the first place. If timing is really critical you'll need to tweak the PauseUs statement as each time thru the loop takes a couple of uS longer due to the inserted checks of the interrupt-flag and the fact that it takes a few cycles to jump around inside the FOR-NEXT loop.

Also, remember what we said about HIGH and LOW? That they write to the TRIS register everytime.....and there's no need for you to use them as you've so elegantly set the TRIS register correctly at the beginning of your program. It's usually "better" and faster to simply write directly to the port register with GPIO.0=1 etc.

/Henrik.

LEDave
- 23rd March 2010, 20:17
Henrik thank you.

The program ran a treat. GPIO.0 blinking away at around a half a second period, GPIO.4 essentially 'on' all the time, very clever.

Nice little project you set up there mackrackit, thanks a lot. I've learned a lot from that namely:

1/ Read the program specification more closely! mackrackit wrote:

But if you do this using pauses to blink the LED the pauses will maybe get in the way (they did. I'm pleased they did though, I've learned from that).


2/ How a timed INTERRUPT works and some pitfalls (PAUSE)!

3/ A re-iteration about HIGH / LOW writing to the register everytime they're used. Far better to set the TRISIO register up and write directly to the PORT. I'm starting to appreciate the subtlety of these things, still lots to learn / re-learn though.

Right then, what's next?

Dave

rmteo
- 23rd March 2010, 20:57
My suggestion is to learn what a "true" interrupt is and how to use it - as your next step. If it means using DT's routines because PBP does not do it, then by all means do so. It will enable you to do so much more as you advance in your adventures with microcontrollers. :p

LEDave
- 23rd March 2010, 22:03
Thanks for that rmteo.

I'll bear that in mind. Don't forget I'm very new to this, sure I'll have to learn all about interrupts at sometime (maybe now is that time).

I'll be very interested in hearing where mackrackit, Henrik and Joe S think I should go next as they have an understanding on where my knowledge base (or lack of it) lies.

Hey I couldn't turn an LED on a Month ago!

Cheers.

Dave

mackrackit
- 23rd March 2010, 23:03
Henrik,
Thanks for finishing that lesson, I got busy.

rmteo,
Good point about ASM interrupts. I am not sure if Dave can do that with the demo version. But when he gets the full version...

Dave,
We are not finished with PBP interrupts yet :)
As you saw things can move pretty fast with the hardware and if you want to have an event happen at a certain time no matter what an interrupt can help.

Many times it is not recommended to use PAUSEes because as you now know they block other things from happening. There are enough things that do this without adding more, but sometimes we have to use them. Every thing in its place.

Now try something like this...
Do a "MAIN_LOOP" that will TOGGLE a LED with a button press. Every time you press a button the LED changes state.

Then make a BYTE size variable and add the PBP interrupt routine for another LED. The new variable will increment a value of 1 every time the interrupt "triggers".

After a given amount of "trigger", the variable reaches 10 the second LED changes state.

This should happen whether the first LED and button has been activated or not.
By having the variable increment to change the second LED state you can now make it blink at any time frame you want.

rmteo
- 23rd March 2010, 23:34
It may be worth pointing out that one does not need to use ASM to use interrupts. I have (and use) 3 different versions/dialects of BASIC for PIC's and they all handle interrupts (including vectored interrupts) without having to delve into ASM. Same situation with C.

mackrackit
- 23rd March 2010, 23:36
It may be worth pointing out that one does not need to use ASM to use interrupts. I have (and use) 3 different versions/dialects of BASIC for PIC's and they all handle interrupts (including vectored interrupts) without having to delve into ASM. Same situation with C.
But this is a PBP forum... So the point is???

LEDave
- 24th March 2010, 00:23
Gulp, I'm on it.

I'm probably going to go quiet for a while trying to figure this one out. I'll give it my best shot though.

I suspect you and Henrik could code it in about five minutes!

Then again I'm not you or Henrik..... :-)

Dave

mackrackit
- 24th March 2010, 00:47
I suspect you and Henrik could code it in about five minutes!
Maybe I can now... 15 years ago would be a different story.

You are doing great! Keep at it!

Oh, forgot to mention the assignment is due Friday :eek:

LEDave
- 24th March 2010, 23:51
Hi everyone.

I've been busy on the 'assignment'.

I've got the first part going namely:

Do a "MAIN_LOOP" that will TOGGLE a LED with a button press. Every time you press a button the LED changes state.

I built a test circuit which I made a small mistake on, then having zero programming confidence quickly convinced myself I'd made a code error, turned out I'd soldered a link into the wrong place (hours wasted), grrrr.

So on my PIC12F683 GPIO.5 has a push button attached which changes an the state of an LED on GPIO.0 everytime it's pressed, so far so good, now for the tricky part....!

It's taking longer than expected so my homework may not been handed in until Monday. :(

Still, only 14 Years and 48 weeks to catch up with you mackrackit!

Dave

mackrackit
- 25th March 2010, 01:27
Still, only 14 Years and 48 weeks to catch up with you mackrackit!
And I am trying to catch up with Bruce...

It never ends :)

LEDave
- 25th March 2010, 22:56
Hi everyone.

Struggling a bit (well quite a bit actually) with the second / third parts of the project.

The brief says:


Then make a BYTE size variable and add the PBP interrupt routine for another LED. The new variable will increment a value of 1 every time the interrupt "triggers".

Ok, so what I'm trying to do here is to use the INTERRUPT flag as my counter (INTCON.2=1) I've set the prescaler at 1:256 = 65536us = 7.6HZ and set 'I' as a VAR BYTE.

My theory goes something like this:

If count (VAR BYTE 'I' incremented by the INTERRUPT flag) = 10 then TOGGLE the LED.

Here's how I'm trying to do it and where I'm falling down.


IF INTCON.2=1 ' INTERRUPT flag overflows
THEN I = I + 1 ' add 1 to the value of I.
INTCON.2=0 ' Reset the overflow flag.
IF I<=10 GOTO MAIN ' If count doesn't = 10 loop again.
IF I =10 GOTO TOG ' If count = 10 then TOGGLE the LED.


I'm thinking at 10 'counts' at 7.6HZ should be approximately blink the LED once a second-ish.

All a bit fragmented I know but I hope what on saying is on the right tracks.

Any thoughts, pointers?

Dave

mackrackit
- 25th March 2010, 23:24
The basic interrupt routine you have worked with


DISABLE
TLOOP:
'DO SOMETHING
INTCON.2=0
RESUME
ENABLE


SOMETHING...
I = I + 1
IF ??? THEN
???
RESET COUNTER
ENDIF

Tick Tock... :)

LEDave
- 25th March 2010, 23:36
DISABLE
TLOOP:
IF INTCON.2=1 THEN I = I + 1 :INTCON.2=0 IF I<=100 GOTO MAIN IF I =100 GOTO TOG
tog:TOGGLE GPIO.2
RESUME: ENABLE


That's what I was trying to fit in.

Blimmey, it's nearly Friday already:eek:

Am I close-ish.

Dave

mackrackit
- 25th March 2010, 23:45
Close-ish...

IF INTCON.2=1
is not needed in the interrupt routine, that is what send the code there in the first place.

The rest might work.
Does it??

LEDave
- 26th March 2010, 00:06
Mmmm.

I was trying to use then reset IF INTCON.2=1 to increment count on 'I' the VAR.


IF INTCON.2=1 THEN I = I + 1 :INTCON.2=0

I'll sleep on it (I hope it doesn't keep me awake thinking).

Dave

mackrackit
- 26th March 2010, 00:11
Something...
I = I + 1
if ??? Then
???
I = 0 'reset counter
endif

HenrikOlsson
- 26th March 2010, 07:16
IF INTCON.2=1
is not needed in the interrupt routine, that is what send the code there in the first place.
Correct. But remember that if/when you start adding more interrupt sources you need to determine which one it was that tripped so checking the interrupt flag is probably good practice. But as have been said, it's not strictly needed in this case.

You seem to have a GOTO Main inside the ISR - you can do that but it is probably not a good idea as it will restart from the beginning of the program and not where it got interrupted. This MAY not be a problem in THIS particular program but can cause some interesting results so - try not to do that.

Have a look at this:


DISABLE
TLOOP:
IF INTCON.2 = 1 THEN 'TMR0 Interrupt?
I = I + 1 'Increment counter
IF I = 100 THEN 'Has it reached 100?
TOGGLE GPIO.2 'If so, toggle LED...
I = 0 '...and reset counter
ENDIF
INTCON.2 = 0 'Reset interrupt flag
ENDIF
RESUME 'back to work.
ENABLE


/Henrik.

LEDave
- 26th March 2010, 20:28
Well once again I've learned a lot of things, thanks as ever.

In the UK there's a famous comedy sketch where a musician says "I was playing all the right notes
but not necessarily in the right order".

I was a little (ok a lot) like that in this last exercise. I had written down I = 0 to reset the counter, I knew
I had to do that which is something and I'd figured I = I + 1 to add to / increment the counter, so not all bad.

Henrik highlighted within the program:

INTCON.2 = 1 THEN 'TMR0 Interrupt?

I guess that's because as mackrackit pointed out to me that for the program to be there the INTERRUPT
must have already occured?



ANSEL = %00000000 'Disable analog select so ports work as digital i/o
CMCON0 = %00000111 'Disable analog comparators
TRISIO = %11111110 'TRISIO.0 set as OUTPUT
GPIO = %00000000 'All bits set LOW
INTCON.5 = 1 'ENABLE TMR0
OPTION_REG = %10000101 '16BIT 1:64 PRESCALE


ON INTERRUPT GOTO TLOOP 'ON INTERRUPT GOTO the INTERRUPT handler LABEL 'TLOOP'

i var byte 'Set I as a VARIABLE BYTE

Main:

Not_pressed:
PAUSE 25 'Leave 25mili_sec for a button press to occur.
if GPIO.5 = 1 THEN GOTO Not_pressed 'Keep waiting for +0v button press on GPIO.5
IF GPIO.5 = 0 THEN goto LED 'Button has been pressed move to LABEL LED:
LED:
TOGGLE GPIO.0 'Change state of GPIO.0 pin
GOTO Not_pressed 'Start again

DISABLE 'Disable INTERRUPT in handler
TLOOP:
IF INTCON.2 = 1 THEN 'TMR0 Interrupt?
I = I + 1 'Increment counter
IF I = 100 THEN 'Has it reached 100?
TOGGLE GPIO.2 'If so, toggle LED...
I = 0 '...and reset counter
ENDIF
INTCON.2 = 0 'Reset interrupt flag
ENDIF
RESUME:ENABLE 'ENABLE INTERRUPT in handler start prog again


10/10 for you guys.

Dave (not clever just persistent).

mackrackit
- 26th March 2010, 22:58
You are doing great Dave, I wish more that came here wanted to learn and not just looking for a copy/pastes solution.

I agree with Henrik about this


INTCON.2 = 1 THEN 'TMR0 Interrupt?
Good to learn what to do if you have multiple interrupts. If you only have one interrupt and you are trying to save code space, as with the demo version, or an instruction cycle or two then you can leave it out.

Another thing to think about when using interrupts is to try and keep the instructions in the handler as few as possible. You would not want to miss an interrupt while taking care of one. Might have to get creative at times but that is the fun. Every project is a puzzle.

Hey, you did not ask "whats next"... :p

Do you have a serial port or a USB to serial converter on your computer?

LEDave
- 27th March 2010, 11:25
Hey, you did not ask "whats next"...

I nearly did, then I thought have we finished TMR0, I'll leave that one_liner one more post I thought, then you beat me to it:)


Do you have a serial port or a USB to serial converter on your computer?

On this M/C a DELL, I have only USB's. On my old pc I have two USB ports and a serial port on the back going spare.

Quick question:

When I built that last circuit (VDD/10k resistor/GPIO.5/button/gnd) it worked. When the button ON gpio.5 was pressed the GPIO.0 LED lit (most of the time 90%+). On some occations however the LED didn't latch on or off. I'm thinking switch de-bouncing was the problem. Is there a way of making the switch work 100% of the time? Maybe BUTTON.

Dave

HenrikOlsson
- 27th March 2010, 12:16
Hi Dave,
Yes the switch probably bounced so it did toggle on then off again before you could see it. Or, you happend to press (and release) the button during the 25ms pause which in case means the program misses the button-press.... Or you pressed it and held it longer than 25ms (quite likely) so that when the program "came around" the button was still pressed so it toggled the LED again....

I'd try lowering that first pause a bit or remove it completely and instead add a pause after the TOGGLE GPIO.0 statement to remove any debounce. Then I'd make the program check that the button was released again before jumping back to Not_Pressed But remeber what happens with the interrupt latency when you're using things like Pause etc.

The BUTTON command is another posibillity but to be honest I don't know exactly how it works internally so I can't say what impact it will have on your interrupt latency.

Side note: You can assign aliases to the port pins (or any variable, register, bit etc). So you can do something like:

myButton VAR GPIO.5
LED_1 VAR GPIO.0
LED_2 VAR GPIO.2

If myButton = 0 then....
....
....


/Henrik.

mackrackit
- 27th March 2010, 12:34
What Henrik said....
I have not used the button command either.
To do a check on the button, if the button is pressed the code would GOSUB to a routine to check if the button is still pressed, then return with that info one way or the other.

But... While we are one the subject of interrupts and GPIO5 is on the pin it is.
Look at Interrupt On Change.

In the mean time find a serial cable to connect to your PC and your board. We will get back to communications later.

Play with the switch problem for now.

LEDave
- 27th March 2010, 12:36
Hi Henrik,


But remember what happens with the interrupt latency when you're using things like Pause etc.


I do indeed remember. So as a rule of thumb, are pauses to be avoided in a program whenever possible or only when using INTERRUPTS.

Dave

mackrackit
- 27th March 2010, 12:46
Hi Henrik,



I do indeed remember. So as a rule of thumb, are pauses to be avoided in a program whenever possible or only when using INTERRUPTS.

Dave

In my opinion everything has a place. But most times it is best to avoid long pauses. If you need to pause for a long time setup a pause loop with several short pauses to total the time. Get into that habit and when you do need to use an interrupt you will be ready.

LEDave
- 27th March 2010, 13:59
If you need to pause for a long time setup a pause loop with several short pauses to total the time. Get into that habit and when you do need to use an interrupt you will be ready.

I can go with that. I liked Henrik's microsecond pauses solution to the INTERRUPT PAUSE problem, which is what your'e saying / reiterating.

Regarding the cable, this isn't what I'm looking for is it? It's the other that needs to be a 'male' connecter is that right?

http://www.maplin.co.uk/module.aspx?moduleno=29968

mackrackit
- 27th March 2010, 14:25
Yup. That will work. Then you need a DB9 female connector that you can solder wires on to go to your dev-board.

mackrackit
- 27th March 2010, 16:36
Dave,
What chips do you have availabe to use?
Did you get any new types?

LEDave
- 27th March 2010, 18:38
I've got 4x12F683 1x12F675 & 2X16F684

The 684 I was / am going to use half of PORTA & PORTC to drive a seven segment display. The first program was just to spell my name DAUE. I got to A then ran out of free code.

I really must buy the PRO_version. Mecanique is the place to buy it from in the UK right?

Dave

mackrackit
- 27th March 2010, 19:54
Buy it from Lester. He is the one that gave us this forum.
http://www.picbasic.co.uk/

LEDave
- 27th March 2010, 21:22
Hi mackrackit,

Hard economics for me I'm afraid, I'm a carer.

Dave

LEDave
- 28th March 2010, 09:20
Hi mackrackit,


Buy it from Lester. He is the one that gave us this forum

I appreciate what you're saying and this forum, I really do and I don't want to cause an upset.

The difference in pricing from Mec & Corn means I can buy a PICkit2 and a
USB/serial cable for the difference, without upsetting the wife.

Dave

mackrackit
- 28th March 2010, 10:37
Hard economics for me I'm afraid, I'm a carer.

That sounds like a demanding job. I bet playing with MCUs is a good way to get your mind off it at the end of the day.

Economics, yup, know what you mean.

I appreciate what you're saying and this forum, I really do and I don't want to cause an upset.

No upset here, many buy from mecanique, I did not know that they are selling PBP for 20 less than Crownhill. Interesting... I have seen complaints about mecanique here, but as long as they deliver... Maybe someone else will chime in about this.

I was looking at this http://www.myamicus.co.uk/ as an alternative but it is only for a 18F25K20 and I do not know much about it yet. I am not recommending, just showing a possible option...

rmteo
- 28th March 2010, 15:28
Hi mackrackit,

I appreciate what you're saying and this forum, I really do and I don't want to cause an upset.

The difference in pricing from Mec & Corn means I can buy a PICkit2 and a
USB/serial cable for the difference, without upsetting the wife.

Dave
Have you considered using free tools? ;)

LEDave
- 28th March 2010, 17:21
That sounds like a demanding job.

It has it's moments (usually several a day) that said it's very rewarding.


I bet playing with MCUs is a good way to get your mind off it at the end of the day.

100%, I love it. We all need an interest. In a funny sort of way PIC's are very similar to us humans. They both input and output and if something goes wrong in between then there's a problem that needs sorting.;)

When you asked what PIC's I had the other day.Were you thinking of any I should have in particular?

Dave

mackrackit
- 28th March 2010, 17:28
100%, I love it. We all need an interest. In a funny sort of way PIC's are very similar to us humans. They both input and output and if something goes wrong in between then there's a problem that needs sorting.;)
That is a good one!!!


When you asked what PIC's I had the other day.Were you thinking of any I should have in particular?
I was just wondering so we could make lessons to match your hardware...

LEDave
- 28th March 2010, 18:01
I was just wondering so we could make lessons to match your hardware...

Well, I'm going for the PRO_version asap. So by the end of next week I'm hoping I can pretty much use any PIC (within the confines of the PICkit1) I like.

If you let me know what you think I'll need I can order it in.

I really appreciate what you're doing by the way.

Dave

mackrackit
- 28th March 2010, 18:20
Well, I'm going for the PRO_version asap. So by the end of next week I'm hoping I can pretty much use any PIC (within the confines of the PICkit1) I like.
COOL!!!


If you let me know what you think I'll need I can order it in.
I think the serial parts we talked about will be good for now. That will give a way to debug and learn how to communicate with another device.
...Do you have a solder-less breadboard? and some miscellaneous LEDs and resistors? ...


I really appreciate what you're doing by the way.

Dave
What comes around goes around... :)

LEDave
- 28th March 2010, 18:45
Do you have a solder-less breadboard?

No but I saw one in Maplins the other day, I'll pick one up.


and some miscellaneous LEDs and resistors? ...

Yes I do, hey I'm LEDave...:D

Byte_Butcher
- 28th March 2010, 18:57
If you let me know what you think I'll need I can order it in.
Dave

Might I suggest a LCD display?
Getting an LCD up and running might be a good experiment, and it's also a handy tool for debugging code later.


steve

LEDave
- 28th March 2010, 19:26
Getting an LCD up and running might be a good experiment, and it's also a handy tool for debugging code later.


I'm game, don't forget I couldn't turn an LED on a few weeks ago though!

Dave

mackrackit
- 28th March 2010, 19:37
Is there a surplus store over there like this?
http://www.allelectronics.com/make-a-store/category/365/LCDs-Liquid-Crystal-Displays-/1.html

LEDave
- 28th March 2010, 19:55
There's RS

They have these (and I've got an account).

http://uk.rs-online.com/web/search/searchBrowseAction.html?method=retrieveTfg&tfgSearch=Y&N=4294955787&searchTerm=LCD%20Displays%20-%20Alphanumeric&cm_sp=Predictive_search-_-Pedictive_search-_-LCD%20Displays%20-%20Alphanumeric

Or Maplins again:

http://www.maplin.co.uk/Search.aspx?criteria=lcd&source=15

The RS range seems far superior.

Dave

Byte_Butcher
- 28th March 2010, 20:18
I'm game, don't forget I couldn't turn an LED on a few weeks ago though!


Sure, most of us couldn't flash an LED when we started.
But Mackrackit is doing a nice job of getting you up to speed, and a parallel LCD display isn't that hard to set up.

You'll need to set up 4 pins on your PIC, all on one port for your LCD data lines, and 2 more pins for Enable and Register Select
You'll need to make sure that those 6 pins are setup as digital outputs and any other stuff that shares those pins (ADC, comparators, etc) are disabled.
Once the pins are set correctly then you'll add a few DEFINE's to your program to tell the PIC where to find your LCD and what pins are what.
Like this, but with YOUR particular ports and pin numbers that you are using:



DEFINE LCD_DREG PORTD 'Set LCD Data port
DEFINE LCD_DBIT 4 'Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTE 'Set LCD Register Select port
DEFINE LCD_RSBIT 0 'Set LCD Register Select bit
DEFINE LCD_EREG PORTE 'Set LCD Enable port
DEFINE LCD_EBIT 2 'Set LCD Enable bit
DEFINE LCD_BITS 4 'Set LCD bus size (4 or 8 bits)


Then it's just a matter of using the LCDOUT command...


LCDOUT $fe, 2, "HELLO WORLD"


or if you wanted to display the content of a variable as a decimal number:



myvariable var word
myvariable = 3955

LCDUT $fe, 2, DEC myvariable


It's easy! :)


steve

mackrackit
- 28th March 2010, 20:31
Has anyone used this one? Is it any good?
http://uk.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=5326795

LEDave
- 28th March 2010, 21:16
Hi B_B

Ok, I'm sold:)

These LCD's look like great fun and a really useful interface.

When my first LED came on, that was brilliant. When my seven segment display /
driver lit up and counted up to nine that was cool.

These look in a different league, can't wait.

Dave

Byte_Butcher
- 28th March 2010, 22:36
Has anyone used this one? Is it any good?
http://uk.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=5326795

That one doesn't look like it's got a backlight. One with a backlight would be sexier... :)

Here in the US, I find these to be a good deal for $10USD.
http://search.digikey.com/scripts/DkSearch/dksus.dll?vendor=0&keywords=c0220az
Don't know about UK vendors.


steve

mackrackit
- 29th March 2010, 15:26
Interrupt on change (interrupt when the state of a pin changes)
Again this is a snippet from another chip (16F873A) but it will give you something to start with.


ON INTERRUPT GOTO MYINT
INTCON = %10010000 'PORTB.0 CHANGE

DISABLE
MYINT:
IF PORTB.0 = 1 THEN
' DO SOMETHING
ELSE
'DO SOMETHING ELSE
ENDIF
INTCON.1 = 0
RESUME
ENABLE
'THE ABOVE WILL ALSO DEBOUNCE THE SWITCH

LEDave
- 29th March 2010, 16:30
Cheers mackrackit,

I made a little table up that other newbies who are maybe following this thread might find useful. It hinges on what you said the other day about setting the prescaler (TMR0) and using that with (I = I +1) to set up a delay of your choosing.



BIT TMR0 Time_u_secs HZ
000 1:2 512 976
001 1:4 1024 488
010 1:8 2048 244
011 1:16 4096 122
100 1:32 8192 61
101 1:64 16384 30.5
110 1:128 32768 15.2
111 1:256 65536 7.6

Didn't quite come out as planned and every time I edit it the changes I make it just resets.
Still, I'm sure you get the drift (might be worth checking my figures as well though).


Any thoughts on that LCD?

Dave

LEDave
- 29th March 2010, 17:13
I've just had a thought.

It's probably dangerous for me to offer advice right now, no matter how well intensioned. As some of my conclusions maybe a little off the mark.

Dave

mackrackit
- 29th March 2010, 17:40
I've just had a thought.

It's probably dangerous for me to offer advice right now, no matter how well intensioned. As some of my conclusions maybe a little off the mark.

Dave
Most of mine are, does not stop me... :rolleyes:

LCD... Back-light would be nice but I did not see very many options from your supplier. So that is why I was looking at one with four lines.

LEDave
- 29th March 2010, 18:10
Most of mine are, does not stop me... :D


LCD... Back-light would be nice but I did not see very many options from your supplier. So that is why I was looking at one with four lines.

In the LCD product spec page (15/17) it says:

(8) In particular do not forcibly bend the I/O cable or the backlight cable. So maybe it does have a backlight?

That's for the display we were looking at:

http://uk.rs-online.com/web/search/searchBrowseAction.html?method=getProduct&R=5326795

Page (15/17) in here:

http://docs-europe.origin.electrocomponents.com/webdocs/06dd/0900766b806dda19.pdf

Dave

mackrackit
- 29th March 2010, 18:18
It also list specs for a LED and EL back light.
So I am not sure. Might be worth contacting them to find out.

LEDave
- 29th March 2010, 18:27
Might be worth contacting them to find out.

I'll try and contact the technical department tomorrow.

So what exactly are we after here? I'll try and find out if this one anything else they have exactly fits the bill.

Dave

mackrackit
- 29th March 2010, 18:31
I would look for one with LED back light. I think 16x4 is nice for one to use on the bench, but a 20x2 would also be OK, IMO.

LEDave
- 29th March 2010, 18:40
So I'm after a 16x4 LED backlight LCD.

Any other spec I should make sure it has?

Dave

mackrackit
- 29th March 2010, 18:50
Hitachi 44780 controller or equivalent. Seems like most do..

LEDave
- 30th March 2010, 16:04
I've just been in touch with RS. They're looking into it.

I've for a 16x4 LED backlight LCD with Hitachi 44780 controller or equivalent.

Fingers X'd

Dave

Archangel
- 30th March 2010, 22:59
I've just been in touch with RS. They're looking into it.

I've for a 16x4 LED backlight LCD with Hitachi 44780 controller or equivalent.

Fingers X'd

Dave
Hi Dave. Dave suggested a 16x4 and 20 x2 lcd
I have only seen 20x4 and 16x2, not saying His supplier doesn't sell those, only that I've not seen them. That said, here are some links to eBay sales and sellers in, dare I say it? China, where everything is made.
http://cgi.ebay.com/16x2-LCD-Module-White-Characters-Blue-Backlight-HD44780_W0QQitemZ350333466029QQcmdZViewItemQQptZLH _DefaultDomain_0?hash=item51918075ad
http://cgi.ebay.com/HD44780-16x2-characters-LCD-module-Green-backlight_W0QQitemZ260573955458QQcmdZViewItemQQptZ LH_DefaultDomain_0?hash=item3cab6b0582
http://cgi.ebay.com/HD44780-16x2-Character-LCD-LCM-Blue-White-backlight_W0QQitemZ270553868761QQcmdZViewItemQQptZ LH_DefaultDomain_0?hash=item3efe4469d9
http://cgi.ebay.com/HD44780-20X4-Character-LCD-Display-with-BLUE-backlight_W0QQitemZ280484116835QQcmdZViewItemQQptZ LH_DefaultDomain_0?hash=item414e27f963
http://cgi.ebay.com/20x4-LCD-Module-White-Characters-Blue-Backlight-HD44780_W0QQitemZ250605685995QQcmdZViewItemQQptZLH _DefaultDomain_0?hash=item3a59434ceb
http://cgi.ebay.com/HD44780-20X4-Character-LCD-Display-with-BLUE-backlight_W0QQitemZ370355244322QQcmdZViewItemQQptZ LH_DefaultDomain_0?hash=item563ae48d22

Depending upon the trade agreements and import policys you might even get to blow off the VAT

mackrackit
- 31st March 2010, 00:02
They come in all sizes.

The one we have been talking about from Dave's supplier is a 16x4. I even have some 24x2 surplus LCDs.

The ones I hate are the 16x1 , I got some that are really 8x2 but all on the same line...

So basically just fine a the largest multi-line display you can afford.

Byte_Butcher
- 31st March 2010, 00:23
They come in all sizes.

I've got some in 2 x 20 and 2 x 24
I was looking at some 2 x 40's and 4 x 40's at Digikey not long ago.

Yes... all sizes.!


steve

rmteo
- 31st March 2010, 00:45
Be aware that 4x40 LCD's are a little different and have 2 controllers (and 2 chip enable lines).

LEDave
- 31st March 2010, 15:21
Hi everyone.

After seeing Joe's ebay displays, I thought I'd have a look on ebay UK and came
across this one:

http://cgi.ebay.co.uk/20x4-LCD-Module-White-Characters-Blue-Backlight-HD44780_W0QQitemZ350334193407QQcmdZViewItemQQptZUK _BOI_Electrical_Components_Supplies_ET?hash=item51 918b8eff#ht_2814wt_957

I was thinking of going for this one from Joe's list in the USA as it says free shipping, although it might a couple of weeks to arrive:


http://cgi.ebay.com/HD44780-20X4-Character-LCD-Display-with-BLUE-backlight_W0QQitemZ280484116835QQcmdZViewItemQQptZ LH_DefaultDomain_0?hash=item414e27f963#ht_3109wt_8 02

What do we think.

Dave

LEDave
- 31st March 2010, 15:32
Almost forgot.

I've bought the MicroCode Studio full program from Mecanique and haven't heard a dicky bird from them, not even an acknowledgement email.

I've re-emailed them on both their email addresses, nothing, they haven't even sent a read receipt. And phoned them three time today, again nothing, no one answering the phone.

I'm a little worried, although are they a small one man outfit and maybe on an Easter break?

Not a lot I can do until someone replies to me I guess.

Dave

LEDave
- 31st March 2010, 15:40
UPDATE:

I've just phoned again and got through (typical), it's being sent today:)

So looking forward to that arriving and no more 'you have used all your code lines prompts'

Dave

mackrackit
- 31st March 2010, 16:04
Did you only order Micro Code Studio or do you mean Pic Basic Pro with the full version of MCS?

LEDave
- 31st March 2010, 16:25
PICBasic PRO Compiler with MicroCode Studio Plus (1)

Please tell me it's the right one?

Dave

mackrackit
- 31st March 2010, 16:28
That sound correct.
Your earlier post had me wondering. ;)

LEDave
- 31st March 2010, 16:36
Hi mackrackit it's this one:

http://www.mecanique.co.uk/products/compiler/pbp.html

Have a quick look for me (I can't afford to lose another nights sleep).

Dave

mackrackit
- 31st March 2010, 16:40
That's the one.
Sorry to scare you...

LEDave
- 31st March 2010, 17:05
:cool:

Thanks for that mackrackit. I thought I had the right one, easy to make a mistake though.

What do you think on the LCD front then, is this one any good?

http://cgi.ebay.co.uk/20x4-LCD-Module-White-Characters-Blue-Backlight-HD44780_W0QQitemZ350334193407QQcmdZViewItemQQptZUK _BOI_Electrical_Components_Supplies_ET?hash=item51 918b8eff#ht_2814wt_957

Or should I order this one from the USA with the free shipping?

http://cgi.ebay.com/HD44780-20X4-Character-LCD-Display-with-BLUE-backlight_W0QQitemZ280484116835QQcmdZViewItemQQptZ LH_DefaultDomain_0?hash=item414e27f963#ht_3109wt_8 02

Or neither.

Dave

mackrackit
- 31st March 2010, 17:43
From what I can see they look like they are the same?
I am using a phone at the moment so I may not be see everything.

LEDave
- 1st April 2010, 12:38
Well my program disks have arrived:)

One PICBASICPRO Compiler & a MicroCode Studio plus disk.

I'll install them this evening when I have some time.

Dave

mackrackit
- 1st April 2010, 13:34
Now the fun begins... :)

LEDave
- 1st April 2010, 14:55
Now the fun begins...

Indeed it does.

Are the two programs fairly straight forward to install?

I guess I need to uninstall the Demo version first.

Dave

mackrackit
- 1st April 2010, 15:17
They should install just like the demo versions did...

What Operating system are you using? 32 or 64 bit?

LEDave
- 1st April 2010, 16:31
XP 32bit.....

mackrackit
- 1st April 2010, 16:34
Should not be a problem then.

LEDave
- 1st April 2010, 17:12
When I get a minute, I'm going to leave the Demo in place and just install the full version over it.

Unless anyone can thing of a reason why I shouldn't do that of course.

Dave

mackrackit
- 1st April 2010, 17:27
Darrel has mentioned having multiple versions of PBP installed. So you may not have to install over but in another place.

LEDave
- 1st April 2010, 21:05
Well, I've now got two working programs installed:

1/ MicroCode Studio Plus - PICBASIC PRO

&

2/ MicroCode Studio - PICBASIC PRO

Tonights silly question: Which one do I use?

Dave

mackrackit
- 1st April 2010, 23:28
I will guess option #1.

You can tell the difference by the chip select drop down box. the full version will have many mor to choose from than the demo.

LEDave
- 2nd April 2010, 22:28
Yes loads more chips and no more 31? lines of code exceeded:)

I've built a circuit today to spell my (and the wifes;) ) name on a seven segment display using a PIC16F684 PORTA and PORTC, works a treat.

We'll have to get to grips with those LCD's in the near future. In the meantime have a great Easter everyone.

Dave

rmteo
- 2nd April 2010, 23:42
Since you are having so much fun with the 7-segment displays and you have a character LCD on the way, think about getting a graphic LCD next. Then you can combine both and do stuff like this.

Byte_Butcher
- 3rd April 2010, 02:01
And if you find you have a fondness for the graphic displays, there's always lots of full color displays to choose from. :cool:
This one is serial QVGA . (240px x 320px, 65K color, 2.2" diagonal screen)

So many parts to choose from... so little time to read all the data sheets! :eek:

http://www.weirdstuffwemake.com/sweetwatergems/electronics/images/display_107.jpg


steve

Archangel
- 3rd April 2010, 10:21
Well my program disks have arrived:)

One PICBASICPRO Compiler & a MicroCode Studio plus disk.

I'll install them this evening when I have some time.

DaveCongratulations, you won't be dissapointed !

LEDave
- 3rd April 2010, 14:25
think about getting a graphic LCD next. Then you can combine both and do stuff like this.

Very impressive rmteo, I like the look of that. How difficult is one of these to set up?


And if you find you have a fondness for the graphic displays, there's always lots of full color displays to choose from.:D


So many parts to choose from... so little time to read all the data sheets!

Absolutely, I don't think I've read anything to do with PIC's that hasn't had a 19 page (minimum) PDF attached. Nice display B_B, again must have took some setting up?


Congratulations, you won't be dissapointed !

Hi Joe, I'm not already and I've only just began my journey.

Dave

Byte_Butcher
- 3rd April 2010, 19:21
Absolutely, I don't think I've read anything to do with PIC's that hasn't had a 19 page (minimum) PDF attached.

19 pgs sounds like a delight! The 18F46J50 I've been trying to "figure out" has a 554 pg data sheet. :(


Nice display B_B, again must have took some setting up?

No, actually they are pretty easy to use. They have onboard processor to do the "hard work", and you just send serial commands and data to it with SEROUT.
It also has a slot for a uSD card (up to 2GB) for photo or video storage. :cool:
It even has it's own programming language (4DGL) and can operate as a standalone device without an external processor.

The downside is that they are rather pricey. Mine is an "obsolete" model that I got a pretty good deal on or I probably wouldn't have bought it.
Newer models even have touchscreen capability!

If anyone is curious, here's the info for the display I have. The user manual is at the lower left corner of the page.
http://www.4dsystems.com.au/prod.php?id=2

Here's the code I used to display my avatar and greeting message. The Image is stored on the uSD card.
This is just a snippet from a much larger lump of code that displayed a slide show (about 50 items) with a text description for each.
You may still find a few odd variables and stuff left over from the original chunk of code, but it compiles and works on a 16F726.
Most of the code is just setting up registers and declaring variables and stuff. Once you get to the "main" section there's not much to actually sending data and displaying images already stored on the memory card...




'Test program for displaying photos and text - 16F726 w/ uLCD-320-PM2

'************************************************* ***************

Include "MODEDEFS.BAS" ' Include Shiftin/out modes
DEFINE OSC 16 ' 16 MHz Osc.
DEFINE HSER_BAUD 38400 ' Set baud rate
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 25 ' 19200 Baud @ 8MHz, 38400 Baud @ 16MHz

@ __config _CONFIG1, _DEBUG_OFF & _PLL_EN & _BORV_2_5 & _BOR_ON & _CP_OFF & _MCLRE_OFF & _PWRT_EN & _WDT_OFF & _INTOSCIO
@ __config _CONFIG2, _VCAP_RA0

'----------------------------------------------------------------------------
'SETUP SOME PORTS AND REGISTERS-----------------???????????????????????????????????----------------
OSCCON=%00110000 'Set Osc to 16MHz.
TRISA=%00000000 'Set 'em all to outputs
TRISB=%00000010 'Set portB to all outputs except RB1
TRISC=%10000000 'Set portC to all outputs except RC7
ANSELA=%00000000 ' Set all pins to digital
ANSELB=%00000000 ' Set all pins to digital
ADCON0=%00000000 'ADC off
option_reg.7=0
WPUB=%00000010

'ALIAS PINS----------------------------------------------------
to_LCD var PORTC.6 '??????????????????????
from_LCD var PORTC.7 '?????????????????????
offbutton var PORTB.1 '????????????????????????

'---------------------------
'---ALLOCATE VARIABLES----------------------------
textstartX var word : textstartX=05 'starting X position for text
textstart1YH var word : textstart1YH=01 'starting Y HIGH positon for text line 1
textstart1YL var word : textstart1YL=05 'starting Y LOW positon for text line 1
textstart2YH var word : textstart2YH=01 'starting Y HIGH positon for text line 2
textstart2YL var word : textstart2YL=35 'starting Y LOW positon for text line 2
photostartX var byte : photostartx =22 'starting X position for photo
photostartY var BYTE : photostartY = 40 'starting Y position for photo
width var byte : width = 200 'image width
height_H var byte : height_H = 0 'image height high byte
height_L var byte : height_L = 200 'image height low byte
addr_H var byte : addr_H=$00 'image address on card HIGH byte
addr_M var byte : addr_M=$10 'image address on card MID byte
addr_L var byte : addr_L=$00 'image address on card LOW byte

'---Font sizes---------------------------------------
fontsize1 var word : fontsize1=01
fontsize2 var word : fontsize2=02
fontsize3 var word : fontsize3=03

'---Predefine a few common colors---------------------------
redH var byte : redH=%11111000
redL var byte : redL=%00000000
greenH var BYTE : greenH=%00000111
greenL var byte : greenL=%11100000
blueH var byte : blueH=%00000000
bluel var byte : bluel=%00011111
yellowH var byte : yellowH=%11111111
yellowL var byte : yellowL=%11100000
magentaH var byte : magentaH=%11111000
magentaL var byte : magentaL=%00011111
cyanH var byte : cyanH=%00000111
cyanL var byte : cyanL=%11111111
orangeH var byte : orangeH=%11111010
orangeL var Byte : orangeL=%11100000
BlackH var Byte : BlackH=%00000000
BlackL var Byte : BlackL=%00000000

'-----------------------------------

Goto main: 'skip the subroutines and JGIG\

'---SUBROUTINE TO SHUT DOWN THE LCD DISPLAY "SAFELY" and end the program. (needs power reset to restart)
shutdown:
HSEROUT [$59,$03,$00] 'power down command
pause 250
end
'----------------------------------------------------------
'-----------------------------------------------------------

Main:

PAUSE 2000 'Make sure the LCD is awake
Hserout [$42, blackH,blackL] 'background color = black
pause 700
Hserout ["O", 01] 'Opaque text
pause 5
HSEROUT ["S",13,00,10,3,greenH,greenL,1,1," BYTE_BUTCHER",$00] 'Put user name at top of screen
pause 100
HSEROUT [$40,$49,photostartx,00,photostartY,width,height_H, height_L,16,addr_H,addr_M,addr_L] 'grab a photo from the uSD card and display it at the predefined coordinates
pause 200
Hserout ["S",textstartX,textstart1YH,textstart1YL,fontsize2,ye llowH,yellowL,2,2, " Greetings",$00] 'text line 1
pause 20
Hserout ["S",textstartX,textstart2YH,textstart2YL,fontsize3,cy anH,cyanL,1,1, " PBP users!",$00] 'text line 2
'----------
checkbutton:
if offbutton = 0 then gosub shutdown
Pause 100
goto checkbutton

end



steve

LEDave
- 3rd April 2010, 20:22
Very clever B_B I must say. Does seem like rather a steep learning curve, although that said I'm surprised at what pieces of code I can actually pick out and understand from your program. I've just got to keep at it I guess.

Whilst we're on LCD's, should I go ahead and order maybe a couple of these?

http://cgi.ebay.co.uk/20x4-LCD-Module-White-Characters-Blue-Backlight-HD44780_W0QQitemZ350334193407QQcmdZViewItemQQptZUK _BOI_Electrical_Components_Supplies_ET?hash=item51 918b8eff#ht_2814wt_957

What do we think, a good one to start off with?

Dave

Byte_Butcher
- 3rd April 2010, 21:56
Whilst we're on LCD's, should I go ahead and order maybe a couple of these?

http://cgi.ebay.co.uk/20x4-LCD-Module-White-Characters-Blue-Backlight-HD44780_W0QQitemZ350334193407QQcmdZViewItemQQptZUK _BOI_Electrical_Components_Supplies_ET?hash=item51 918b8eff#ht_2814wt_957

What do we think, a good one to start off with?

Dave

Sure. Why not. Anything with that"s got a Hitachi HD44780 controller is your friend. (like that one)

The choice of color, and number of lines and characters is only determined by your personal preference and pocketbook...

Order it and give it a go!


steve

Archangel
- 5th April 2010, 04:45
Very clever B_B I must say. Does seem like rather a steep learning curve, although that said I'm surprised at what pieces of code I can actually pick out and understand from your program. I've just got to keep at it I guess.

Whilst we're on LCD's, should I go ahead and order maybe a couple of these?

http://cgi.ebay.co.uk/20x4-LCD-Module-White-Characters-Blue-Backlight-HD44780_W0QQitemZ350334193407QQcmdZViewItemQQptZUK _BOI_Electrical_Components_Supplies_ET?hash=item51 918b8eff#ht_2814wt_957

What do we think, a good one to start off with?

Dave
Hi Dave,
It's the ones I always buy, you can kill them, but you have to work at it :) be careful buying from them, as they offer the exact same units with different prices. Their service is good, shipping a little slow sometimes, friendly and helpful.

LEDave
- 5th April 2010, 22:58
It's the ones I always buy, you can kill them, but you have to work at it

Hi Joe, you almost make that sound like a challenge...:)

I'm going to order a couple of those and see how it goes, plus a solder-less breadboard.

I'm still not 100% on the cables I need though. On this PC (DELL) I've have USB only but on my old m/c I have USB and a serial port on the back.

So should I just buy a serial cable and fem & male db converter or do I buy a usb.

Here's the link to a website I've found which seems pretty good:

http://www.cabling4less.co.uk/Data_Cables.php?gclid=CNq637Dp7aACFdGX2AodE28VFQ

mackrackit
- 5th April 2010, 23:18
If it was me I would use the old computer with the serial port for the machine to send data to
while using the new machine for coding and programing.

If you do it that way then one of the Female to Female cables should be fine. Cut it in half, plug into the computer and the wires can go to the bread board.

You will have to use an ohm meter to ring out which wire is which and you will probably have to solder thicker wires to the cable to work with the bread board.

You will only need, in most cases, the wires coming from the DB9 connector, 2, 3, and 5.

LEDave
- 5th April 2010, 23:49
Hi mackrackit,


If it was me I would use the old computer with the serial port for the machine to send data to while using the new machine for coding and programing.

I'm happy with that.

Another LEDave silly question coming up. Are we saying I should buy the top cable from the link below and cut one end off then meter the cable / pins out?

http://www.cabling4less.co.uk/Data_Cables.php?gclid=CNq637Dp7aACFdGX2AodE28VFQ

If that's right, how about buying the top cable and the 'Cabling4Less DB9 Data Gender Changer (M-M)' (three quarters of the way down the page) and soldering the wires onto that?

Dave

mackrackit
- 6th April 2010, 00:00
Might be a bit difficult to solder to that.
You could buy some " ends " as if you were making a cable ans solder to that and not cut the cable.

My way you end up with two cables. Just buy one long enough to fit the way your bench is set up. End up with two one meter cables?

LEDave
- 6th April 2010, 00:35
My way you end up with two cables. Just buy one long enough to fit the way your bench is set up. End up with two one meter cables?

I like it:cool:

Any other kit or should that do it for now?

Dave

mackrackit
- 6th April 2010, 00:45
The serial and LCD stuff should keep you busy for awhile :)

So many things that can be done now.

LEDave
- 6th April 2010, 01:30
The serial and LCD stuff should keep you busy for awhile

I'm really looking forward to it:)

I'll order that kit up and the displays asap.

Dave

LEDave
- 7th April 2010, 11:42
Two LCD's and one DB9 (Female) to DB9 (Female) cable ordered up:)

LEDave
- 8th April 2010, 19:30
Well the cables have arrived:)

First job, cut it in half and meter the pins out?

mackrackit
- 8th April 2010, 19:42
Yup.
You are looking for wires connected to
pin 5 = common
pic 2 = data to PC
pin 3 = data from PC

The others you will not need for awhile, flow control type stuff.

LEDave
- 8th April 2010, 21:09
Hi mackrackit,

Just to make sure that I'm checking the right pins. Pins 5 - 2 - 3 correspond to this diagram:

http://hflink.com/interface/DB9_RS232_pinout.gif

Dave

mackrackit
- 8th April 2010, 21:45
No, that is the male connector.
The female connector starts with 1 on the right.

LEDave
- 8th April 2010, 21:56
I'm pleased I asked:eek:

The one on the left then.

LEDave, also known as 'Mr Windy'

Dave

mackrackit
- 8th April 2010, 22:06
At least you did not ask how to tell which one is female or male... :p

LEDave
- 8th April 2010, 22:34
At least you did not ask how to tell which one is female or male

I had that one explained to me many years ago when I was a young apprentice, funny that was one lesson I never forgot;)

Right then I've got:

5 - Yellow

3 - Red

2 - Brown

How does that sound / look?

Very fine wires, I was quite surprised by that.

Dave

mackrackit
- 8th April 2010, 22:58
There does not seem to be much of a standard for color coding. That is the reason to check with a meter.

Small wires. Yup. The reason I mentioned soldering heavier wires on for breadbording.

Sounds like you are about ready for some fun.

LEDave
- 8th April 2010, 23:06
Sounds like you are about ready for some fun.

Ready and waiting:)

Although I haven't got my breadboard yet.

mackrackit
- 9th April 2010, 02:02
If you use a 14 pin chip in your PicKit1 the empty header holes near the diodes can be used for external to the board stuff. Solder a serial cable there??? Be sure to look at the PBP manual, gives a little schematic for serial hick ups. :)

LEDave
- 9th April 2010, 09:06
Mmmm,

A little confused here mackrackit. I can see the header J3 (see attached word.docs) but can't see which of the three cables go where from looking at the diagrams.

Also, am I right in that: Pin5 = clear to send, Pin3 = receive data and Pin2 = transmit data.

Or (wild assumptions here) I can connect the three wires to anywhere on J3 as long as they correspond to three I/O pins on the socket which can be set-up to communicate with the pc COM-PORT.

Dave

mackrackit
- 9th April 2010, 12:11
As far as I know, any of the PIC® that work in the PicKit1 do not have hardware serial (UART), so it does not matter. The only exception I can think of is the ADC pins, you may want to save these for sensors, but they will still work for serial.

Pin 5
Common, ground, zero rail...
This must be connected to both devices for any serial to work.

Pin 2
Data is sent to the PC via this pin. PIC® -->> PC

Pin 3
Data is sent to the PIC® via this pin. PIC® <<-- PC

LEDave
- 9th April 2010, 23:10
Hi mackrackit,

I'm using a PIC12F683 on my PICKit1.

I've got common pin5 on the DB9 cable (yellow) going to VSS PIC pin8.

I've got pin3 on the DB9 cable (red) going to GPIO.0 PIC pin7.

And pin2 on the DB9 cable (brown) going to GPIO.2 PIC pin5.

All via header J3.

How does that sound?

Dave

mackrackit
- 9th April 2010, 23:24
Sounds like it should work.
Is there any analog on those pins? No problem, just turn it off and give it a go.

Maybe you already know it, MCS has a nice terminal program built in.

LEDave
- 9th April 2010, 23:38
Yes there is analog AN0/1/2

So turn the ANSEL & CMCON0 off.


MCS has a nice terminal program built in.

Is this Microsoft Hyperterminal?

mackrackit
- 10th April 2010, 00:55
Yup, turn them off

Not hyperterminal. MCS - View - Serial communicator.

LEDave
- 10th April 2010, 01:02
Mmm

I've got a headache.

So we've got one transmit and one receive line to and from the PIC set up.So do I write a program so that when data from the pc arrives (if it ever does:eek:) at GPIO.0 an led toggles.

Would that be a good starting point?

Dave

mackrackit
- 10th April 2010, 01:54
You have a headache... I am stuck in an "art gallery" for the next few hours.

Yes, pick a baud say of 2400 , can not remember the mode number.

SERIN2 PIN, BAUD,[MYVAR]
IF MYVAR = ??? THEN

Something like that....
I will be back atthe shop later.

LEDave
- 10th April 2010, 15:06
I am stuck in an "art gallery" for the next few hours.

Strange places 'art galleries' me and my wife visited one years ago and the man from behind the counter came over and said "Would you model for me" to which my wife said (after a pause I might add) " No I couldn't " to which he said " I wasn't talking to you! " And no I didn't either by the way.;)

Is this anywhere near where I should be heading?


MYVAR VAR BYTE

serin2 GPIO.0, 2400,["MYVAR = ", BIN MYVAR, 10]

IF MYVAR = %00001010 THEN HIGH GPIO.5


Also, the Port (com1) settings are: 9600 bps 8N1. Do I need to change that to 2400?

Dave

LEDave
- 10th April 2010, 15:52
I've been looking for 'Serial Communicator' in MicroCode_Studio and all I can find is this:


The Serial Communicator enables you to connect to and monitor a serial port. For more information, see the online help provided with the Serial Communicator software.


I've also been to the MCS website, still no luck.

Dave

mackrackit
- 10th April 2010, 16:02
Lets say you are sending "3" from the PC


MYVAR VAR BYTE

serin2 GPIO.0, 2400,[DEC MYVAR]

IF MYVAR = 3 THEN HIGH GPIO.5



Also, the Port (com1) settings are: 9600 bps 8N1. Do I need to change that to 2400?You will do that in the terminal program.