 |
:: استاذ و مشرف قسم الالكترونيات ::
تاريخ التسجيل: May 2007
المشاركات: 6,894
|
|
نشاط [ F.Abdelaziz ]
قوة السمعة:335
|
|
07-04-2012, 02:01 PM
المشاركة 7
|
|
البرنامج :
كود:
/*
Basic Alarm system for any equipment
As fire alarm system, diesel-generator alarm system….
*/
// Definitions &Declarations
#define ON 1
#define OFF 0
#define T0IF INTCON.T0IF //Timer0 Interrupt Flag Bit INTCON.F0IF defined as "T0IF"
//INPUTS
sbit INPUT at PORTC.B0 ; // Input Sensor as Switch
sbit ALARM_ACCEPTED at PORTC.B1 ;// Input "ALARM_ACCEPTED" Switch
sbit LAMP_TEST at PORTC.B2 ;// Input "LAMP_TEST" Switch
//OUTPUTS
sbit OUTPUT at PORTD.B0 ; //"Output" device as "LED" '
sbit BUZZER at PORTD.B1;
// Internal Bits OR"Internal Relays"
bit flash;
bit M0;
bit INPUT_PULSE ;
bit UNACCEPT ;
unsigned char Counter = 0;
void settings ( void ); // Setting Function
void interrupt ( );
// main function
void main ( )
{
OUTPUT=OFF;
settings ( ) ; // Run Setting Function for ports and registers
while ( 1 ) // run a loop
{
PORTD.B7=flash; // As "Operation Indication" - option
INPUT_PULSE = (INPUT&~M0 );//Produce "INPUT ONE SHOT PULSE "
M0=INPUT;
UNACCEPT = (~ALARM_ACCEPTED &(INPUT_PULSE | UNACCEPT )) ;
OUTPUT=LAMP_TEST |((UNACCEPT & flash) | (INPUT & ~UNACCEPT )) ;
BUZZER = (UNACCEPT | LAMP_TEST);
}// end loop
} // end main
void settings ( void ) // Setting Function
{
//1- PORTS Setting
TRISD= 0 ; // RD0 as outputs
PORTD=0;
TRISC=0xFF;
PORTC=0;
// 2- Setting the OPTION register
OPTION_reg = 0b11000100 ; //Prescaler 1:32 ,assigned to Timer0 , pull-up resistors on port B disabled
// 3- Set interrupt
INTCON = 0b10100000; // Interrupt on Timer0 enabled & Global Interrupt enabled
TMR0 = 100 ; // Set Timer0 to 100 , as initial value
}
// Interrupt Routine Service IRS
void interrupt ( )
{
if( T0IF ) // Interrupt was caused by an overflow of Timer0?
{
Counter ++; // Increment the timer for the blinking LED each (255-100)* 32 = 5ms
if( Counter>= 100 ) // If the time has passed TEMP_LED=100 T = 5ms * 100 times = 500 ms = 0.5sec
{
flash = flash^1 ; // Invert LED status to flash .
/* ^ bitwise exclusive OR (XOR); compares pairs of bits and returns 1 if the bits are complementary, otherwise returns 0 */
Counter= 0 ; // Reloading the LED timer to start again
}
TMR0 = 100 ; // Timer0 reloaded
T0IF = 0 ; // Reset the interrupt flag of timer 0
} // end that occurred on Timer0 interrupt
} // end of interrupt service routine
|