Howdy ! I'm back on the forum after some absence (I had some personal problems).
I am trying to develop a project. I use a PIC12F675 with which I read the value of a group of 6 resistors, of different values, individually, to perform 6 specific tasks.
I am attaching the diagram. I am also attaching the code used so far, by which I try, in the first phase, to read if a button was pressed briefly or long, in order to make two different decisions depending on the duration of the press.
I wasted many hours with gemini/chatgpt, none of them managed to identify the problem of the code not working. I tried dozens of options, without any results.
What proved to me, once more, that we are superior (still?) to artificial intelligence, at least in certain aspects.
Can you help me identify and solve the problem? Thank you in advance !
Code:@ __config _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _BODEN_ON & _CP_ON DEFINE OSC 4 INCLUDE "modedefs.bas" CMCON = 7 TRISIO = %00001001 INTCON = 0 IOC = 0 GPIO = 0 ANSEL = %00110001 ' Constante longpress CON 5000 ' maximum press (5 sec) shortpress CON 100 ' minimum press ' Variabile durata var word PressStartTime var word overflow_counter_low var word T1CON = %00000110 ' Prescaler 1:64, activating Timer1 TMR1H = 0 ' Resetam Timer1 TMR1L = 0 GPIO.2 = 0 ADCON0 = %10000001 PAUSEUS 100 Main: durata = 0 overflow_counter_low = 0 ADCON0.1 = 1 While ADCON0.1 = 1 : Wend DataW.HighByte = ADRESH DataW.LowByte = ADRESL if DataW < 805 then if DataW > 50 AND DataW < 160 THEN b_level = 1 if DataW > 180 AND DataW < 270 THEN b_level = 2 if DataW > 290 AND DataW < 380 THEN b_level = 3 if DataW > 400 AND DataW < 500 THEN b_level = 4 if DataW > 540 AND DataW < 650 THEN b_level = 5 if DataW > 690 AND DataW < 800 THEN b_level = 6 if b_level <> 0 then TMR1H = 0 TMR1L = 0 PressStartTime = TMR1L while durata < longpress if T1CON.0 == 1 then overflow_counter_low = overflow_counter_low + 1 if overflow_counter_low == 65535 then overflow_counter_low = 0 durata = durata + 65535 endif endif durata = durata + (TMR1H * 256 + TMR1L) wend durata = durata - PressStartTime PAUSE 100 SEROUT GPIO.2, 2, ["Press for : ", #durata, " ms", 13, 10] endif endif GOTO Main![]()




Bookmarks