اهلا اخي..للاسف مااستعمل برنامج mikro
بس كتبت لك الكود باستخدام برنامج mplab ..حاول تطبق نفس الفكرة.
جربته في بروتس واشتغل.. بس كانه يحتاجله تعديل في الديلاي(delay) ..حاول تزيد في القيمة بين الضغطتين..
كود:
#include <htc.h>
__CONFIG(FOSC_INTOSC&WDTE_OFF&MCLRE_ON&CP_OFF);
#define _XTAL_FREQ 16000000
void main (void)
{
OSCCON = 0x7B; //select internal osciallator =16Mhz
__delay_us(4); //allow the new clock to stabilize
TRISCbits.TRISC2 =0; // set Pin 2 in PortC as output
TRISCbits.TRISC1 =1; // set Pin 1 in PortC as input
RC2=0; //clear Pin 2 in PortC
RC1=0; // clear Pin 1 in PortC
char stat=0; //define the state of the button
while(1)
{
while(RC1==1) //if button pushed
{
__delay_ms(100); //wait for 100 ms
if (RC1==1) //if the button is still pressed
{
RC2=1; //turn on the LED on PortC pin 2
stat=1; // change the status of button to high
}
}
while(RC1==0){ //if the button is not pressed
if (stat){ // check the previous status of the button if stat=1
RC2=1; //keep the LED high
for(int i=0; i<30; i++) //delay for 3 sec
{
while (RC1==1) //if the button is pressed during the delay, break the for loop
{
i=30;
}
__delay_ms(100);
}
}
RC2=0; //since the 30 min is passed and the button is not pressed,turn off the LED
stat=0; // change the status of the LED to low
}
}
}