Thanks !
But nothing on serial ...(in Proteus 8)
Thanks !
But nothing on serial ...(in Proteus 8)
Last edited by fratello; - 28th March 2024 at 18:33.
forget Proteus.
Also I think Henrik forgot to add the label Exit: just before the Serout command.
Ioannis
Last edited by Ioannis; - 28th March 2024 at 19:03.
No, I did not forget to add a label.
EXIT is a keyword used to break out of the current loop.
AI, simulation, virtualization.... What happened to the good old breadboard?
Do I really need to spin this up on my dev board here or can you do some troubleshooting on your own and not just say "it's not working". You did include the same setupcode used before didn't you?
It works ! Finally, the first program that shows me the duration. BUT .... the correct identification of the pressed button does not work ! I pressed ONLY button 0 : short or long ...It doesn't matter which button I press: if I press it briefly it indicates button 0, if I press it long it indicates button 5. Why?
Anyway thanks for pointing into a good direction !
Solved !
![]()
Last edited by fratello; - 29th March 2024 at 10:23.
the chances of AI finding well written pbp code to plagiarize from are slim at best.AI, simulation, virtualization.... What happened to the good old breadboard?
afaics AI can only write code if it can plagiarize it from somewhere, the code only works if the stolen code exactly matched your circumstances.
its quite amazing that this plagiarism is tolerated just because a machine is stealing it. open source etc. does not mean you can copy it and pass it off as your own original work.
breadboard , the manual and a data sheet is at least an honest and rewarding learning experience
henriks work as it needs to be
Code:#CONFIG cfg = _INTRC_OSC_NOCLKOUT cfg&= _WDT_ON cfg&= _PWRTE_OFF cfg&= _MCLRE_ON cfg&= _BODEN_ON cfg&= _CP_OFF cfg&= _CPD_OFF __CONFIG cfg #ENDCONFIG CMCON = 7 TRISIO = 111001 INTCON = $C0 PIE1.0 = 1 ANSEL = 110001 ADCON0 = 000001 Long_Press CON 5000 Short_Press con 100 cnt VAR WORD b_level VAR BYTE but VAR BYTE DataW VAR WORD Main: GOSUB ReadButton IF but > 0 THEN cnt = 0 WHILE but > 0 cnt = cnt + 10 if cnt > Long_Press THEN EXIT PAUSE 10 GOSUB ReadButton WEND SEROUT GPIO.2, 2, ["You pressed button ", #b_level, " for ", #cnt, "ms", 13, 10] endif Goto Main ReadButton: ADCON0.1 = 1 While ADCON0.1 = 1 : Wend DataW.HighByte = ADRESH DataW.LowByte = ADRESL but = 0 if DataW < 805 then but=1 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 < 520 THEN b_level = 4 if DataW > 540 AND DataW < 650 THEN b_level = 5 if DataW > 690 AND DataW < 800 THEN b_level = 6 ENDIF RETURN
Warning I'm not a teacher
a bit fancier
Code:#CONFIGcfg = _INTRC_OSC_NOCLKOUT cfg&= _WDT_ON cfg&= _PWRTE_OFF cfg&= _MCLRE_ON cfg&= _BODEN_ON cfg&= _CP_OFF cfg&= _CPD_OFF __CONFIG cfg #ENDCONFIG DEFINE INTHAND _TICK DEFINE DEBUG_REG GPIO DEFINE DEBUG_BIT 2 DEFINE DEBUG_BAUD 9600 DEFINE DEBUG_MODE 0 CMCON = 7 TRISIO = 111001 INTCON = $C0 PIE1.0 = 1 ANSEL = 110001 CLEAR ' Constante TimerReload CON 61637 ;3.906mS ' Variabile W_TEMP VAR BYTE BANK0 STATUS_TEMP VAR BYTE BANK0 MILLIES var word BANK0 b_level var byte b_state var byte NOW var word LEDT var word buttont var word duration var word DataW var word GPIO.2 = 0 ADCON0 = 000001 T1CON = 000001 'Prescaler 1:1,Timer1 ON Main: PIE1.0 = 0 NOW = MILLIES ;in 3.906mS ticks PIE1.0 = 1 IF NOW - LEDT > 250 THEN ;1 sec LEDT = NOW TOGGLE GPIO.1 ENDIF 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 < 520 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_state == 0 then b_state = 1 buttont = now else DEBUG "button ",#b_level, 13, 10 endif ELSE if b_state then ' duration = (now - buttont)<<2 duration = now - buttont buttont = duration.lowbyte */1000 b_state = 0 DEBUG "Pressed button ",#b_level," for : ", #duration.highbyte,".",#buttont, " S", 13, 10 ' DEBUG "Pressed button ",#b_level," for : ", #duration, "mS", 13, 10 b_level = 0 endif endif GOTO Main TICK: ;isr asm MOVWF _W_TEMP ;copy W to temp register,could be in either bank SWAPF STATUS,W ;swap status to be saved into W BCF STATUS,RP0 ;change to bank 0 regardless of current bank MOVWF _STATUS_TEMP MOVE?CT 0, T1CON, TMR1ON ; stop timer MOVLW LOW(_TimerReload) ; Add TimerReload ADDWF TMR1L,F BTFSC STATUS,C INCF TMR1H,F MOVLW HIGH(_TimerReload) ADDWF TMR1H,F MOVE?CT 1, T1CON, TMR1ON ; start timer MOVE?CT 0, PIR1, TMR1IF ; CLR timer FLAG INCF _MILLIES ,F BTFSC STATUS,Z INCF _MILLIES+1 ,F SWAPF _STATUS_TEMP,W;swap STATUS_TEMP register int W, sets bank to original state MOVWF STATUS ;move W into STATUS register SWAPF _W_TEMP,F ;swap W_TEMP SWAPF _W_TEMP,W ;swap W_TEMP into W RETFIE endASM
Last edited by richard; - 29th March 2024 at 11:04. Reason: note modified button 4 for my testing
Warning I'm not a teacher
Thank you very much !!! I can't wait to test it at the weekend !
LE : I use PBP 2.5, so TimerReload CON 61637 = WARNING Line 10: 111001 Numeric overflow, value truncated.
Last edited by fratello; - 29th March 2024 at 11:14.
Bookmarks