Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Assembly lanugage program for PIC16c74

Status
Not open for further replies.

sirdizel

Newbie level 3
Joined
May 17, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,310
Hello, this is my first time posting on this forum and I hope this is not an issue because im asking for help in my first post here.

I want to read in 2 analogue values, both between 0 -5 volts, i want to store them in appropriate registers. The two voltages are to be compared and appropriate result to be displayed on the LED's

port A = input

port B = output( i will have LEd's connected to bit 1 and 2)



If input A is greater than B then led 1 will turn on

If input B is greater than A then led 2 will turn on

If both inputs equal then both LEDs stay off

This is the code I have so far

Code:
list p=16c74 
org 0x01;
          
#include pic16c74.inc
#define count  

call ini

Reg1         equ       h'20'               	;set registers h20 i 21
Reg2         equ       h'21'

Movlw   	h'07'
Movwf cmcon                             	 ; komparator off
Clrf portb                                    	 ; portb as output


bsf                 status, rp0                                       ;bank1
movlw            b'00000110'                                 ;analogue inputs Ra0 and Ra1
movwf            adcon0                                        ; configure analogue inputs
bcf                 status,  r                                            ; bank 0

               ; ADC configure
movlw  b'11000001'        ; 
movwf adcon0                ;a/d config


              ; config
bcf intcon, gie           ; gie off

              ; conversion
conver: 
              ; channel 0

movlw           b'11000001'   	; set channel 0 
movwf           adcon0            ; start conversion
call delay            	; delay for result
bsf                adcon0, go       	; wait for result
btfsc             adcon0,go      	;check if ifnished
goto $-1
movf             adres, w       	; place the result in w register
movwf           reg1

              ; channel 1

movlw        b'11001001'   	;set channel 1 
movwf       adcon0                        ; start conversion
call delay            	; wait for the result
bsf	adcon0, go    	; wait
btfsc         adcon0,go        	;check if ifnished
goto $-1
movf        adres, w       	; send result into w reg
movwf      reg2

               ; comparision using substraction

Movlw, reg1         ;do roboczego wynik kana?u 0
Movlf, reg2         ; do roboczego wynik kana?u 1
Subwf reg1, f       ; odejmuje a wynik do w 
                                    

;if the result is less than 0 reg1>reg2 then C is reset

Btfss  status, c    ; check marker c
                            
                	; negative result operations
bsf  portb. 0      	;set port b.0
bcf  portb. 1      	; reset portb.1
goto conver
	
			; positive result operations
	Bcf portb.0                  
	Bsf portb.1                  ; set port, reset port
goto conver


delay                         ; delay to get the conversion
movlw           .8
movwf  count
incfsz count, f
goto $-1
return

this is as far as i could get and im not even sure if the whole concept is incorrect or just an error in the code, any help would be much appreciated.
 
Last edited:

Change your tabs into spaces to improve the formatting of your code when you post it. There should be an option for this in the editor.
Are you using Mplab Sim?
You can step through the code using the mplab simulator to see what is going on.
 

im using ancient piece of software called "icepic" with pic16c74 emulator board
 

im using ancient piece of software called "icepic" with pic16c74 emulator board

Hi,

Have cleaned up your code so it at least Builds when using Microchips MPLAB which you can download for free from Microchips site.

Have not run it to check your logic works correctly but at least its a start for you.

Code:
	list p=pic16C74
	#include <P16C74.inc>


;	#define count  


Reg1         equ       h'20'               	;set registers h20 i 21
Reg2         equ       h'21'
count	 	equ	       h'22'
 
	org 0x000  ; start location

;	call ini   ; call to no where   ***************************

;Movlw   	h'07'
;Movwf   cmcon                             	 ; komparator off   NOT ON C74 **********************************
	Clrf    portb                                 ; portb as output
	 
	
	bsf    status, rp0                            ;bank1
	movlw   b'00000110'                           ;analogue inputs Ra0 and Ra1
	movwf   adcon0                                ; configure analogue inputs
	bcf    status,  rp0                          ; bank 0
	
; ADC configure
	movlw  b'11000001'        ; 
	movwf adcon0                ;a/d config	
	              				; config
	bcf intcon, gie           ; gie off
	
	              ; conversion
conver: 
	              ; channel 0
	
	movlw   b'11000001'   	; set channel 0 
	movwf   adcon0            ; start conversion
	call    delay            	; delay for result
	bsf    adcon0, go       	; wait for result
	btfsc  adcon0,go      	;check if ifnished
	goto $-1
	movf     adres, w       	; place the result in w register
	movwf    reg1
	
	              ; channel 1
	
	movlw   b'11001001'   	;set channel 1 
	movwf   adcon0                        ; start conversion
	call    delay            	; wait for the result
	bsf 	adcon0, go    	; wait
	btfsc   adcon0,go        	;check if ifnished
	goto     $-1
	movf     adres, w       	; send result into w reg
	movwf    reg2
	
	               ; comparision using substraction
	
	Movlw reg1         ;do roboczego wynik kana?u 0
;	Movlf, reg2         ; do roboczego wynik kana?u 1                INVALID INSTRUCTION  *******
	Subwf reg1, f       ; odejmuje a wynik do w 
	                                    
	
	;if the result is less than 0 reg1>reg2 then C is reset
	
	Btfss  status, c    ; check marker c
	                            
	                	; negative result operations
	bsf  portb, 0      	;set port b.0      USE COMMA ,  NOT FULL POINT.  *****************
	bcf  portb,1      	; reset portb.1
	goto conver
		
				; positive result operations
		Bcf portb,0                  
		Bsf portb,1                  ; set port, reset port
	goto conver
	
	
delay                         ; delay to get the conversion
	movlw           .8
	movwf  count
	incfsz count, f
	goto $-1
	return

	END					; NEEDED
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top