Continue to Site

Welcome to our site!

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

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

PK2 and 16F690 Question

Status
Not open for further replies.

dieplz

New Member
Ok, I have the following code, and it is not making the controller behave as I would expect.

The code should turn on pin RC0, then after a delay, turn on RC1, then after another delay, turn off RC1, and once again, after another delay, turn off RC0. Finally, after another delay, it should start the loop again.

void main(void)
{
TRISC = 0;
while(1)
{
RC0 = 1;
DelayMs(1000);
RC1 = 1;
DelayMs(1000);
RC1 = 0;
DelayMs(1000);
RC0 = 0;
DelayMs(1500);
}
}

What is happening is RC0 is going high, turning on an LED on my PK2, then RC1 is going high, turning on a different LED, but at the same time, RC0 goes low again, turning the LED off. Basically, the code works as it should, but it only allows one output high at a time.

At first I felt that the PK2 just didnt have enough current to drive both led's at once, but then I remembered that in the demo, it was able to do just that.

Is there something that I am missing in order to get more than one output high at a time? I'm sorry if this is a newb question, but I did a few searches and came up with nothing, and am new to programming PIC's, but not new to programming at all.

Thanks!
 
If you could peek at the assembly code (or disassembly in the debugger) it might tell you a lot.
 
dieplz said:
What is happening is RC0 is going high, turning on an LED on my PK2, then RC1 is going high, turning on a different LED, but at the same time, RC0 goes low again, turning the LED off. Basically, the code works as it should, but it only allows one output high at a time.

At first I felt that the PK2 just didnt have enough current to drive both led's at once, but then I remembered that in the demo, it was able to do just that.

Is there something that I am missing in order to get more than one output high at a time? I'm sorry if this is a newb question, but I did a few searches and came up with nothing, and am new to programming PIC's, but not new to programming at all.

Thanks!
Disable analog functions, clearing the ANSEL register.

Code:
void main(void)
{
    ANSEL = 0;
    TRISC = 0;
    while(1)
    {
        RC0 = 1;
        DelayMs(1000);
        RC1 = 1;
        DelayMs(1000);
        RC1 = 0;
        DelayMs(1000);
        RC0 = 0;
        DelayMs(1500);
     }
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top