Author Topic: EasyPIC-6 Development Board by MikroElectronica - Take"2"  (Read 49635 times)

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #25 on: November 13, 2010, 08:11:54 AM »
I started to drown very quickly when I was trying to setup the PIC, I suppose that is why I`m suggesting use the examples.

Like Kwackers said try an LED code.

Load up the LED curtain MikroC example and then you know that all the setup is correct to allow the LEDs to come on (i.e outputs set)

Then go down to the main code - delete it all and type in something like:

void main ()      // <-- this should already be in the example code
{
while (1)     // Loops the code because 1 is always true so keep cycling through it!
{
PORTC.b1 = 1;    // turns on PORTC  bit 1 = so the LED should come on
delay_ms (1000);   // delay a second
PORTC.b1 = 0;     // the LED will go off
}
}

I think that should work...??

Then like Kwackers said, try and get two to flash and that sort of stuff. Then I tried to make 1 of 6 flash at random so that I had a dice ... etc

Chris

Then you should have a flashing LED!!

Offline kwackers

  • Sr. Member
  • ****
  • Posts: 356
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #26 on: November 13, 2010, 08:44:25 AM »
Sorry Chris, there's a bug in it...

you turn the led on,
wait one second
turn the led off
go back to the beginning.

See the problem?
The time take to go back to the beginning is in the order of a microsecond so the led won't be off for very long...

You can either add an extra 'off' delay after turning it off,
or
if you're happy with the on and off times being equal simply 'invert' the state of the bit
eg
Code: [Select]
while (1)
{
    PORTC.b1 = !PORTC.b1;  // ! means 'not' i.e inverts the bit
    delay_ms(1000);
}

(shorter too)
« Last Edit: November 13, 2010, 08:49:09 AM by kwackers »

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #27 on: November 13, 2010, 09:16:38 AM »
Yep...see that now :D

Which is why the EasyPIC is so good - me being a numpty would have loaded that to the PIC and then found it didn`t work! :D

void main ()      // <-- this should already be in the example code
{
while (1)     // Loops the code because 1 is always true so keep cycling through it!
{
PORTC.b1 = 1;    // turns on PORTC  bit 1 = so the LED should come on
delay_ms (1000);   // delay a second
PORTC.b1 = 0;     // the LED will go off
delay_ms(1000) // EDIT !!! EXTRA DELAY ADDED!
}
}

Offline j45on

  • Sr. Member
  • ****
  • Posts: 380
  • My tiny workshop Location Ashford Kent
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #28 on: November 13, 2010, 09:35:49 AM »
Chris you think you are a numpty I managed to order completely the wrong book I ordered programming microcontrolers in assembly instead of C  :lol: that makes me a propper numpty  :doh:
I shall try your bit of code later
Jason

Offline j45on

  • Sr. Member
  • ****
  • Posts: 380
  • My tiny workshop Location Ashford Kent
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #29 on: November 13, 2010, 02:10:07 PM »
I think I have broke it  :scratch:
I plugged in the board and switched it on and it was running the led curtain code from the library
I started a new project and copy n pasted the code above in and hit the build and program button
now I have nothing so I tried programing the curtain code nothing again so I tried the led blink and the 2x16 lcd one nothing works now
I have not changed any jumpers or switches since I bought it
The power,usb and pgr/icd leds sugest something is going on
I have tried it with and without the lcd,reset it removed and replaced the pic and still nothing  :zap: what have I done ?
Jason

Offline kwackers

  • Sr. Member
  • ****
  • Posts: 356
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #30 on: November 13, 2010, 02:18:05 PM »
Unlikely you've broken it.

Make sure when you program it that there are no error messages, then check the code has 'taken' using the verify option.
Make sure you haven't inadvertently flipped any of the dip switches, make sure the crystal is in place etc.

Presumably you're powering it from the USB?

Offline j45on

  • Sr. Member
  • ****
  • Posts: 380
  • My tiny workshop Location Ashford Kent
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #31 on: November 13, 2010, 02:36:57 PM »
Phew got it working again seams to have been when I started a new project I have now managed to get the led curtain code working again  :ddb:
I cant get craynerds bit of code to do anything if I delete the code on screen and paste in his it compiles with no errors but wont do anything on the easypic.
I am using usb should I not ?
Jason

