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.

What's wrong with this code?

Status
Not open for further replies.

Wbdsgnr

New Member
I have got a PIR sensor, I amplified it, and now I want to use the comparator inside the 16f88. The reference signal is 5 volt with a variable resistance. Somehow it doesn't work, when lowering the reference voltage PORTB still gives a high output.. But maybe I'm just making a very stupid mistake?

Code:
		PROCESSOR 16F88
		#include "p16f88.inc"
		__config	0x1F04
		
		ORG			0x00
		goto			Main
		ORG			0x04
		goto			INR
	
Main		banksel		TRISA
		movlw		b'11100111'		
		movwf		TRISA
		clrf			TRISB
		movwf		TRISB
		banksel		PORTB
		movlw		b'11111111'
		movwf		PORTB
		
		
		banksel		CMCON
		movlw 		b'00000101'
		movwf		CMCON
		
		banksel		PIE2
		bsf			PIE2,CMIE
		banksel		INTCON
		bsf			INTCON,PEIE
		bsf			INTCON,GIE
		
INR
		banksel		PORTB
		movlw		b'00000000'
		goto 			INR
		
		RETFIE
			
End
 
Code:
      PROCESSOR 16F88 
      #include "p16f88.inc" 
      __config   0x1F04 
       
      ORG         0x00 
      goto         Main 
      ORG         0x04 
      goto         INR 
    
Main      banksel      TRISA 
      movlw      b'11100111'       
      movwf      TRISA 
      clrf         TRISB 
;      movwf      TRISB            <- what's this for?
      banksel      PORTB 
      movlw      b'11111111' 
      movwf      PORTB 
       
       
      banksel      CMCON 
      movlw       b'00000101' 
      movwf      CMCON 
       
      banksel      PIE2 
      bsf         PIE2,CMIE 
      banksel      INTCON 
      bsf         INTCON,PEIE 
      bsf         INTCON,GIE 
LOOP
      goto       LOOP          ; You don't want to fall to INR.
       
INR 
      banksel      PORTB 
      movlw      b'00000000' 
      movwf      PORTB      ; <-- maybe you need this?
      goto          INR 
       
      RETFIE 
          
End
 
motion said:
Code:
   INR 
      banksel      PORTB 
      movlw      b'00000000' 
      movwf      PORTB      ; <-- maybe you need this?
      goto          INR 
       
      RETFIE

This routine doesn't ever exit, the 'goto INR' will keep it in a permanent loop - presumably it's only partly written so far?.
 
Nigel Goodwin said:
motion said:
Code:
   INR 
      banksel      PORTB 
      movlw      b'00000000' 
      movwf      PORTB      ; <-- maybe you need this?
      goto          INR 
       
      RETFIE

This routine doesn't ever exit, the 'goto INR' will keep it in a permanent loop - presumably it's only partly written so far?.

Thanks guys, I'll try it right away. Yes it's just a test, later it should set a relay and stuff, but I first wanted to get this straight so later on I could be sure nothing is wrong with this part of the code.
 
In the finished version, since you used the W and STATUS registers, don't forget to save their context at the beginning of INR and restore them prior to RETFIE.
 
PROCESSOR 16F88
#include "p16f88.inc"
__config 0x1F04

ORG 0x00
goto Main
ORG 0x04
goto INR

Main
banksel TRISA
movlw b'11100111'
movwf TRISA
clrf TRISB <- you wont need this
; movwf TRISB <- if you will not use the PORTB then you dont need to setup it's direction

banksel PORTB

movlw b'11111111' <- high output in PORTB is because of this
movwf PORTB <-----------------------'


banksel CMCON
movlw b'00000101'
movwf CMCON

banksel PIE2
bsf PIE2,CMIE
banksel INTCON
bsf INTCON,PEIE
bsf INTCON,GIE
LOOP
goto LOOP ; The program will stuck here 4ever, instead of runing the port value for your control logic

INR
banksel PORTB
movlw b'00000000'
movwf PORTB ; <-- maybe you need this? (motion is right !!)
goto INR

RETFIE

End


If you don't know how to program in assembler why don't you try C ??
You have many C compilers for the Pic Family for the 16XXX you need the MPLAB C16 and obviously the IDE too :)

Anyway the code is a little bit confuse since i don't know what you really whant to make.

Well greetings from Portugal !! :D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top