The Shop > Electronics & IC Programing
EasyPIC-6 Development Board by MikroElectronica - Take"2"
raynerd:
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: ---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++;
}
}
--- End code ---
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: ---#define LED1 PORTC.b0
#define LED2 PORTC.b1
--- End code ---
Now PORTC.b0 and b1 can be called (defined) as LED1 and LED2 in the code!
--- Code: ---while (1)
{
LED1 = 1;
LED2 = 0;
delay_ms(1000);
LED2 = 1;
LED1 = 0;
delay_ms(1000);
}
--- End code ---
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!
DMIOM:
--- Quote from: j45on on November 13, 2010, 02:10:07 PM --- I think I have broke it :scratch: .....
--- End quote ---
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
j45on:
Cheers guys :thumbup: I shall have a play tonight.
Call of duty black ops took over my weekend ::)
kwackers:
Could have got you that cheap :wave:
raynerd:
--- Quote from: j45on on November 15, 2010, 07:41:53 AM ---Call of duty black ops took over my weekend
--- End quote ---
:doh: :bang:
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version