deepmak
Member level 2
- Joined
- Jun 1, 2013
- Messages
- 52
- Helped
- 13
- Reputation
- 26
- Reaction score
- 13
- Trophy points
- 1,288
- Activity points
- 1,677
Good day all,
im fairly new to micro controllers and their programming , i want to design a device that can consist of a main board connected to push button(s) (one or two in series ) , with 4 outputs for warning devices and it would be used to confirm an operator attendance in their room ,and it would operates like this :
the supervisor sets a certain period , basically 3 minutes ( or 6 or 12 ) , the operator should push the button at their desk once before the period elapse to confirm they are at their desk , should the delay pass , a visual warning will operate , pressing the button will reset the delay and the count start over
if say 15 second passed with no operator interaction , a sound warning start in the operator room , again pressing the button will reset the delay and start over.
if no interaction again , a second stage sound warning will sound at the supervisor room , having them to check the room and push the button to silent all warnings and start over
if no interaction still after the second stage alarm , a third stage sound warning will start after say 90 seconds at the staff room or other place where worker would be , and it will sound until the warning are silenced from the operator room.
i thought of attaching the push button as external interrupt to reset all warning and start the delay over , however all books or lectures i read about interrupt were mentioning that interrupt will resume the flow of the program after being served , meanwhile i need to reset the delay with every push/press.
sorry for being lengthy but is it ok for interrupts to change the flow of execution ? like having a "GOTO Start1 " statement to direct the control to the start of program ?
on the other hand , i thought of the following code with polling , could you please check it ?
Thanks in advance , i plan to add delay configuration later if this works
Edit : syntax corrected after coding in Mikroc IDE , sorry for errors (wrote code from work using notepad)
simulation works using PIC16F84A
Regards
im fairly new to micro controllers and their programming , i want to design a device that can consist of a main board connected to push button(s) (one or two in series ) , with 4 outputs for warning devices and it would be used to confirm an operator attendance in their room ,and it would operates like this :
the supervisor sets a certain period , basically 3 minutes ( or 6 or 12 ) , the operator should push the button at their desk once before the period elapse to confirm they are at their desk , should the delay pass , a visual warning will operate , pressing the button will reset the delay and the count start over
if say 15 second passed with no operator interaction , a sound warning start in the operator room , again pressing the button will reset the delay and start over.
if no interaction again , a second stage sound warning will sound at the supervisor room , having them to check the room and push the button to silent all warnings and start over
if no interaction still after the second stage alarm , a third stage sound warning will start after say 90 seconds at the staff room or other place where worker would be , and it will sound until the warning are silenced from the operator room.
i thought of attaching the push button as external interrupt to reset all warning and start the delay over , however all books or lectures i read about interrupt were mentioning that interrupt will resume the flow of the program after being served , meanwhile i need to reset the delay with every push/press.
sorry for being lengthy but is it ok for interrupts to change the flow of execution ? like having a "GOTO Start1 " statement to direct the control to the start of program ?
on the other hand , i thought of the following code with polling , could you please check it ?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 void main() { int i,j,h,k; trisa=0; trisb=1; porta=0; while (1) { start1: for (i=1;i<=3600;i++) { delay_ms(50); if (portb.f0==0) // button pressed i=1;} porta.f0=1; // first stage visual warning for(j=1;j<=300;j++) { delay_ms(50); if(portb.f0==0) { porta.f0=0; goto start1;}} porta.f1=1; // first stage sound warning for(h=1;h<=300;h++) { delay_ms(50); if (portb.f0==0){ porta.f0=0; porta.f1=0; goto start1;}} porta.f2=1; // second stage sound warning for (k=1;k<=1800;k++) { delay_ms(50); if (portb.f0==0) { porta.f0=0; porta.f1=0; porta.f2=0; goto start1;}} porta.f3=1; // thrid stage sound warning while (1){ if(portb.f0==0){ porta.f0=0; porta.f1=0; porta.f2=0; porta.f3=0; goto start1;}} } }
Thanks in advance , i plan to add delay configuration later if this works
Edit : syntax corrected after coding in Mikroc IDE , sorry for errors (wrote code from work using notepad)
simulation works using PIC16F84A
Regards
Last edited: