yes sir it work fine with few changes .
but have some eshus.
when press sw mcu inter count mode & hold there till delay time .if agen i press sw during hold time mcu not goes next counter mode . it goes when delay time complete there .
whats wrong with me .
it have some some problem .
when press sw mcu inter count mode & hold there till delay time .if agen i press sw during hold time mcu not goes next counter mode . it goes when delay time complete there .
whats wrong with me .
PHP:
// Global includes
#include <xc.h>
#include <delay.h>
__CONFIG(FOSC_INTRCIO & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF);
#define LED PORTC
int count;
#define sw RA0
#define _XTAL_FREQ 4000000 //Internal clock is 4MHz//
/* THE main source code Start here*/
void main(void)
{unsigned int count_flag = 0;
CMCON=0x7; // disable the comparator
ANSEL=0x00; // all pin are Digital
TRISA=0b00001001; //only RA3 & RA0 is input
TRISC=0b00000000; //
PORTC=0b11111111;
while (1) { //loop forever
if(sw==1)//(sw_pressed)
{count_flag=1;}
if(count_flag==1){
count++;
switch(count)
{ case 1: {LED=0b00000001;}
delay_ms(5000);
break ;
case 2: {LED=0b00000010;}
delay_ms(5000);
break ;
case 3: {LED=0b00000100;}
delay_ms(5000);
break ;
case 4: {LED=0b00001000;}
delay_ms(5000);
break ;
case 5: {LED=0b00010000;}
delay_ms(5000);
break ;
case 6: {LED=0b00100000;}
delay_ms(5000);
count=0;
break ;
default :
break;
}
}
//else
if(sw==0)//(sw_unpressed)
{{count_flag=0;}
if(count_flag==0)
{LED=0b00000001;}
delay_ms(200);
{LED=0b00000010;}
delay_ms(200);
{LED=0b00000100;}
delay_ms(200);
{LED=0b00001000;}
delay_ms(200);
{LED=0b00010000;}
delay_ms(200);
{LED=0b00100000;}
delay_ms(200);
}
}
}
}
This way your switch condition will be monitored while in the delay ( well at least every mS ) you will need to tweak the us delay as I'm not sure of the "if" overhead...