Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A/D On 18F1320

Status
Not open for further replies.
AtomSoft said:
Lets see if this is better:
Much improved, but a lot of your code has spaces instead of tabs. Other parts of it have tabs. It's all over the place. Use one or the other - be consistent. Best thing (IMHO) would be to go thru it and replace all those spaces with tabs so the columns line up all the way down, and comments all start at the same column (whenever possible anyway).
 
Just edited your code (I was bored!) to remove all spaces. Macro definition should be outside of org.

Like this:
Code:
	list	p=18F1320
	include	<p18F1320.inc>
	CONFIG	OSC = INTIO2, WDT = OFF, LVP = OFF

	cblock	0x00
	Count,advtemp,L2T,d1,d2,d3
	endc

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

	org 0x00 		;reset vector
	;goto	Main	
	;org	0x08		;ISR High 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	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
	bra	$+4
	decfsz	d2, f
	;goto	Delay_0
	bra	$-6
	bra	$+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
 
Saw your video nice but needs sound

I assume your using basic c ??
I is just a newbi so had to ask.
your connections to the Junebug?? why have 2 plugs pluged into the junebug?? ICD and con3.
I keep hearing about this ICD for debugging code ? explain??
I have lots of questions as I want to know what and why
still trying to figure out %10111111, oscon, etc??
I assume %10111111 is a byte definition but how does it set the A0 and A6 ports??
 
Status
Not open for further replies.

Latest threads

Back
Top