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.

Can anyone check this for me...?

Status
Not open for further replies.

RobertD

New Member
Short flasher program with weak PORTB pull up. The pull up doesn't work for me, PORTB stays all 0's. It used to work, now I don't know why it doesn't work anymore. It's the same one I use for my long program, and it works there.
I want to know if your pull up work. My PORTA is working fine, but PORTB doesn't go up like it's supposed to.
(I set the timer to 1 because it's faster to step through.)
(PS: Now the PORTA pin doesn't go up anymore...?!?!?)

Code:
	LIST	p=16F88
	include "P16F88.inc"
	__config _CONFIG1, _WDT_OFF &  _MCLR_ON &  _LVP_OFF

	TIMER1	EQU		0x20
	TIMER2	EQU		0x21

	org	0x00		;start of program

init
	banksel	OPTION_REG	;bank 1
	movlw	0x42		;8MHz internal osc
	movwf	OSCCON
	clrf	ANSEL		;all A pins digital
	movlw	0x00		;all A pins outputs
	movwf	TRISA 
	movlw	0xFF                ;all  B pins inputs
	movwf	TRISB
	movlw	0x00                 ;PORTB pull up
	movwf	OPTION_REG          
	banksel	PORTA	              ;select bank 0
	clrf	PORTA

main
           bsf         PORTA,6
	call	delay
	bcf	PORTA,6
	call	delay
  	btfss	PORTB,4
	goto	main



;____________________________________

delay
	MOVLW   D'1'          
             MOVWF   TIMER1          
               
DELAY2
	MOVLW	D'2'			
	MOVWF	TIMER2
	DECFSZ  TIMER2,F        
	GOTO    $-1             
               
	DECFSZ	TIMER1,F		
	GOTO	DELAY2				
	RETLW   0			


	

	end
 
Last edited:
In addition to the changes Gayan mentioned:
Code:
__config _CONFIG1, _WDT_OFF &  _MCLR_ON &  _LVP_OFF [COLOR="Red"]& _INTRC_IO[/COLOR]
You need to specify which oscillator is being used or RA6 may be dedicated to the RC oscillator output by default.
 
Last edited:
OK I did make the changes, PORTA works but PORTB registers don't go up, they remain all 0's, all the time. If your program works fine, then this suggest there may be a bug in my MPLAB software itself. My computer is not well protected from bugs.

Since I'm trying to make all PORTB pins 1's, why do you do this...?
Code:
main
	btfsc	PORTB,4
	goto	main
 
Last edited:
This is not a bug in MPLAB and the chances of you finding a bug are extremely small.

What is connected to the various ports?
How do you know the pullups aren't working?
What will happen if the btfsc PORTB,4 skips the goto main?

Mike.
 
There is nothing connected to the ports. It's just code to make portb 1's. It's an LED flasher code, but I'm just running the sim.

Does your MPLAB make PORTB 1's with this...? It's supposed to, with the weak pull up using the option_reg pull up. My program worked for a while using it, now it doesn't. And I'm just trying to see what I'm doing wrong by writing a program just to pull up PORTB, and also test PORTA outputs. PORTA works, but PORTB pullups don't.

Did you run the program to see if PORTB pullups work?
Also, if the pullups work, then PORTB,4 will be set, and the program will hang on main. That's why I ask; why is it necessary to have btfsc PORTB,4...? What is it with PORTB4 that needs to be checked?
 
Last edited:
When I run your code above I get all ones for port b except b6 which is zero due to the debugger. As I asked earlier, how do you know they aren't working? Are you metering the pins? Using PicKit2, ICD2 etc.

Mike.
 
When I run your code above I get all ones for port b except b6 which is zero due to the debugger. As I asked earlier, how do you know they aren't working? Are you metering the pins? Using PicKit2, ICD2 etc.

Mike.
I got all zeros for PORTB running the code under MPLAB SIM. Are you debugging the code with hardware?
BTW I have MPLAB v8.10 installed.


RobertD said:
Does your MPLAB make PORTB 1's with this...? It's supposed to, with the weak pull up using the option_reg pull up. My program worked for a while using it, now it doesn't. And I'm just trying to see what I'm doing wrong by writing a program just to pull up PORTB, and also test PORTA outputs. PORTA works, but PORTB pullups don't.

If you're simulating the code with MPLAB SIM, I'm not sure that it's supposed to set the inputs high, even if the pull-up reistors are enabled. The simulator can't know if you have some switches connected to PORTB and which their states are.
Fow switch debugging, I would probably use the Stimuls editor, ignoring for the moment that I have the pull-ups.
 
Last edited:
If your program works fine, then this suggest there may be a bug in my MPLAB software itself. My computer is not well protected from bugs.

In the MPLAB SIM Help file it clearly states under general limitations that "Weak pull-ups on ports not implemented"

Therefore if you're expecting to read Port B,4 and see a logic 1 because you enabled weak pull-ups that's not going to work while running the code under MPLAB simulator.
 
Are you debugging the code with hardware?
BTW I have MPLAB v8.10 installed.

I was using hardware and 8.10. I suspect the OP has made a simple mistake that is causing the problem. Something like selecting PK2 as programmer rather than debugger which will give the reported symptoms.

If the OP answers my earlier question (how do you know the pullups aren't working) we may be able to work out the source of the problem.

Mike.
 
Since I'm trying to make all PORTB pins 1's, why do you do this...?
Code:
main
	btfsc	PORTB,4
	goto	main
Gayan modified your code because it had a bug in it. He wrote that snippet above so that the LED would flash when bit4 on portB goes low by a switch. When the switch is open, the pin is pulled high by the weak pullups on a real life PIC.
Your code below:
Code:
  	btfss	PORTB,4
	goto	main

;____________________________________

delay
	MOVLW   D'1'          
             MOVWF   TIMER1          
               
DELAY2
	MOVLW	D'2'
would have caused the delay subroutine to be executed without a call instruction, causing the the stack to underflow repeatedly, when bit4 of portB was high. He fixed a bug for you. ;)
 
Last edited:
When I run your code above I get all ones for port b except b6 which is zero due to the debugger. As I asked earlier, how do you know they aren't working? Are you metering the pins? Using PicKit2, ICD2 etc.

Mike.

First of all, thanks guys, you are most helpful. I'm sorry to keep dragging you back to such elementary coding, but I really must finish this thing. And I want to assure you I am quite grateful for your help.

Pommie that's great, so the code is working. I am working in sim, and Geko said weak pullups are not implemented, so I assume there is another way to test for pullups, I tested in PK2debugging and released mode, and still get 0's. You said it might be OP error, I don't quite understand what you mean by that. I also found out the ANSEL register sets up both PORTA and PORTB at the same time on the 16F88, but since the code is working then ANSEL setup must be right. I don't understand what kchriste means by; 'causing the stack to underflow continually'. That code was just a test code for PORTA outputs and for PORTB pullups. I'm not concerned with switching the PORTB pins since I already have that working. I do need to have PORTB pullups working though, and that's what I'm concentrating on now.


UPDATE: Ok PORTB pullups work in PK2, and I got the PORTA pins to go up by resetting TRISA. Fantastic.

Now I have to find out why I can't get the values to transfer from the W register to the assigned registers, I moved the registers to 0x20, first spot, and still the value in W doesn't transfer after I add up, all the W0-5 registers, the total doesn't want to go from W to 'bottom_byte_reg' ....
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top