Having trouble reading input values in PIC assembly programming?

In summary, the conversation is about learning how to program in assembly for PICs and encountering difficulties in reading input values. The code was initially set up for analog inputs, but after changing them to digital inputs, the issue was resolved. The code is also provided for future reference.
  • #1
rsegecin
2
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
  • #2
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?
 
  • #3
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
 

Related to Having trouble reading input values in PIC assembly programming?

1. What is Pic Assembly programming?

Pic Assembly programming is a low-level programming language used to write code for microcontrollers and embedded systems. It is a form of assembly language specifically designed for PIC (Peripheral Interface Controller) microcontrollers.

2. What are the advantages of using Pic Assembly programming?

One of the main advantages of Pic Assembly programming is that it allows for direct control over hardware components, making it ideal for developing low-level programs and applications. It also has a smaller memory footprint and can run faster than higher-level programming languages.

3. How is Pic Assembly programming different from other programming languages?

Pic Assembly is a low-level language, meaning that it is closer to the machine language of the microcontroller and requires a deep understanding of the hardware. It uses mnemonic codes to represent machine instructions and is usually written in a text editor rather than a dedicated development environment.

4. What are some common applications of Pic Assembly programming?

Pic Assembly programming is commonly used in the development of embedded systems, such as in industrial control, robotics, and consumer electronics. It is also used for applications that require precise timing and control, such as in medical devices and scientific instruments.

5. Is Pic Assembly programming difficult to learn?

Pic Assembly programming may be more challenging to learn compared to higher-level languages, as it requires a good understanding of computer architecture and hardware. However, with practice and dedication, it can be a valuable skill for developing low-level applications and systems.

Similar threads

  • Programming and Computer Science
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Electrical Engineering
Replies
2
Views
2K
  • Electrical Engineering
Replies
10
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Electrical Engineering
Replies
9
Views
2K
  • Electrical Engineering
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
6K
  • General Engineering
Replies
2
Views
3K
Back
Top