Offline kwackers

  • Sr. Member
  • ****
  • Posts: 356
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #32 on: November 13, 2010, 03:05:31 PM »
Shouldn't need much, there was no direction set in Chris's code - try this.

Code: [Select]
void main()
{
  TRISC = 0x00;          // set direction to be output
 
  while (1)
 {
    PORTC.b1 = 0;        // Turn OFF LED 1 on PORTC
    Delay_ms(1000);      // 1 second delay

    PORTC.b1 = 1;        // Turn ON LED 1 on PORTC
    Delay_ms(1000);      // 1 second delay
  }
}

Offline j45on

  • Sr. Member
  • ****
  • Posts: 380
  • My tiny workshop Location Ashford Kent
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #33 on: November 13, 2010, 03:19:02 PM »
 :nrocks: thanks that works
why are RC0 and RC2 led's iluminated there is nothing in the code  :scratch:
Jason

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #34 on: November 13, 2010, 04:16:47 PM »
:nrocks: thanks that works
why are RC0 and RC2 led's iluminated there is nothing in the code  :scratch:

Have a shufti at the .pdf data sheet, PortC pin functions for the uC you are using.

Most port pins have several uses, in fact I think they all do, apart from Xtal Osc pins ...

Could be something like an 'OSCOUT' or the like ... depends on the Config set-up...

Happens to me all the time ...  :loco:

WTF is it doing NOW???    , is my favourite mantra ..

Dave BC
I have a few modest talents. Knowing what I'm doing isn't one of them.

Offline j45on

  • Sr. Member
  • ****
  • Posts: 380
  • My tiny workshop Location Ashford Kent
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #35 on: November 13, 2010, 04:27:47 PM »
WTF is it doing NOW???

strangley I have said that a lot tonight as well  :lol:

This is about the most constructive thing I have managed to do
Jason

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #36 on: November 13, 2010, 04:33:24 PM »
Jason

Which PIC is it ??

Assume it is a PIC ..

Dave BC
I have a few modest talents. Knowing what I'm doing isn't one of them.

Offline kwackers

  • Sr. Member
  • ****
  • Posts: 356
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #37 on: November 13, 2010, 05:11:42 PM »
If you want to be really clever, connect your stepper drivers 'clock' input to b1 of portC.
Your stepper motor will now step 1 step each second.

By changing the value in the delay you can change how fast it steps (reducing it will make it step faster).

Then by using a counter to only do it so many times you've essentially got a simple divider!

e.g.

Code: [Select]
void main()
{
  int count;                // variable we'll use to count

  TRISC = 0x00;          // set direction to be output

 for (count = 0; count < 400; count++)  // step 400 times
 {
    PORTC.b1 = 1;        // Turn ON clock pulse
    PORTC.b1 = 0;        // Turn OFF clock pulse

    Delay_ms(10);      // 10 mS delay (about 100hz)
  }
}

Notice there isn't a delay between turning on the clock pulse and turning it off - this is because it only needs to be high for a tiny amount of time in order to be recognised by the driver.

Offline j45on

  • Sr. Member
  • ****
  • Posts: 380
  • My tiny workshop Location Ashford Kent
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #38 on: November 13, 2010, 05:12:51 PM »
It is the pic that came with the easypic 6 KIT

PIC16F887-I/P
Jason

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #39 on: November 13, 2010, 05:42:34 PM »
Ah! got 2 of them ...

Just looked at the data sheet for PortC, P58 is interesting.

All sorts of magic stuff on RC0, RC2.

You might check the bits set in the registers on that table.

Any one ending in xxxxxCON could be be incompatible with what you're doing.

It may be configged for Osc out, Comparator out  or PWM.

Just a thought ... could well be nowt relevant in there.

Dave BC
I have a few modest talents. Knowing what I'm doing isn't one of them.

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #40 on: November 14, 2010, 04:20:43 AM »
Jason...

