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.
 
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.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…