Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

somebody help me on PIC16F877

Status
Not open for further replies.

sidang

Newbie level 5
Newbie level 5
Joined
Aug 25, 2007
Messages
8
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Location
GB
Activity points
1,345
hello everyone..i have a problem on my project.. My project is a digital clock with multi mode timer (3 different time of alarm)..Hope someone could help me..the problem is

i donno how to switch off / reset the LED during the alarm time..in other word: the LED will be on for 2 minute and i need to switch off the LED during that time..

this my code..

int S1, S2, c1, c2, c3, c4, c5, c6, a3, a4, a5, a6, e3, e4, e5, e6, m3, m4, m5, m6 ;
int i;

void main ()

{
PORTA=0;
PORTB=0;
PORTC=0;
TRISA=0;PORTA=0;
TRISB=0;
TRISC=0;
TRISD=255;
PORTD=0;

c1=0; c2=0; c3=0; c4=0; c5=0; c6=0;
a3=0; a4=1; a5=0; a6=0;
e3=0; e4=2; e5=0; e6=0;
m3=0; m4=3; m5=0; m6=0;

restart:
if (PORTD.F0==0 && PORTD.F1==1 && PORTD.F7==1 && PORTD.F6==1)
{

PORTB=c3+c4*16;
PORTC=c5+c6*16;

if (PORTD.F2==0 && PORTD.F3==1) {c3++;

if (c3==10)
{ c3=0;
c4=c4+1;
}

if (c4==6)
{c4=0;
c5=c5+1;
}

if (c5==10)
{c5=0;
c6=c6+1;
}

if (c6==2 && c5==4)
{c6=0;
c5=0;
}

Delay_ms(500);}

if (PORTD.F3==0 && PORTD.F2==1) {c5++;
//if (PORTD.F3==0 && PORTD.F2==0){c5++; c3++;}


if (c3==10)
{ c3=0;
c4=c4+1;
}

if (c4==6)
{c4=0;
c5=c5+1;
}

if (c5==10)
{c5=0;
c6=c6+1;
}

if (c6==2 && c5==4)
{c6=0;
c5=0;
}

Delay_ms(500);}
goto restart;
}

else if(PORTD.F0==1 && PORTD.F1==0 && PORTD.F7==1 && PORTD.F6==1)
{

PORTB=a3+a4*16;
PORTC=a5+a6*16;

if (PORTD.F2==0 && PORTD.F3==1) {a3++;

if (a3==10)
{ a3=0;
a4=a4+1;
}

if (a4==6)
{a4=0;
a5=a5+1;
}

if (a5==10)
{a5=0;
a6=a6+1;
}

if (a6==2 && a5==4)
{a6=0;
a5=0;
}

Delay_ms(500);}

if (PORTD.F3==0 && PORTD.F2==1) {a5++;
//if (PORTD.F3==0 && PORTD.F2==0){a5++; a3++;}


if (a3==10)
{ a3=0;
a4=a4+1;
}

if (a4==6)
{a4=0;
a5=a5+1;
}

if (a5==10)
{a5=0;
a6=a6+1;
}

if (a6==2 && a5==4)
{a6=0;
a5=0;
}

Delay_ms(500); }


goto restart;
}
else if(PORTD.F0==1 && PORTD.F1==1 && PORTD.F7==0 && PORTD.F6==1)
{

PORTB=e3+e4*16;
PORTC=e5+e6*16;

if (PORTD.F2==0 && PORTD.F3==1) {e3++;

if (e3==10)
{ e3=0;
e4=e4+1;
}

if (e4==6)
{e4=0;
e5=e5+1;
}

if (e5==10)
{e5=0;
e6=e6+1;
}

if (e6==2 && e5==4)
{e6=0;
e5=0;
}

Delay_ms(500);}

if (PORTD.F3==0 && PORTD.F2==1) {e5++;
//if (PORTD.F3==0 && PORTD.F2==0){e5++; e3++;}


if (e3==10)
{ e3=0;
e4=e4+1;
}

if (e4==6)
{e4=0;
e5=e5+1;
}

if (e5==10)
{e5=0;
e6=e6+1;
}

if (e6==2 && e5==4)
{e6=0;
e5=0;
}

Delay_ms(500); }


goto restart;
}

else if(PORTD.F0==1 && PORTD.F1==1 && PORTD.F7==1 && PORTD.F6==0)
{

PORTB=m3+m4*16;
PORTC=m5+m6*16;

if (PORTD.F2==0 && PORTD.F3==1) {m3++;

if (m3==10)
{ m3=0;
m4=m4+1;
}

if (m4==6)
{m4=0;
m5=m5+1;
}

if (m5==10)
{m5=0;
e6=e6+1;
}

if (m6==2 && m5==4)
{m6=0;
m5=0;
}

Delay_ms(500);}

if (PORTD.F3==0 && PORTD.F2==1) {m5++;
//if (PORTD.F3==0 && PORTD.F2==0){e5++; e3++;}


if (m3==10)
{ m3=0;
m4=m4+1;
}

if (m4==6)
{m4=0;
m5=m5+1;
}

if (m5==10)
{m5=0;
m6=m6+1;
}

if (m6==2 && m5==4)
{m6=0;
m5=0;
}

Delay_ms(500); }


goto restart;
}

else if ((PORTD.F0==0 && PORTD.F1==0 && PORTD.F7==0 && PORTD.F6==0 ) || (PORTD.F0==1 && PORTD.F1==1 && PORTD.F7==1 && PORTD.F6==1))
{
PORTA.F0 = 1;
c1++;
PORTB=c3+c4*16;
PORTC=c5+c6*16;
if (c1==10)
{c1=0;
c2=c2+1;
}

if (c2==6)
{c2=0;
c3=c3+1;
}

if (c3==10)
{c3=0;
c4=c4+1;

}

if (c4==6)
{c4=0;
c5=c5+1;
}

if (c5==10)
{c5=0;
c6=c6+=1;
}

if (c6==2 && c5==4)
{c6=0;
c5=0;
}

Delay_ms(7);
PORTA.F0 = 0;
Delay_ms(7);
}


if ((c3==a3+1 && c4==a4 && c5==a5 && c6==a6 ))

{
porta.f1=1;
delay_ms(5000);
c3=c3+1;
}



if ((c3==e3+1 && c4==e4 && c5==e5 && c6==e6 ))

{
porta.f2=1;
delay_ms(5000);



c3=c3+1;
}

if ((c3==m3+1 && c4==m4 && c5==m5 && c6==m6 ))

{
porta.f3=1;
delay_ms(5000);



c3=c3+1;
}





goto restart;




}




