mohideen
Member level 2
Hi all,
The program that i have done should ON the LED, ON the Buzzer and ON the seven segment togather when i ON the switch.
But, however the LED and the Buzzer only ON after the seven segment has finish counting.
Specifically,
1) When i switch ON,
a) The LED should blink with a delay of 1 sec.
b) The buzzer should sound a tone with a delay of 1 sec.
c) The seven segment should count up to 6 with a delay of 10 secs with each count.
This function should be togather and happen at the same.
Pls do help me troubleshoot my program.
Thanks.
This is my program.
#include <p18f4520.h>
#include <delays.h>
unsigned char i = 0; // Initialize i
int x; // Initialize counter
unsigned int count=0;// Initialize count
void main ()
{
ADCON1=0x0F;
TRISA = 0b11000000; //set RA5 as output
TRISB = 0b11011111; //set RB5 as output
TRISC = 0b10000000; //set RC0-RC6 as outputs
TRISE = 0b11111111; //set RE0 as input
while(i<60)// for 60 counts of 'i'
{
if(PORTEbits.RE0==0)// When switch is flipped ON
{
PORTA = 0b00100000;// ON LED
Delay10KTCYx(6); // with a delay of 1 sec
PORTA = PORTA<<1;
i++;
for( x=0; x <300; x++)// ON buzzer with a delay of 1 sec
{
PORTBbits.RB5 = ~PORTBbits.RB5;
Delay10TCYx(14);
}
for( x=0; x <350; x++)
{
PORTBbits.RB5 = ~PORTBbits.RB5;
Delay10TCYx(15);
}
for( x=0; x <100; x++)
{
PORTBbits.RB4 = ~PORTBbits.RB4;
Delay10TCYx(1000);
}
while (count<7)// for count lesser than 6
{
switch(count)// lookup table
{
case 0ORTC=0b11000000;break;// display 0
case 1ORTC=0b11111001;break;// display 1
case 2ORTC=0b10100100;break;// display 2
case 3ORTC=0b10110000;break;// display 3
case 4ORTC=0b10011001;break;// display 4
case 5ORTC=0b10010010;break;// display 5
case 6ORTC=0b10000011;break;// display 6
}
Delay10KTCYx(430); // delay for 5 sec
Delay10KTCYx(430); // delay for 5 sec
count++; // count keep increasing
}
}
}
}// end )
---------- Post added at 21:07 ---------- Previous post was at 19:17 ----------
Pls anyone Help...
This is abit urgent...
Thanks....
The program that i have done should ON the LED, ON the Buzzer and ON the seven segment togather when i ON the switch.
But, however the LED and the Buzzer only ON after the seven segment has finish counting.
Specifically,
1) When i switch ON,
a) The LED should blink with a delay of 1 sec.
b) The buzzer should sound a tone with a delay of 1 sec.
c) The seven segment should count up to 6 with a delay of 10 secs with each count.
This function should be togather and happen at the same.
Pls do help me troubleshoot my program.
Thanks.
This is my program.
#include <p18f4520.h>
#include <delays.h>
unsigned char i = 0; // Initialize i
int x; // Initialize counter
unsigned int count=0;// Initialize count
void main ()
{
ADCON1=0x0F;
TRISA = 0b11000000; //set RA5 as output
TRISB = 0b11011111; //set RB5 as output
TRISC = 0b10000000; //set RC0-RC6 as outputs
TRISE = 0b11111111; //set RE0 as input
while(i<60)// for 60 counts of 'i'
{
if(PORTEbits.RE0==0)// When switch is flipped ON
{
PORTA = 0b00100000;// ON LED
Delay10KTCYx(6); // with a delay of 1 sec
PORTA = PORTA<<1;
i++;
for( x=0; x <300; x++)// ON buzzer with a delay of 1 sec
{
PORTBbits.RB5 = ~PORTBbits.RB5;
Delay10TCYx(14);
}
for( x=0; x <350; x++)
{
PORTBbits.RB5 = ~PORTBbits.RB5;
Delay10TCYx(15);
}
for( x=0; x <100; x++)
{
PORTBbits.RB4 = ~PORTBbits.RB4;
Delay10TCYx(1000);
}
while (count<7)// for count lesser than 6
{
switch(count)// lookup table
{
case 0ORTC=0b11000000;break;// display 0
case 1ORTC=0b11111001;break;// display 1
case 2ORTC=0b10100100;break;// display 2
case 3ORTC=0b10110000;break;// display 3
case 4ORTC=0b10011001;break;// display 4
case 5ORTC=0b10010010;break;// display 5
case 6ORTC=0b10000011;break;// display 6
}
Delay10KTCYx(430); // delay for 5 sec
Delay10KTCYx(430); // delay for 5 sec
count++; // count keep increasing
}
}
}
}// end )
---------- Post added at 21:07 ---------- Previous post was at 19:17 ----------
Pls anyone Help...
This is abit urgent...
Thanks....