PIC18F452 Instruction

Thread Starter

StatEP

Joined May 3, 2007
5
is this program good?
PORTA 2: the sensor input.
PORTA3 connect to PORTA0.

Rich (BB code):
	list p=18f452

	; Include file, change directory if needed
	include "p18f452.inc"


	; Start at the reset vector
Reset_Vector  code 0x000
	goto Start                           ; Start application beyond vector area
	code	0x002A  
Start
	clrf	PORTB		             ;Clear PORTB
	clrf	TRISB		              ;PORTB all outputs, 
				                 ; A/D result on LEDs

	movlw	B'00010001'	         ;Fosc/8, A/D enabled
	movwf	ADCON0
	movlw	B'00001010'   	         ;Left justify,2 analog channel
	movwf	ADCON1		         ;Vres+ = 5mV

	movlw	B'11000111'	         ;TMR0 prescaler, 1:256
	movwf	T0CON

Main
	btfss	INTCON,TMR0IF	        ;Wait for Timer0 to timeout
	goto	Main
	bcf	INTCON,TMR0IF
	bsf	ADCON0,GO	         ;Start A/D conversion
Wait
	btfss	PIR1,ADIF	           ;Wait for conversion to complete
	goto	Wait


	NOP
	MOVFF	ADRESH,WREG
	MOVFF	WREG,W
	SUBLW	B'11111111'
    BNZ		Less_than_5mv		;if <> 0xff, go less than 5mv
	MOVFF	ADRESL,WREG			;else
	ANDLW	0x80				
	SUBLW	0x80
	BNZ		Less_than_5mv	;if <> 0xc0, go less than 5mv
	GOTO 	Than_5mv				;otherwise, >5mv

Less_than_5mv
	MOVFF	W,WREG
	NOP
	ADDLW	0x00
   
	ADDLW   B'10011010'		;0x66 + 0x99 -> WREG
	BZ	   Sub_P2		    ;if Zero, go check Less or high than 2mv
	BNC	  Less_2mv	  ;if no Carry, Less Than 2mv
	GOTO   	Less_5mv_than_2mvS1

Sub_P2
	MOVFF	ADRESL,WREG
	ADDLW	0x00
	ANDLW   0xc0				

	ADDLW	B'01000000'
	BC	   Less_5mv_than_2mvS1
	goto	  Less_2mv		

Than_5mv
	MOVLW	B'00000100'	        ;RB2 ON
	goto	Disp_PB	

Less_5mv_than_2mvS1
	MOVLW	B'00000010'	        ;RB1 ON
	goto    Disp_PB

Less_2mv
	MOVLW	B'00000001'	        ;RB0 ON
	goto    Disp_PB
Disp_PB
	movwf	PORTB		        ;Write A/D result to PORTB

	clrf	PORTB
WaitPush			;Pause while switch is pressed
	btfss	PORTA,4
	goto	WaitPush

	movwf	PORTB
	goto	Main		;Do it again

	end
_______________________________________________________________________________________________________

This code is to read the values made from the sensor. Upper limit set. LED Lights up when it goes over the limit.
i'm open to suggestion
 
Top