filjoa
Joined: 04 May 2008 Posts: 260
|
Interrupts problem |
Posted: Fri Nov 07, 2008 7:52 am |
|
|
Hi
I try make one project for controller part of car alarm, but stay with some problems because need use interrupts but I dont know how
this program work:
1º-wait for ignition from the car, after start program
2º-after ignition ON, need in "x"(distance from ABS) impulses which "sens" stay TRUE.
3º-if sens=TRUE, stay all ok and car run normally, if sens=FALSE it jump for function stop();
4º-in function stop() it start cut for 1 second injection after wait 20 seconds for driver put sens=TRUE and repeat this 3 times. After this 3 times sens continue FALSE go to function off(); and stop car.
5º- in function run(); it wait for doors open or ignition off, if some of them happen, it restart program (I don't know how).
This is my program and problem stay in comment:
Quote: |
#include <18F252.h>
#fuses EC_IO,NOWDT,NOPROTECT,NOLVP
#use delay(clock=40000000)
#use rs232(baud=115200, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8)
#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
nop
#endasm
} // Reserve space for the bootloader
//###### IN PORTS ######
#define DOOR PIN_B7
#define BREAK PIN_B6
#define RFID PIN_B5
#define ABS PIN_B4
#define IGN PIN_B3
//###### OUT PORTS ######
#define RED PIN_C4
#define GREEN PIN_C5
#define R1 PIN_C0
#define R2 PIN_C1
#define R3 PIN_C2
#define R4 PIN_C3
void run()
{
int8 doors, ignition;
doors=0;
ignition=0;
do
{
doors=input(DOOR);
ignition=input(IGN);
}while(doors!=0 || ignition!=0);
//restart program
}
void off()
{
output_high(R2);
}
void stop()
{
output_high(R1);
delay_ms(1000);
//wait 20seconds for sens=input(ING) is TRUE
output_high(R1);
delay_ms(1000);
//wait 20seconds for sens=input(ING) is TRUE
output_high(R1);
delay_ms(1000);
//wait 20seconds for sens=input(ING) is TRUE
off();
}
void main ()
{
int8 start,sens,wait;
start=0;
sens=0;
wait=0;
while(1)
{
do
{
start=input(IGN);
}while(start!=0);
do
{
sens=input(RFID);
wait=wait++; //or wait 40000000 impulses from input wave
}while((sens!=0 && wait!=40000000) || wait!=40000000);
if (sens==1) run();
else stop();
}
}
|
variables "wait" and "sens=input(ING)" need work with an interrupts correct?
some one can help me?
kind regards, Filipe Abrantes |
|