Having trouble reading input values in PIC assembly programming?

AI Thread Summary
The discussion revolves around programming in assembly for PIC microcontrollers, specifically addressing issues with reading input values. The original code was not functioning as expected because the ports were configured as analog inputs by default. The user learned that to read discrete values (0 or 1), the ports needed to be set as digital I/O. The solution involved modifying the code to include configuration for the ANSEL register, ensuring that the relevant pins were set to digital mode. The updated code successfully implements this change, allowing for proper input reading and output control through blinking LEDs.
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
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Back
Top