Sorry, my fault again. I just sent those instructions and little bit of code in my head. I forgot they set the direction of the ports in void main ()

One thing that mucked me up for hours and hours was that when you open a new code for example from the MikroC examples, you need to go File --> open --> Change - File Type  to MikroC PROJECT !!   If you open just the C file it won`t build.


Code: [Select]
void main() {

  [color=red]ANSEL  = 0;                                    // Configure AN pins as digital
  ANSELH = 0;
  C1ON_bit = 0;                                  // Disable comparators
  C2ON_bit = 0;
  
  TRISA = 0x00;                                  // set direction to be output
  TRISB = 0x00;                                  // set direction to be output
  TRISC = 0x00;                                  // set direction to be output
  TRISD = 0x00;                                  // set direction to be output

  PORTA = 0x00;                                  // turn OFF the PORTD leds
  PORTB = 0x00;                                  // turn OFF the PORTD leds
  PORTC = 0x00;                                  // turn OFF the PORTC leds
  PORTD = 0x00;                                  // turn OFF the PORTD leds[/color]

 while (1) {
    for (counter = 0; counter < 8; counter++){
      PORTA |= 1 << counter;
      PORTB |= 1 << counter;
      PORTC |= 1 << counter;
      PORTD |= 1 << counter;
 
      wait();
    }
      
    counter = 0;
    while (counter < 8) {
      PORTA &= ~(1 << counter);
      PORTB &= ~(1 << counter);
      PORTC &= ~(1 << counter);
      PORTD &= ~(1 << counter);
      wait();
      counter++;
    }
  }

Yea, sorry I`ve just pulled up the example code for the LED curtain above. All the stuff in red is the PIC setup so my intention was for you to keep that in, I forgot that was in main so you deleted it.

How about trying this as a bit of an extension. I don`t know the correct explanation, one of the others will explain in more detail but this always blew me away because it makes it feel like your code is less computer like and more English!

Go right to the VERY TOP line of the code (it makes it simple if we put it here) and write:

Code: [Select]
#define LED1 PORTC.b0
#define LED2 PORTC.b1


Now PORTC.b0 and b1 can be called (defined) as LED1 and LED2 in the code!

Code: [Select]
while (1)
{
LED1 = 1;
LED2 = 0;
delay_ms(1000);
LED2 = 1;
LED1 = 0;
delay_ms(1000);
}    

Think that should work OK...the point is, rather than talking about PORTC.b1 your now talking about Button 1 or LED1 or MotorX in the code. OK, only a simple text substitution, but it impresses me!

« Last Edit: November 14, 2010, 07:53:53 AM by craynerd »

Offline DMIOM

  • Hero Member
  • *****
  • Posts: 676
  • Country: gb
  • Isle of Man
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #41 on: November 14, 2010, 07:06:00 AM »
I think I have broke it  :scratch: .....

Jason, glad that you're now sorted.

I don't use the MikroElectronica boards or IDE, but a more general PIC-related "gothcha" are the fuses - these are outside your actual program but they configure various features of the PIC.

One that can be a show-stopper, and give symptoms just like you had experienced, is the setting that tells the PIC which clock source - can be an external xtal, an actual external oscillator, a ceramic resonator, an external RC network or maybe an internal oscillator.  Despite having a perfect program, if that fuse wrongly set, then absolutely nothing will happen as there'll be no ticks ... 

Another fuse gotcha is if you inadvertently enable the watchdog timer ("WDT").  The WDT is a safety feature designed to catch programs that get stuck in an un-expected loop - you have to tickle it periodically to let it know you're still alive (the WDT acts just like the dead-man's handle in a loco cab).  If you find your program starts OK and then keeps re-starting its always worth checking if you have an un-expected WDT active. 

Last fuse to pay attention to (as it can cost £$) are the code protection fuse(s). DON'T set this unless you really mean to!  If, like us, you manufacture and sell kit which uses embedded PICs, and the code is your intellectual property, you want to prevent un-scrupulous potential competitors cloning your kit, then when all is fully debugged, the production PICs are programemd with the CP fuse set - this stops anyone reading them and can also have the side-effect of preventing you from re-programming them yourself.

Dave

Offline j45on

  • Sr. Member
  • ****
  • Posts: 380
  • My tiny workshop Location Ashford Kent
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #42 on: November 15, 2010, 07:41:53 AM »
Cheers guys  :thumbup: I shall have a play tonight.
Call of duty black ops took over my weekend  ::)
Jason

Offline kwackers

  • Sr. Member
  • ****
  • Posts: 356
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #43 on: November 15, 2010, 09:17:04 AM »
Could have got you that cheap  :wave:

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #44 on: November 15, 2010, 10:29:16 AM »
Call of duty black ops took over my weekend 

 :doh: :bang:

Offline j45on

  • Sr. Member
  • ****
  • Posts: 380
  • My tiny workshop Location Ashford Kent
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #45 on: November 15, 2010, 03:11:34 PM »
Thanks Chris
that works a treat it certainly helps simplify things a bit  :beer:
I now have a flashing letter J made from led's on my board  :ddb:
« Last Edit: November 15, 2010, 03:32:24 PM by j45on »
Jason

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #46 on: November 15, 2010, 03:42:22 PM »
Have you tried using variables yet?

Code: [Select]
int count = 0;
 
while (1)
{

count = count + 1       // adds 1 to the variable count

if (count >= 500)        // CHANGE the number Count is counting to!
{
count = 0;                 // when it does get to this number it`ll go back to zero
PORTC = ~PORTC;      // ...and flip PORTC either on or off.
}
}

