Set PIC IO Pin High - Assembly Help

  • Thread starter Thread starter TylerH
  • Start date Start date
  • Tags Tags
    Assembly
Click For Summary

Discussion Overview

The discussion revolves around setting a PIC microcontroller pin high using assembly language. Participants explore issues related to pin configuration, simulator behavior, and hardware connections, focusing on the PIC16F628A model. The conversation includes technical details about register manipulation and clock configuration.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports that none of the pins, except Vdd and Vss, are high and questions if the PIC starts functioning immediately upon power-up.
  • Another participant suggests that the STATUS register bits may be incorrectly manipulated when switching memory banks and emphasizes the importance of checking the TRIS register settings for input/output configuration.
  • A third participant notes the absence of clock configuration directives in the provided code.
  • The original poster later specifies the PIC model as 16F628A and acknowledges forgetting to disable comparators on PORTA, which they believe affects the simulator's output.
  • Further, they inquire about necessary connections for proper operation, mentioning references to "pulling up" pins for reset functionality.
  • Participants discuss the correct initialization of PORTA and the disabling of comparators, along with adjustments made to the assembly code based on feedback received.

Areas of Agreement / Disagreement

Participants express differing views on the correct handling of the STATUS register and the necessary configuration for the PIC microcontroller. The discussion remains unresolved regarding the specific cause of the issue with the pin not being set high in the physical circuit.

Contextual Notes

Some participants highlight potential limitations in the original code, such as missing clock configuration and the need for additional connections beyond Vdd and Vss. There is also mention of the need to disable comparators, which may not have been initially considered.

TylerH
Messages
729
Reaction score
0
I need some help setting a pin high. I have tested all pins(incase I accidentally set the wrong one) with a multimeter, and none, other than Vdd and Vss, of course, were high. I also ran it in a simulator, and notice that the value at PORTA never changes, its always 0.

Is there something special I need to do to get it to start, or does it start as soon as it has current to Vdd and ground on Vss? Also, if it was fried, would a PICkit2 programmer, used with MPLAB, have an error message of some sort?

Code:
STATUS	equ 03h
PORTA	equ 05h
PORTB	equ 06h
TRISA	equ 85h
TRISB	equ 86h


start
	call	init
main
	movlw	02h
	xorwf	PORTA,01h
	
	movlw	0ffh
	call	delay
	call	delay
	goto	main


init
	bsf	STATUS,05h
	bcf	TRISA,01h
	bcf	STATUS,05h
	return


delay
	movwf	20h
wait
	decfsz	20h,01h
	goto	wait
	return
	
	end
 
Technology news on Phys.org
I think you may be wiggling the wrong bits in the STATUS register when swapping memory banks. I looked at the PCI16f81x data sheet (I use it a lot but in C, so don't remember ASM too good...) and it looks like bits 6&7 are the bank registers.

Also I believe setting a TRIS bit to 1 sets the pin to INPUT, not OUTPUT.

Check your spec sheet and see... or just try everything and anything in your simulator...
 
Also, I don't see your clock configuration directive.
 
Oh crap! feel like an idiot for not telling what PIC I'm using. It's a 16f628a.

schip666!: Mine uses <6:5> for normal bank selection, and 7 has something to do with indirect referencing and the bank it uses. You are correct that 0s in TRIS are for output, so I've corrected my code in that respect. I'd been forgetting to disable the comparators on PORTA, and after disabling them, the rights to PORTA show in the simulator's memory. Even though it seems to be working in the simulator, it doesn't do anything in my circuit.

Antiphon: I don't know the directives, I just use MPLAB's Configure->Configuration Bits menu option. What directives should I be using, or where could I learn them?

I've found a lot of references to "pulling up" pins to get it to reset. The only pins I have connected is +5V on Vdd and GND on Vss, should I have other things connected?

Also, here's my new code:
Code:
STATUS	equ 03h
PORTA	equ 05h
PORTB	equ 06h
CMCON	equ	1fh
TRISA	equ 85h
TRISB	equ 86hstart
	call	init
main
	call	switch
	movlw	0ffh
	call	delay
	btfsc	PORTA,01h
	call	delay
	goto	mainswitch
	movlw	0fh
	xorwf	PORTA,01h
	returndelay
	movwf	20h
wait
	decfsz	20h,01h
	goto	wait
	returninit
	clrf	PORTA
	
	; disable comparators on RA<4:0>
	movlw	0x07
	movwf	CMCON
	
	bsf	STATUS,05h

	; set RA<4:0> to out
	movlw	00h
	movwf	TRISA
	
	bcf	STATUS,05h
	return
	
	end
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K