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.

Help me...

Status
Not open for further replies.

alamy

New Member
the idea is to compare the input value with setpoints (SP) value and turn ON the LED for appropriate setpoints

Input > SP1 = LED1 On
Input > SP2 = LED2 On
Input > SP3 = LED3 On

by simulate using MPLAB (MPSIM), i found my 'test' routines have problem...but do not know how should i solve it..

here the code

pls help me

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Author : alamy
;Date   : 22/10/04
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;********************************************************************** 


   list      p=16F84A            ; list directive to define processor 
   #include <p16F84A.inc>        ; processor specific variable definitions 

   __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC 


; '__CONFIG' directive is used to embed configuration data within .asm file. 
; The lables following the directive are located in the respective .inc file. 
; See respective data sheet for additional information on configuration word. 

;***** VARIABLE DEFINITIONS 
STATUS     EQU      03h      ; variable used for context saving 
TRISA      EQU      85h        ; variable used for context saving 
PORTA      EQU      05H 
TRISB      EQU      86h 
PORTB      EQU      06h 
TempW	   EQU	    20h
SP0 	   EQU      21h
SP1 	   EQU      22h
SP2 	   EQU      23h


;*************************************************************
      ORG     0x000             ; processor reset vector 
      goto    main              ; go to beginning of program 

      ORG     0x004             ; interrupt vector location 

main    bsf     STATUS,5         ; bank 0 -----> bank 1 
	    movlw   b'11111111'       ; set the port b as inputs 
	    movwf   TRISB             ; 
	    movlw   b'00000000'       ; set the port a as outputs 
	    movwf   TRISA    
	    bcf     STATUS,5         ; bank 1 -----> bank 0 
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;setting setpoint
setpoint
		movlw 	.15
		movwf	SP0
		movlw 	.32
		movwf	SP1
		movlw 	.48
		movwf	SP2
;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
read
		movf	PORTB,w
		movwf	TempW

;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;test input with setpoints
Test
		btfss	TempW,SP0       ; TempW > SP0 ?
		goto	Out1			; No!
		btfss 	TempW,SP1		; TempW > SP1 ?
		goto	Out2			; No!
		btfss 	TempW,SP2		; TempW > SP2 ?
		goto	Out3			; No!
		goto	Test			; Retry
;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo    
Out1	movlw	1
		movwf	PORTA
		goto	read
            
Out2	movlw	2
		movwf	PORTA
		goto	read

Out3	movlw	3
		movwf	PORTA
		goto	read
		
;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

      END                     ; directive 'end of program'

thanks in advance
 
my pic read input, let say 25, it should jump to test second setpoint but it nots...it goes to next instruction to OUT1...why?...

if my input bigger than SP1, it should skip. why does it goes to next instruction...

what should i do?...
 
alamy said:
my pic read input, let say 25, it should jump to test second setpoint but it nots...it goes to next instruction to OUT1...why?...

if my input bigger than SP1, it should skip. why does it goes to next instruction...

what should i do?...

You can't use BTFSS - that just checks for a specific BIT being high or low.

You need to do a mathmatical test, you can use either SUBxx or XORxx to do so, then check the STATUS register.

I suggest you check the PICList, which has an entire section about comparisons!. A number of my tutorials also include code to do so.
 
i need some explaination ..

i found that before calling table using RETLW instruction ...sometimes they use ANDLW instruction, but sometimes not...

i do try both...by simulate the value ...it goes same ..the question is what is different by using/not the ANDLW instruction...and what for ?.

thanks...
 
alamy said:
i need some explaination ..

i found that before calling table using RETLW instruction ...sometimes they use ANDLW instruction, but sometimes not...

i do try both...by simulate the value ...it goes same ..the question is what is different by using/not the ANDLW instruction...and what for ?.

I usually use ANDLW before a table, the reason is to prevent the jump going too far - if you have seven values in the table and call it with 8 in W, you are in serious trouble. By ANDLW'ing it with b'00000111' the jump value can't be higher than seven. Obviously this only works with jump tables of a nice binary length, 3, 7, 15 etc.
 
thanks nigel...

but when using ANDLW..does it change our value?...

let say, if value is b'00000011' ANDLW b'00000111' equal to b'00010101'...but...it will jump to list no.3 in our table.? why?

thanks in advance
 
alamy said:
thanks nigel...

but when using ANDLW..does it change our value?...

let say, if value is b'00000011' ANDLW b'00000111' equal to b'00010101'...but...it will jump to list no.3 in our table.? why?

No, ANDLW won't change the value (as long as it's no longer than the AND value used, in this example b'00000111').

It logically AND's the two values together, it doesn't ADD them, that's ADDLW - all AND does is make the output bits '1' ONLY if both input bits are '1'. Essentially it masks the input value, which is what you need for a table.
 
ok..thanks nigel for the explaination...

i have another question..also about table..

if i have table with 256/127 values...can i have two tables or more?
how many tables can we put in ?

how do i know i reach the limit...is there any calculation?...

thanks in advance...
 
alamy said:
ok..thanks nigel for the explaination...

i have another question..also about table..

if i have table with 256/127 values...can i have two tables or more?
how many tables can we put in ?

how do i know i reach the limit...is there any calculation?...

thanks in advance...

You can have multiple tables, but it's easiest to make sure none of them cross a 256 byte boundary, and you have to ensure you set the paging bits correctly before you call them.

There are various schemes to do this automatically, and to allow tables larger than 256 bytes - I seem to remember someone posting details a while ago on this board.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top