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.

Problem with c programming in PIC18f4520...

Status
Not open for further replies.

mohideen

Member level 2
Joined
Jan 19, 2011
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,580
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 0:pORTC=0b11000000;break;// display 0
case 1:pORTC=0b11111001;break;// display 1
case 2:pORTC=0b10100100;break;// display 2
case 3:pORTC=0b10110000;break;// display 3
case 4:pORTC=0b10011001;break;// display 4
case 5:pORTC=0b10010010;break;// display 5
case 6:pORTC=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....
 

try setting the switch ON before powering up the system. If you switch ON after a while powering up the system, the program may be couldn't be out of the display count loop.
 

Oh i'll try it as soon as possible...
Is there any problem with my program...
Anyhting that i can do which can counter my problem?
 

the code seems OK. another thing you may use; instead of if statement, you can make an interrupt routine to the switch ON. I mean you can make the switching ON an interrupt to the microcontroller.
 

Thanks hansmuller,
But i kinda dont understand the interrupt routine
Can i have an example for the interrupt routine...
Thanks
 

interrupt means; when pic is running its main code, when an interrupt happens, pic breaks its current work and immediately runs the interrupt routine. interrupt is programmed outside the main code. you can see many examples and definition on internet. also datasheet of pic will help you.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top