stuckkk
Newbie level 6
- Joined
- Dec 18, 2012
- Messages
- 13
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,383
Hi,
I am having problem simulating the following program using PIC simulator IDE. Appreciate if someone could point out the errors in this prog.
Below is the coding
The program get stuck in the first 'for' loop. I have tried several ways but still in my simulator(PIC simulator IDE) it continues blinking. I was thinking it should blink 10 times and stop according to the loop, but it does not come out of the loop.
And, after that how can I make switch-case part to be looped until the PORTA bit 7 is pressed for the second time which switches off all LEDs. I mean after each case is executed back to the start of the switch, so another case can be selected.
I havent written the functions I am calling for in this program as I suppose they are irrelevant to the errors I am having.
Thanks.
I am having problem simulating the following program using PIC simulator IDE. Appreciate if someone could point out the errors in this prog.
Below is the coding
Code:
#include<htc.h>
unsigned char inbyte=0, input=0;
unsigned int counter=0;
void config ();
void function ();
void function_1 ();
void delay (int k);
void main()
{
while(1)
{
config ();
inbyte=PORTA;
if (inbyte = inbyte & 0x80) //read PORTA bit7
{
counter=!counter;
while (counter==1)
{
for (int a=0; a<10; a++) //the program get stuck in this loop
{
PORTB= PORTB | 0x40;
delay (1000);
PORTB= PORTB & 0xBF;
delay (1000);
}
input=PORTA; //read PORTA again
switch(input)
{
case 0x01:
function ();
function_1 ();
PORTB= PORTB | 0x01;
break;
case 0x02:
function ();
function_1 ();
PORTB= PORTB | 0x02;
break;
case 0x04:
function ();
function_1 ();
PORTB= PORTB | 0x04;
break;
case 0x08:
function ();
function_1 ();
PORTB= PORTB | 0x08;
break;
case 0x10:
function ();
function_1 ();
PORTB= PORTB | 0x10;
break;
}
}
while (counter==0) //if PORTA bit7 is pressed again, off all LEDs
{
PORTB=0x00;
}
}
}
}
void config ()
{
CMCON=0x07;
TRISA=0xFF;
TRISB=0x00;
}
void delay (int k)
{
for (int i=0; i<k; i++);
}
The program get stuck in the first 'for' loop. I have tried several ways but still in my simulator(PIC simulator IDE) it continues blinking. I was thinking it should blink 10 times and stop according to the loop, but it does not come out of the loop.
And, after that how can I make switch-case part to be looped until the PORTA bit 7 is pressed for the second time which switches off all LEDs. I mean after each case is executed back to the start of the switch, so another case can be selected.
I havent written the functions I am calling for in this program as I suppose they are irrelevant to the errors I am having.
Thanks.