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.

count up and count down

Status
Not open for further replies.

crys

New Member
in my program i can seem to count it up! how can make it go to if(PORTB=0x01)??

i using PIC16f877a
**broken link removed**


#include<pic.h>
int decode[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x00,0x98};

void timer(void);

main()
{
TRISB=0x01;
TRISC=0x00;
PORTC=decode[0];
OPTION=0x07;
TMR0IE=1;
GIE=1;
timer();
}

void timer(void)
{
TMR0=0xD9;
while(1);
}

void interrupt blink(void)
{
static int multiply=0, x=0;
GIE=0;
multiply++;
if(TMR0IF==1)
{
TMR0IF=0;
if(multiply==10)
{

if(PORTB==0x01)
{
x++;
if(x==10)
{
x=0;
}
PORTC=decode[x];
multiply=0;
}
else
{
x--;
if(x==-1)
{
x=9;
}
PORTC=decode[x];
multiply=0;
}
}

}
GIE=1;
timer();
}
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top