See if that works - again, not got my EasyPIC board with me! I`m sure "~" flips the value from 1 to 0 or vice versa.

EDIT - by the way, the whole point of that is that your getting a delay using a variable and counting. Suprisingly useful!

EDIT 2 - have you used inputs yet?
« Last Edit: November 15, 2010, 03:44:43 PM by craynerd »

Offline j45on

  • Sr. Member
  • ****
  • Posts: 380
  • My tiny workshop Location Ashford Kent
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #47 on: November 15, 2010, 04:02:14 PM »
No I have not tried any of that yet I have only fiddled with the examples so far and the last bit of code you posted.  :thumbup:
I was hoping to have the book I ordered this weekend gone but I ordered the wrong one  :doh:
And I have been reading a book on C but it's aimed at computer programming and not microcontrolers.
There seams to be a lack of really basic beginners tutorials on the net for stuff like this
Jason

Offline kwackers

  • Sr. Member
  • ****
  • Posts: 356
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #48 on: November 15, 2010, 04:09:40 PM »
Books on assembler aren't really a dead loss since they'll allow you to get a feel for the hardware.

The most complex thing with PIC's is the hardware. Each pin on a PIC is multifunction, it may have an analog to digital converter, RS232, CAN, USB, SPI or a whole host of functionality as well as its ability to operate as a standard digital input or output.
Each of these requires that the mode the pin is operating in can be setup, and each mode requires registers set up to tell it how to behave.

That's why the examples can be useful to base your stuff on, find one that uses similar hardware to you and simply modify the code inside main after the hardware has been set.

Once you get the hang of the hardware then the programming is just standard C - it doesn't need to be PIC specific (although Mikro C does have some of it's own 'extensions' along with appropriate libraries for the hardware.

What all this means is you can use the assembler book to try and understand the hardware, but any C programming tutorial to understand the C language.

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: EasyPIC-6 Development Board by MikroElectronica - Take"2"
« Reply #49 on: November 15, 2010, 05:48:33 PM »
I got 'Designing Embedded Systems with PIC uControllers' from Amazon some weeks ago. Lots of example code for asm. and C18.

Starts pretty much from Sq. 1

Found it very helpful.

About £22 ish

Nice thick heavy  book. ( Also good for the flattening the spine of books on the scanner ....  :thumbup: )

Would like to find one with some stuff for Hi-Tech C, but not much luck.

C18 don't do 16Fxx chips. Which is a bit of a bummer, 'cos I was given quite a number ...  :scratch:

Dave BC

I have a few modest talents. Knowing what I'm doing isn't one of them.