+ Reply to Thread
Page 2 of 3
First 1 2 3 Last
Results 16 to 30 of 45

Thread: A/D On 18F1320

  1. #16
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,743

    Default

    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


  2. #17
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,743

    Default

    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

  3. #18
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,701
    Blog Entries
    5

    Default

    Quote Originally Posted by AtomSoft
    yep thank god but it takes like 30 seconds to reset is that normal?
    30sec seems a little long, do you mean download and rerun?
    Also make sure the mode Release / Debug is correct on the MPLAB menu bar.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  4. #19
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,701
    Blog Entries
    5

    Default

    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.
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  5. #20
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,743

    Default

    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

  6. #21
    Help us help you blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent blueroomelectronics Excellent
    Join Date
    Jan 2007
    Location
    Toronto, Canada
    Posts
    10,701
    Blog Entries
    5

    Default

    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
    
    Bill
    Smart Kits build Smart People

    http://www.blueroomelectronics.com/

  7. #22
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,743

    Default

    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?

    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.htm
    
    My code would be:
    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
    			;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
    
    But not working
    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

  8. #23
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,743

    Default

    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

  9. #24
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    Quote Originally Posted by AtomSoft
    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?
    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.

    Like this:
    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
    
    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).
    Last edited by futz; 15th March 2008 at 01:00 AM.
    =========================
    Futz's Microcontrollers & Robotics
    =========================

  10. #25
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,743

    Default

    Ok got it at 100ms heres the delay:
    Code:
    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
    
    Thanks a bunch i didnt know that
    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

  11. #26
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    Quote Originally Posted by AtomSoft
    Ok got it at 100ms heres the delay:
    Code:
    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
    
    Ya, but clean up the delay like this:
    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
    
    The generator builds nasty, cluttered looking code.
    Last edited by futz; 15th March 2008 at 01:28 AM.
    =========================
    Futz's Microcontrollers & Robotics
    =========================

  12. #27
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,743

    Default

    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

  13. #28
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,743

    Default

    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

  14. #29
    futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent futz Excellent
    Join Date
    Sep 2007
    Location
    Vancouver, B.C.
    Posts
    1,980

    Default

    Quote Originally Posted by AtomSoft
    1 silly question

    will comments be in code? Like do they take up space? if not can i just comment out the code?
    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.
    Last edited by futz; 15th March 2008 at 01:32 AM.
    =========================
    Futz's Microcontrollers & Robotics
    =========================

  15. #30
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,743

    Default

    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

+ Reply to Thread
Page 2 of 3
First 1 2 3 Last

Similar Threads

  1. 18F1320 A/D Conversion
    By UTMonkey in forum Micro Controllers
    Replies: 5
    Latest: 27th December 2007, 04:48 AM
  2. 18f1320 - Tris = Ok, Lat = ?
    By UTMonkey in forum Micro Controllers
    Replies: 6
    Latest: 8th December 2007, 01:55 AM
  3. A/D question
    By YAN-1 in forum Micro Controllers
    Replies: 6
    Latest: 26th October 2007, 12:50 AM
  4. a/d conversion16f877
    By Handel in forum Micro Controllers
    Replies: 4
    Latest: 16th October 2007, 07:05 AM
  5. 18F1320 internal OSC doubling itself
    By Oznog in forum Micro Controllers
    Replies: 1
    Latest: 12th October 2005, 06:50 AM

Tags for this Thread