Having trouble reading input values in PIC assembly programming?

Click For Summary
SUMMARY

The discussion centers on resolving issues related to reading input values in PIC assembly programming, specifically for the PIC16F688 microcontroller. The original code failed to read digital values due to the default configuration of the ports as analog inputs. The solution involved modifying the code to set the ANSEL register to zero, thereby configuring the ports as digital I/O. This adjustment allowed for proper reading of discrete values from the hardware ports.

PREREQUISITES
  • Understanding of PIC assembly language programming
  • Familiarity with the PIC16F688 microcontroller architecture
  • Knowledge of digital versus analog input configurations
  • Experience with manipulating registers such as ANSEL and TRISC
NEXT STEPS
  • Study the PIC16F688 datasheet for detailed register configurations
  • Learn about the differences between analog and digital I/O in PIC microcontrollers
  • Explore advanced assembly programming techniques for PICs
  • Investigate debugging methods for assembly code in embedded systems
USEFUL FOR

Embedded systems developers, electronics engineers, and students learning assembly programming for PIC microcontrollers will benefit from this discussion.

rsegecin
Messages
2
Reaction score
0
Hi. I'm learning how to program in assembly to PICs and I'm stuck quite a while in a problem trying to figure out how to read an input value. I've been googling a lot and it seems that my code it's fine but as I'm beginning to learn I would like to know if any of you guys could tell me if its really ok.

Code:
#include <P16F688.inc>

ORG 	0x00
goto 	main

main:
	banksel		TRISC
	movlw 		B'00000100'
	movwf		TRISC
	
loop:
	banksel		PORTC
	btfsc		PORTC, RC2
	call 		blinkRed
	
	btfss		PORTC, RC2
	call 		blinkGreen	
goto 	loop

blinkRed:
	banksel		PORTC
	bsf			PORTC, 1
	bcf			PORTC, 0
	;movlw 		B'00000010'
	;movwf		PORTC		
return

blinkGreen:
	banksel		PORTC
	bcf			PORTC, 1
	bsf			PORTC, 0
	;movlw 		B'00000001'
	;movwf		PORTC	
return

end

Thank you very much.
 
Technology news on Phys.org
Hey rsegecin and welcome to the forums.

I'm not familiar with this kind of assembler, but is the information you are trying to read meant to be coming from a hardware port?
 
Hi chiro thank your very much for the reply. I've just found out that if I left the code the way I mentioned in the post above the ports were configured by default as analog inputs therefore to get a discrete value 0, 1 wouldn't work as an analog input has to have some others configurations to work properly. So I just needed to set them as digitals IO.

I'm posting the code for future reference to others:

Code:
#include <P16F688.inc>

ORG 	0x00
goto 	main

main:
	banksel		ANSEL
	movlw 		B'00000000'
	movwf		ANSEL
		
	banksel		TRISC
	movlw 		B'00000100'
	movwf		TRISC

loop:
	banksel		PORTC

	btfsc		PORTC, 2
	call 		blinkRed	

	btfss		PORTC, 2	
	call 		blinkGreen
goto 	loop

blinkRed:
	banksel		PORTC
	movlw 		B'00000010'
	movwf		PORTC		
return

blinkGreen:
	banksel		PORTC
	movlw 		B'00000001'
	movwf		PORTC	
return

end
 

Similar threads

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