please help me..thanks..
 

Hi,
To switch on/off any output pin, try this.....

output_high(PIN_A0); // port_a0 will be switched to high

output_low(PIN_A0); // port_a0 will be switched to low

hope this will do.

ZS1BFE Cape Town -- S.A.
 

    sidang

    Points: 2
    Helpful Answer Positive Rating
Hi,
I presume that your code is a working code and that you are only looking for blanking out the LEDs during alarm conditions. This can be done by logically disabling the common anode/cathode drivers during alarm period using an unused port bit say port A.f7. Alternatively, you can load Port B and Port C with 0XFF during the alarm period and load the values of C3 to C6 after the alarm.

From your code it appears that you are outputting alarm on port bits A.f1 to A.f3, but you do not seem to be clearing those bits? Also why there is a long delay of 5secs.? Are you getting the basic 1sec, ticks with timer interrupt, since that portion is not clear in the code. Any how these are not important to me, I only asked these questions out of curiosity.

Regards,
Laktronics
 

    sidang

    Points: 2
    Helpful Answer Positive Rating
hai..thank you so much for you help..but can u explain to me what do you mean by "but you do not seem to be clearing those bits?"..what does it means clearing those bit..

thanks again
 

Hi,
I have been referring to the code sets similar to the following:

if ((c3==a3+1 && c4==a4 && c5==a5 && c6==a6 ))

{
porta.f1=1;
delay_ms(5000);
c3=c3+1;
}

I have assumed that the statement ' porta.f1=1;' is where you are turning on the alarm. But if it is so, I do not see anywhere the bit getting turned off. Again it is not clear how you are getting one second clock to increment location C1. That is why I asked you whether your code is a working code.

Also, as regards switching off the display during the alarm period is concerned, you may have to load 0XFF or 0X00 into Port B/C depending upon whether you are using a Common Anode or Common Cathode type of display.

Regards,
Laktronics
 

    sidang

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top