View previous topic :: View next topic |
Author |
Message |
scanan
Joined: 13 Aug 2004 Posts: 79 Location: Turkey
|
about portB on pic18f45k40 |
Posted: Fri Oct 03, 2025 8:37 am |
|
|
hello,
I am trying to input a button value from PIN_B4
and my global interrupt is enabled.
I can't input from PIN_B4
when disabled the PIN_B4 function as input correctly
I trried
enable_interrupts(INT_EXT1);
disable_interrupts(INT_EXT2);
disable_interrupts(INT_LOWVOLT);
enable_interrupts(INT_TIMER0);
disable_interrupts(INT_TIMER1);
disable_interrupts(INT_AD);
disable_interrupts(INT_IOC_B4);
disable_interrupts(INT_IOC_B4_L2H );
disable_interrupts(INT_IOC_B4_H2L );
enable_interrupts(GLOBAL);
but can't get an input
seems that PORTB is by default analog input read the datasheet I can't get any clue.
any suggestions _________________ Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com
Do whatever you do with amateur spirit -
But always feel professional. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19956
|
|
Posted: Fri Oct 03, 2025 9:00 am |
|
|
set_analog_pins(NO_ANALOGS);
Obviously if you are using some analog pins, substitute the pins you want
here instead. |
|
 |
scanan
Joined: 13 Aug 2004 Posts: 79 Location: Turkey
|
|
Posted: Fri Oct 03, 2025 9:32 am |
|
|
Ttelmah wrote: | set_analog_pins(NO_ANALOGS);
Obviously if you are using some analog pins, substitute the pins you want
here instead. |
setup_wdt(WDT_OFF);
setup_adc(ADC_OFF);
setup_adc_ports(NO_ANALOGS);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_4);
setup_timer_1(T1_DISABLED | T1_DIV_BY_1);
setup_timer_2(T2_DISABLED, 0xFF, 0x10);
setup_timer_3(T3_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_low_volt_detect(FALSE);
setup_oscillator(OSC_HFINTRC_8MHZ );
clear_interrupt(INT_EXT1);
//clear_interrupt(INT_EXT2);
handle_test_leds(1);
delay_ms(1500);
handle_test_leds(0);
version();
ext_int_edge(1, L_TO_H);
//ext_int_edge(2, H_TO_L);
enable_interrupts(INT_EXT1);
disable_interrupts(INT_EXT2);
disable_interrupts(INT_LOWVOLT);
enable_interrupts(INT_TIMER0);
disable_interrupts(INT_TIMER1);
disable_interrupts(INT_AD);
disable_interrupts(INT_IOC_B4);
disable_interrupts(INT_IOC_B4_L2H );
disable_interrupts(INT_IOC_B4_H2L );
enable_interrupts(GLOBAL);
still can't read the PIN_B4 as digital input. _________________ Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com
Do whatever you do with amateur spirit -
But always feel professional. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9584 Location: Greensville,Ontario
|
|
Posted: Fri Oct 03, 2025 9:48 am |
|
|
Any chance that's a 'PPS' PIC ?? |
|
 |
scanan
Joined: 13 Aug 2004 Posts: 79 Location: Turkey
|
|
Posted: Fri Oct 03, 2025 11:02 am |
|
|
temtronic wrote: | Any chance that's a 'PPS' PIC ?? |
big chance I am very confused with these PPS PICS _________________ Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com
Do whatever you do with amateur spirit -
But always feel professional. |
|
 |
dyeatman
Joined: 06 Sep 2003 Posts: 1968 Location: Norman, OK
|
|
Posted: Fri Oct 03, 2025 11:24 am |
|
|
Quote: | Any chance that's a 'PPS' PIC ?? |
In other words ALWAYS tell us what chip and compiler version you are using!!
Also helps to show all the setup lines from the chip definition forward, this
would save you and this group a great deal of "back and forth" and guessing. _________________ Google and Forum Search are some of your best tools!!!! |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19956
|
|
Posted: Fri Oct 03, 2025 11:26 am |
|
|
You say you can't get an interrupt, but you are only disabling the interrupt
on this pin, not enabling it. You also understand that the 'handler' for this
needs to just be INT_IOC?.
You show nothing to illustrate why you think the pin is analog.
Nothing reading this pin, or enabling the interrupt on it.
Also understand that if you have multiple lines on one interrupt as you
show, it is the last one that applies. If you want multiple settings (like
H2L and L2H), these need to be or'ed together in a single line.
You do realise that enabling any interrupt without a handler declared for
it, will cause the chip to stop working?. The code will vector to where the
handler should be, never get a clear interrupt for this, and as a result
things won't work. I suspect this may be what is stopping your input
from working. Interrupts wake up disabled, so get rid of all the fiddling
with this pin, and just make sure you have got working handlers for
every event. Also that these will exit correctly. having a handler that
does not exit, would also stop things working. Also some handlers have
critical things that need to happen before they can exit. So (for example)
serial handlers must read the character, or they can never exit.
Why do you have INT_AD?. This would only be used if you are triggering the
AD from perhaps a timer. The value must be read in this or like the serial
interrupt it cannot be cleared. |
|
 |
|