Software interrupt for Polling Input pin PIC16F628A? any soft interrupt example ?

Status
Not open for further replies.

asking

Full Member level 5
Joined
Sep 21, 2010
Messages
279
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Activity points
3,377
Hi,

I am trying to make some counter based on the input (logic 1, 5v) signal. when the Proximity will sense the object pass by it will give output 1 (logic 5v) for the time it detects object. Then it will be 0 again. So i am trying to write one simple program to increment counter, but i am facing some issues.


1) Counter should not increment continuously @ MIPS rate. (i really don't how to use Software interrupt.) (it should count 1 by 1)

2) i have made little program for just testing but i am unable to use software interrupt. is this correct way to keep my code in Main {} or i should use it in While(1) loop for continous monitoring ?

3) can i use Void Interrupt () { ISR } for this ? or it should be only use with hardware interrupt like RB0/INT, TMR0IF etc..


Code:
if (PORTA.F1 == 1)
{
VAR1 = 1;
}

If (VAR1 == 1 && PORTA.F1 == 1)
{
COUNT = COUNT + 1;
VAR1 = 0;
}



OR

Code:
 void Interrupt()
 {
 if (PORTA.F1 == 1)
{
VAR1 = 1;
}

if (VAR1 == 1 && PORTA.F1 == 1)
{
COUNT = COUNT + 1;
VAR1 = 0;
}
 }

Code:
short int COUNT = 0, VAR1 = 0, VAR2 = 0;

void main()
{
CMCON = 7;
TRISA = 0b00000001;
TRISB = 0b00000000;
OPTION_REG.F7 = 0;
PWM1_Init(38000);
PWM1_Set_duty(150);
PWM1_Start();

if (PORTA.F1 == 1)
{
VAR1 = 1;
}

If (VAR1 == 1 && PORTA.F1 == 1)
{
COUNT = COUNT + 1;
VAR1 = 0;
}

while (1)
{
// should i use polling here or in main loop ? please explain i am confused between void main() and while(1).......
}


Please throw some light on software interrupts. Please provide some software interrupt based some examples.

Thanks
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…