# Problem in Polling PORTB<4:7> bits

Status
Not open for further replies.

#### spark1524

##### New Member
Hi there,

I am using PIC16F877. the concept is that it will be used in normal operation as a special counter, however, there should be a method that during operation, if I need to change certain parameters in EEPROM, it can do that, and then resume normal operation. I am using HT-PIC for programming. The pesudo code will be something of the sort

void main(void){
initialize_system();
while(1){
while(Program_mode_pin==0){
//perform normal counter operation
}
while(Program_mode_pin==1){
if(RB4==1)
//increment value;
if(RB5==1)
//decrement value;
if(RB6==1)
//subtract 1000 from value;
if(RB7==1)
//when done adjusting value, write value to eeprom and continue normal counter;
}

}

}

The actual code which I am trying to implement for Program_mode_pin for entering into value adjustment is as follows;
Code:
		while(Program_mode==1){

while((Rate_int_up==0)&&(Rate_int_down==0)&&(Rate_dec_up==0)&&(Rate_dec_down==0));

if(Rate_int_up){
rate_change = 1;
rate	=	rate	+ 100;
if(rate>9999)
rate	=	rate - 10000;
}
if(Rate_int_down){
rate_change = 1;
rate	=	rate - 100;
if(rate<0)
rate	=	rate + 10000;

}

if(Rate_dec_up){
rate_change = 1;
rate	=	rate + 1;
if((rate%100)==0)
rate	=	rate - 100;

}
if(Rate_dec_down){
rate_change = 1;
rate	=	rate - 1;
if((rate%100)==99)
rate	=	rate + 100;

}

if(rate_change==1){
update_rate(rate);
rate_change = 0;
}

while((Rate_int_up)||(Rate_int_down)||(Rate_dec_up)||(Rate_dec_down));
}

GIE = 0;
rate_ten_		=	(char)((rate/1000)%10);
rate_one_		=	(char)((rate/100)%10);
rate_point_one_	=	(char)((rate/10)%10);
rate_point_ten_	=	(char)(rate%10);

rate	=	(int)(rate_ten_*1000) + (int)(rate_one_*100) + (int)(rate_point_one_*10) + (int)rate_point_ten_;
update_rate(rate);

write_eeprom(0x01,rate_ten_);
write_eeprom(0x02,rate_one_);
write_eeprom(0x03,rate_point_one_);
write_eeprom(0x04,rate_point_ten_);
//		write_eeprom(0x05,pulses_to_ignore);
GIE = 1;
goto END;
}
END:
GIE = 0;
}
Rate_int_up, Rate_int_down, Rate_dec_up, Rate_dec_down are RB4, RB5, RB6, RB7. Please help, how to get desired results, as the code is not behaving properly. Sometimes it does the job, and suddenly it stops responding.

Please help. Thanks in anticipation

Status
Not open for further replies.

Replies
3
Views
963
Replies
9
Views
2K
Replies
8
Views
1K
Replies
6
Views
1K
Replies
2
Views
2K