yep thank god but it takes like 30 seconds to reset is that normal?
yep thank god but it takes like 30 seconds to reset is that normal?
AtomSofts eBay Store
AtomSoftTech: C18 TIPS & TRICKS v9 PDF
My Name: Jason Lopez
My BLOG | My YouTube Videos!
My Favorite Store:
dipmicro Electronics
Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
Electronic Components & Tools Exchange
Im going to make the little 4 button remote on a pcb just so i can use it for later test requiring multiple buttons.
AtomSofts eBay Store
AtomSoftTech: C18 TIPS & TRICKS v9 PDF
My Name: Jason Lopez
My BLOG | My YouTube Videos!
My Favorite Store:
dipmicro Electronics
Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
Electronic Components & Tools Exchange
30sec seems a little long, do you mean download and rerun?Originally Posted by AtomSoft
Also make sure the mode Release / Debug is correct on the MPLAB menu bar.
Ahh try this at the beginning of your code. Debug speed is based on oscillator speed.
Default is 32Khz (slow!)
this will set it 8MHz
Of course your delays are going to go quite a bit faster!
Code:movlw 0x72 ; 8MHz clock select movwf OSCCON
Last edited by blueroomelectronics; 14th March 2008 at 10:07 PM.
ok i will check that but what is it supposed to be (debug right) also when i alter code i usually press compile then program then reset so it starts from ORG 0 again but when i press reset it takes anywhere from 15-30 secs
AtomSofts eBay Store
AtomSoftTech: C18 TIPS & TRICKS v9 PDF
My Name: Jason Lopez
My BLOG | My YouTube Videos!
My Favorite Store:
dipmicro Electronics
Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
Electronic Components & Tools Exchange
I've moved a couple things around and added OSCCON
Code:list p=18F1320 include <p18F1320.inc> CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF cblock 0x00 Count advtemp L2T endc org 0x00 ; reset vector LED macro x,y ;MACRO LED <PORTA>, <TRISA> movlw x movwf LATA ;LATA = x movlw y movwf TRISA ;TRISA = y call Delay ;call the Delay subroutine endm ;end macro goto Main org 0x08 ; ISR Low vector goto ISR org 0x18 ; ISR Low vector goto ISR Main movlw 0x72 ; 8MHz clock select movwf OSCCON CLRF PORTB ;Initialize PORTB by clearing output data latches CLRF LATB ;Alternate method to clear output data latches MOVLW 0x01 ;A/D Config MOVWF ADCON1 ;ADCON1: All analog except AN0 MOVLW b'00000010' ;TRISB Config MOVWF TRISB ;Set RB1 as input RB<7:2> and RB0 as outputs MOVLW b'11001000' ;INTCON Config MOVWF INTCON ;Enable GIE/GIEH, PEIE/GIEL, RBIE Disable rest MOVLW b'11110101' ;INTCON2 Config MOVWF INTCON2 ;Enable RBPU, Rising Edge Interrupts, High Priority MOVLW b'11001000' ;INTCON3 Config MOVWF INTCON3 ;High Priority, Enable INT1 and Clear Flags movlw b'00010101' ;enable A/D, AN5 movwf ADCON0 StartUp bsf ADCON0,GO ;Start A/D conversion adloop btfsc ADCON0,DONE ;Check if done. If not goto adloop else skip loop goto adloop MOVLW 0xEE ;Button Pressed Preset CPFSLT ADRESH ;If ADRESH < Skip the goto else start over goto StartUp ;because no button pressed Check1 MOVLW 0xBF ;4th button Preset CPFSGT ADRESH ;If ADRESH > BFH then this button was pressed goto Check2 ;If not then it wasnt pressed skip to next check MOVLW 0x04 MOVWF L2T ;Set L2T to 0x04 (MY LOOP COUNTER) goto LEDXT ;Goto LEDXT which is the Light X Times where x = 4h for this button Check2 MOVLW 0x7F ;3rd button preset CPFSGT ADRESH ;If ADRESH > 7FH then this button was pressed goto Check3 ;If not then it wasnt pressed skip to next check MOVLW 0x03 MOVWF L2T ;Set L2T to 0x03 (MY LOOP COUNTER) goto LEDXT ;Goto LEDXT which is the Light X Times where x = 3h for th Check3 MOVLW 0x3F ;Same as others CPFSGT ADRESH goto Check4 MOVLW 0x02 MOVWF L2T goto LEDXT Check4 MOVLW 0x00 ;Same CPFSEQ ADRESH ;If ADRESH = 0 then goto LED1T because button 1 was hit goto StartUp ;if not then goto startup goto LED1T ;LED 1 Time LED1T call ScrollMe ;Scroll LEDs 1 time goto StartUp ;Goto Startup LEDXT ;LEDXT loop call ScrollMe ;Scroll 1 time DECFSZ L2T ;Decrement L2T and skip the next line if 0 goto LEDXT ;goto ledxt loop goto StartUp ;Goto StartUp Delay decfsz Count,f ;decrement Count and skip when zero goto $-2 ;not zero? repeat return ScrollMe LED b'00000001',b'10111110' ; Light LED 1 LED b'01000000',b'10111110' ; Light LED 2 LED b'01000000',b'00111111' ; Light LED 3 LED b'10000000',b'00111111' ; Light LED 4 LED b'10000000',b'01111110' ; Light LED 5 LED b'00000001',b'01111110' ; Light LED 6 return ; Return from where called ISR BCF INTCON3, 0 ; Clear INT1 BCF INTCON, 0 ; Clear RBIF: RB Port Change Interrupt Flag bit LED b'00000001',b'01111110' ; Light LED 6 call Delay ; 2 delays call Delay retfie ; Return from where called END
Dude i cant seem to get the delay right. I used the Delay Code Generator to make the below and it doesnt work or maybe im doing something wrong?
My code would be:Code:; Delay = 0.2 seconds ; Clock frequency = 8 MHz ; Actual delay = 0.2 seconds = 400000 cycles ; Error = 0 % cblock d1 d2 d3 endc Delay ;399992 cycles movlw 0x35 movwf d1 movlw 0xE0 movwf d2 movlw 0x01 movwf d3 Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay_0 ;4 cycles goto $+1 goto $+1 ;4 cycles (including call) return ; Generated by http://www.piclist.com/cgi-bin/delay.exe (December 7, 2005 version) ; Fri Mar 14 23:43:27 2008 GMT ; See also various delay routines at http://www.piclist.com/techref/microchip/delays.htmBut not workingCode:list p=18F1320 include <p18F1320.inc> CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF cblock 0x00 Count advtemp L2T d1 d2 d3 endc org 0x00 ; reset vector LED macro x,y ;MACRO LED <PORTA>, <TRISA> movlw x movwf LATA ;LATA = x movlw y movwf TRISA ;TRISA = y call Delay ;call the Delay subroutine endm ;end macro goto Main org 0x08 ; ISR Low vector goto ISR org 0x18 ; ISR Low vector goto ISR Main movlw 0x72 ; 8MHz clock select movwf OSCCON CLRF PORTB ;Initialize PORTB by clearing output data latches CLRF LATB ;Alternate method to clear output data latches MOVLW 0x01 ;A/D Config MOVWF ADCON1 ;ADCON1: All analog except AN0 MOVLW b'00000010' ;TRISB Config MOVWF TRISB ;Set RB1 as input RB<7:2> and RB0 as outputs MOVLW b'11001000' ;INTCON Config MOVWF INTCON ;Enable GIE/GIEH, PEIE/GIEL, RBIE Disable rest MOVLW b'11110101' ;INTCON2 Config MOVWF INTCON2 ;Enable RBPU, Rising Edge Interrupts, High Priority MOVLW b'11001000' ;INTCON3 Config MOVWF INTCON3 ;High Priority, Enable INT1 and Clear Flags movlw b'00010101' ;enable A/D, AN5 movwf ADCON0 StartUp bsf ADCON0,GO ;Start A/D conversion adloop btfsc ADCON0,DONE ;Check if done. If not goto adloop else skip loop goto adloop MOVLW 0xEE ;Button Pressed Preset CPFSLT ADRESH ;If ADRESH < Skip the goto else start over goto StartUp ;because no button pressed Check1 MOVLW 0xBF ;4th button Preset CPFSGT ADRESH ;If ADRESH > BFH then this button was pressed goto Check2 ;If not then it wasnt pressed skip to next check MOVLW 0x04 MOVWF L2T ;Set L2T to 0x04 (MY LOOP COUNTER) goto LEDXT ;Goto LEDXT which is the Light X Times where x = 4h for this button Check2 MOVLW 0x7F ;3rd button preset CPFSGT ADRESH ;If ADRESH > 7FH then this button was pressed goto Check3 ;If not then it wasnt pressed skip to next check MOVLW 0x03 MOVWF L2T ;Set L2T to 0x03 (MY LOOP COUNTER) goto LEDXT ;Goto LEDXT which is the Light X Times where x = 3h for th Check3 MOVLW 0x3F ;Same as others CPFSGT ADRESH goto Check4 MOVLW 0x02 MOVWF L2T goto LEDXT Check4 MOVLW 0x00 ;Same CPFSEQ ADRESH ;If ADRESH = 0 then goto LED1T because button 1 was hit goto StartUp ;if not then goto startup goto LED1T ;LED 1 Time LED1T call ScrollMe ;Scroll LEDs 1 time goto StartUp ;Goto Startup LEDXT ;LEDXT loop call ScrollMe ;Scroll 1 time DECFSZ L2T ;Decrement L2T and skip the next line if 0 goto LEDXT ;goto ledxt loop goto StartUp ;Goto StartUp ;Delay ;decfsz Count,f ;decrement Count and skip when zero ;goto $-2 ;not zero? repeat ;return Delay ;399992 cycles movlw 0x35 movwf d1 movlw 0xE0 movwf d2 movlw 0x01 movwf d3 Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay_0 ;4 cycles goto $+1 goto $+1 ;4 cycles (including call) return ScrollMe LED b'00000001',b'10111110' ; Light LED 1 LED b'01000000',b'10111110' ; Light LED 2 LED b'01000000',b'00111111' ; Light LED 3 LED b'10000000',b'00111111' ; Light LED 4 LED b'10000000',b'01111110' ; Light LED 5 LED b'00000001',b'01111110' ; Light LED 6 return ; Return from where called ISR BCF INTCON3, 0 ; Clear INT1 BCF INTCON, 0 ; Clear RBIF: RB Port Change Interrupt Flag bit LED b'00000001',b'01111110' ; Light LED 6 call Delay ; 2 delays call Delay retfie ; Return from where called END
AtomSofts eBay Store
AtomSoftTech: C18 TIPS & TRICKS v9 PDF
My Name: Jason Lopez
My BLOG | My YouTube Videos!
My Favorite Store:
dipmicro Electronics
Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
Electronic Components & Tools Exchange
On the bright side this is my final 4 button pad design. Since its for testing on various projects i will not doll it up with a case and such.
I made the connector from some old parts off an old motherboard i had around.
AtomSofts eBay Store
AtomSoftTech: C18 TIPS & TRICKS v9 PDF
My Name: Jason Lopez
My BLOG | My YouTube Videos!
My Favorite Store:
dipmicro Electronics
Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
Electronic Components & Tools Exchange
And no wonder. You can't use "goto $+2" on an 18F. You must change those to "goto $+6". The delay calculator was made for 16F's. So of course your delays are completely screwed up.Originally Posted by AtomSoft
Like this:
Ya, unless I need precision I always strip the excess clutter (those little fine-tuning goto's and nops) out of delays made by the piclist generator. Even if I do need precision I still clean it up. The comments are splattered all over the place and the labels are on the line before the code. They can almost always be on same line as code (depends on length of label).Code:Delay movlw 0x23 ;2 second delay @8MHz movwf d1 movlw 0xb9 movwf d2 movlw 0x09 movwf d3 Delay_0 decfsz d1,F goto $+6 decfsz d2,F goto $+6 decfsz d3,F goto Delay_0 return
Last edited by futz; 15th March 2008 at 01:00 AM.
Ok got it at 100ms heres the delay:
Thanks a bunch i didnt know thatCode:Delay ;199993 cycles movlw 0x3E movwf d1 movlw 0x9D movwf d2 Delay_0 decfsz d1, f goto $+6 decfsz d2, f goto Delay_0 ;3 cycles goto $+2 nop ;4 cycles (including call) return![]()
AtomSofts eBay Store
AtomSoftTech: C18 TIPS & TRICKS v9 PDF
My Name: Jason Lopez
My BLOG | My YouTube Videos!
My Favorite Store:
dipmicro Electronics
Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
Electronic Components & Tools Exchange
Ya, but clean up the delay like this:Originally Posted by AtomSoft
The generator builds nasty, cluttered looking code.Code:Delay movlw 0x3E ;100ms movwf d1 movlw 0x9D movwf d2 Delay_0 decfsz d1, f goto $+6 decfsz d2, f goto Delay_0 goto $+2 ;can be deleted if you don't need precision nop ;can be deleted if you don't need precision return
Last edited by futz; 15th March 2008 at 01:28 AM.
oh ok i am also going to remove the interrupt code i still have in place to save memory
AtomSofts eBay Store
AtomSoftTech: C18 TIPS & TRICKS v9 PDF
My Name: Jason Lopez
My BLOG | My YouTube Videos!
My Favorite Store:
dipmicro Electronics
Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
Electronic Components & Tools Exchange
1 silly question
will comments be in code? Like do they take up space? if not can i just comment out the code?
AtomSofts eBay Store
AtomSoftTech: C18 TIPS & TRICKS v9 PDF
My Name: Jason Lopez
My BLOG | My YouTube Videos!
My Favorite Store:
dipmicro Electronics
Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
Electronic Components & Tools Exchange
Comments take no space in the PIC. They are ignored by the assembler. If you want code left in your source for later use but not assembled then by all means just comment it out. Standard practice.Originally Posted by AtomSoft
Last edited by futz; 15th March 2008 at 01:32 AM.
Thanks Then The Final Code Is:
Code:list p=18F1320 include <p18F1320.inc> CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF cblock 0x00 Count advtemp L2T d1 d2 d3 endc org 0x00 ; reset vector LED macro x,y ;MACRO LED <PORTA>, <TRISA> movlw x movwf LATA ;LATA = x movlw y movwf TRISA ;TRISA = y call Delay ;call the Delay subroutine endm ;end macro ;goto Main ;org 0x08 ; ISR Low vector ;goto ISR ;org 0x18 ; ISR Low vector ;goto ISR Main movlw 0x72 ; 8MHz clock select movwf OSCCON CLRF PORTB ;Initialize PORTB by clearing output data latches CLRF LATB ;Alternate method to clear output data latches MOVLW 0x01 ;A/D Config MOVWF ADCON1 ;ADCON1: All analog except AN0 MOVLW b'00000010' ;TRISB Config MOVWF TRISB ;Set RB1 as input RB<7:2> and RB0 as outputs MOVLW b'11001000' ;INTCON Config MOVWF INTCON ;Enable GIE/GIEH, PEIE/GIEL, RBIE Disable rest MOVLW b'11110101' ;INTCON2 Config MOVWF INTCON2 ;Enable RBPU, Rising Edge Interrupts, High Priority MOVLW b'11001000' ;INTCON3 Config MOVWF INTCON3 ;High Priority, Enable INT1 and Clear Flags movlw b'00010101' ;enable A/D, AN5 movwf ADCON0 StartUp bsf ADCON0,GO ;Start A/D conversion adloop btfsc ADCON0,DONE ;Check if done. If not goto adloop else skip loop goto adloop MOVLW 0xEE ;Button Pressed Preset CPFSLT ADRESH ;If ADRESH < Skip the goto else start over goto StartUp ;because no button pressed Check1 MOVLW 0xBF ;4th button Preset CPFSGT ADRESH ;If ADRESH > BFH then this button was pressed goto Check2 ;If not then it wasnt pressed skip to next check MOVLW 0x04 MOVWF L2T ;Set L2T to 0x04 (MY LOOP COUNTER) goto LEDXT ;Goto LEDXT which is the Light X Times where x = 4h for this button Check2 MOVLW 0x7F ;3rd button preset CPFSGT ADRESH ;If ADRESH > 7FH then this button was pressed goto Check3 ;If not then it wasnt pressed skip to next check MOVLW 0x03 MOVWF L2T ;Set L2T to 0x03 (MY LOOP COUNTER) goto LEDXT ;Goto LEDXT which is the Light X Times where x = 3h for th Check3 MOVLW 0x3F ;Same as others CPFSGT ADRESH goto Check4 MOVLW 0x02 MOVWF L2T goto LEDXT Check4 MOVLW 0x00 ;Same CPFSEQ ADRESH ;If ADRESH = 0 then goto LED1T because button 1 was hit goto StartUp ;if not then goto startup goto LED1T ;LED 1 Time LED1T call ScrollMe ;Scroll LEDs 1 time goto StartUp ;Goto Startup LEDXT ;LEDXT loop call ScrollMe ;Scroll 1 time DECFSZ L2T ;Decrement L2T and skip the next line if 0 goto LEDXT ;goto ledxt loop goto StartUp ;Goto StartUp ;Delay ;decfsz Count,f ;decrement Count and skip when zero ;goto $-2 ;not zero? repeat ;return Delay movlw 0x3E movwf d1 movlw 0x9D movwf d2 Delay_0 decfsz d1, f goto $+6 decfsz d2, f goto Delay_0 goto $+2 nop return ScrollMe LED b'00000001',b'10111110' ; Light LED 1 LED b'01000000',b'10111110' ; Light LED 2 LED b'01000000',b'00111111' ; Light LED 3 LED b'10000000',b'00111111' ; Light LED 4 LED b'10000000',b'01111110' ; Light LED 5 LED b'00000001',b'01111110' ; Light LED 6 return ; Return from where called ;ISR BCF INTCON3, 0 ; Clear INT1 ;BCF INTCON, 0 ; Clear RBIF: RB Port Change Interrupt Flag bit ;LED b'00000001',b'01111110' ; Light LED 6 ;call Delay ; 2 delays ;call Delay ;retfie ; Return from where called END
Last edited by AtomSoft; 15th March 2008 at 02:34 AM.
AtomSofts eBay Store
AtomSoftTech: C18 TIPS & TRICKS v9 PDF
My Name: Jason Lopez
My BLOG | My YouTube Videos!
My Favorite Store:
dipmicro Electronics
Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
Electronic Components & Tools Exchange