czarkek
Joined: 16 Jul 2008 Posts: 1
|
Button PIC18F2685 |
Posted: Wed Jul 16, 2008 6:03 am |
|
|
Hi, i think i have simple problem for someone with experience, but i dont know how solve this. My question is why if i return to main loop after proces1 or proces2, my holding of button not working and works like press. It working only once in first use. My code looks like this:
Code: |
#int_TIMER2
void TIMER2_isr(void)
{
if(t1)
t1--;
}
void check_buttons(void)
{
char new_status;
new_status = input(PIN_A3);
if (new_status==0)
{
if(new_status != gc_old_button_status)
{
t1 = BUTTONS_TIMER_TICKS;
}
else
{
if(!t1)
output_low(PASS);
}
}
else
{
if(new_status != gc_old_button_status)
{
if(t1)//go to simple mode
rs=2;
else //go to rs232 mode
rs=1;
}
}
// Save button status for next time.
gc_old_button_status=new_status;
}
void main()
{
no_m=0;
can_init();
t2=0;
t1=0;
net_id=0x501;
net_rtr=0;
net_ext=0;
net_len=8;
net_pri=3;
for (z=0;z<net_len;z++)
net_data[z] = 0;
net_data[0] = 0x11;
net_data[1] = 0x02;
rs=0;
load_busy_and_msg();
//write_can_settings();
can_set_mode(CAN_OP_CONFIG);
load_can_settings();
can_set_mode(CAN_OP_NORMAL);
can_set_mode(CAN_OP_CONFIG);
load_can_mask();
can_set_mode(CAN_OP_NORMAL);
//settings
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,48,4);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_vref(FALSE);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER2);
disable_interrupts(INT_RTCC);
output_high(FAIL);
output_high(PASS);
start:
gc_old_button_status = input(PIN_A3); // get switch status
rs=0;
//printf("\n\r CHOOSING MODE \n\r");
while(1)
{
check_buttons();
if (rs==1)// go to rs232 mode
{
output_high(PASS);
output_low(FAIL);
goto stage1;
}
// if not go to sending mode
else if(rs==2)
{
output_high(FAIL);
output_high(PASS);
goto stage2;
}
}
stage1:
proces1();
output_low(PASS);
goto start;
stage2:
proces2();
output_low(FAIL);
goto start;
}
|
Thanks in advance.
P.S. Sorry for my English. |
|