Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

HELP Me i need someone solve my code program!!

Status
Not open for further replies.

am9

New Member
i doing my final project on ultrasonic distance meter am using PIC 16f84 ... i did a program but i faced some mistakes in the code's can anyone help and check the program code for me plzzzz !!


this the my program code :- **broken link removed**
 
program code

i doing my final project on ultrasonic distance meter am using PIC 16f84 ... i did a program but i faced some mistakes in the code's can anyone help and check the program code for me plzzzz !!


this the my program code :- **broken link removed**

You want us to download an EXE file to our computer to check your code. Yeah Right!!:eek:

Why not show us the code here?:confused:
 
micro I'm not sure what you're talking about it's a .asm file he posted.
I'll repost it for him.

AM9 for future posts please note that in the advanced posting options you can upload a variety of file types.
 

Attachments

  • ultrasonic distance code.ASM
    7.6 KB · Views: 130
Last edited:
You want us to download an EXE file to our computer to check your code. Yeah Right!!:eek:

Why not show us the code here?:confused:

It's an asm file not exe, what did you open?

Only problem I saw that I can tell you is that "send" does not exist and perhaps you are missing a "Call send" but yea there is no send loop

Mike
 
I verified the extension after downloading and opened it directly in a text editor, micro must have had some other complication, misclick for downloading or a browser oddity.
 
Sceadwian thank u am new here next time i'll upload here :) ... plzz can u edit my code program coz i dont know whats wrong with .. if call send is missing can add it .. :)
 
I can't, don't program pic =) Your code is incomplete. We can't complete it because we don't know where you got it from.
 
Last edited:
micro I'm not sure what you're talking about it's a .asm file he posted.
I'll repost it for him.

AM9 for future posts please note that in the advanced posting options you can upload a variety of file types.

I don't know what happened, but when I clicked on the link it showed up as an .exe file, but it's fine now.
Danm index finger got me in trouble again!:eek:
 
I just assembled that code and it appears to assemble correctly.

Here it is after I ran it through my code tidy program,
Code:
;Processor 16F84 
;
;

	errorlevel	-302

		org	0h		;start from 0000h
		goto	START		;start main program
		org	4h		;interrupt vector
		goto	isr		;interrupt routine at isr
;
Pc		equ	02h
STATUS		equ	03h
TRISA		equ	85h
PORTA		equ	05h
TRISB		equ	86h
PORTB		equ	06h
INTCON		equ	0bh
OPTN		equ	81h
LOOP		equ	0Ch
TEMP		equ	0Fh
Dist		equ	22H
TMR0		equ	01h
Count1		equ	23h
Value		equ	24h
lsd		equ	25h
Msd		equ	26h
bigmsd		equ	27h
delay1		equ	28h
delay2		equ	29h
r0		equ	30h
r1		equ	31h
;
;**********set up the ports A and b**********  
;
START
		bsf	STATUS,5	;select bank1
		movlw	B'00000'	;set PORTA pins as o/p
		movwf	TRISA		;setting the port A bits
		movlw	B'00000101'	;move 00000101 to w
		movwf	TRISB		;setting RB0 as input for interrupt
		movlw	B'00000000'	;set the prescalar for TMR0 registsr
		movwf	OPTN		;as 1:2
		clrf	INTCON		;disable all interrupts
		bcf	STATUS,5	;select bank0


;**********check if the switch is closed*********  
;
SWITCH1		btfss	PORTB,2		;read the switch,skip if closed
		goto	SWITCH1
;
;***********send 40KHz signal***********  
;
		movlw	D'10'		;move decimal 10 to w to generate 10 cycles of 40 KHz signal
		movwf	LOOP		;move decimal 10 to location 0c
		movlw	b'00100'	;load the initial value to PORTA
		movwf	PORTA
;
Send		nop			;send 40KHz signal
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		comf	PORTA,F		;toggle RA1/RA2 bits
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		comf	PORTA,F		;toggle RA1/RA2
		decfsz	LOOP,F		;decrement loop by 1 skip if zero
		goto	SEND
		clrf	PORTA
;
;***********mask delay 1.8ms***************  
;
		movlw	d'255'		;255x7=1.8ms for mask
		movwf	delay1
		movlw	d'7'
		movwf	delay2
;
Delay		decfsz	delay1,f	;delay loop for 1.8ms for mask
		goto	delay
		decfsz	delay2,f
		goto	delay

;****************enable interrupts********************  
		bsf	INTCON,4	;enable RB0 interrupt
		bsf	INTCON,7	;enable global interrupt
;
;********************start  timer****************  
;
		clrf	TMR0		;clear TMR0 register
		clrf	value
		movlw	d'75'		;move 75 to count1.prescalar is 1:2 so when
					;TMR0 reaches
		movwf	count1		;75 time taken will be 150us or 0.15ms
					;eqt to 1 inch
					;
loop1		movf	count1,0	;move 17 to w
		subwf	TMR0,0		;check whether TMR0 is 75
		btfss	STATUS,0
		goto	loop1		;if not 70 go back to loop
		clrf	TMR0		;if 75 clear TMR0 and
		incf	value,f		;increment value
					;
		movf	value,0
;              sublw d'12  
;              btfss STATUS,2  
;              goto loop1  

Isr		movlw	d'12'		;1.8ms is equivalent to 12 inches
		addwf	value,f		;add the eqt distance of mask to final result
;              call daa         ;call decimal adjust routine  
;
;********************convert the count to decimal***************  
		Movf	value,0		;load the number to convert
		call	con_bcd		;convert the tens and units
		movf	msd,w		;load the tens into w for hundred conversion
					;(tens>9) 
		call	con_big		;convert the tens into hundreds (tens>9)
		goto	display
Over            nop 
		goto	over
;
Con_bcd		clrf	msd		;clear the msd
Movwf1sd				;move the number to convert into 1sd 
Ten		movlw	d'10'		;load the constant 10
		subwf	lsd,w		;subtract 10 from 1sd
		btfss	STATUS,0	;check if answer negative
		goto	done		;conversion complete,jump to done
		Movwf	lsd		;save the answer back in 1sd 
		incf	msd,1		;increment the msd
		goto	ten		;do the routine again
Done		return			;return to caller
Con_big		clrf	bigmsd		;clear hundreds
		movwf	msd		;move the hundreds number to msd
Hund		movlw	d'10'		;load the constant 10
		subwf	msd,w		;subtract 10 from msd
		btfss	STATUS,0	;check if answer negative
		goto	hundone		;conversion complete, jump to hundred done
		movwf	msd		;save the answer back in msd
		incf	bigmsd,1	;increment the bigmsd
		goto	hund		;do the routine again
hundone		return			;return to caller
;
;*******************display****************************  
;
Display		bsf	STATUS,5	;bank1
		clrf	TRISA		;set portA all output
		movlw	d'0'
		movwf	PORTB		;set portb all output
		bcf	STATUS,5	;bank0
		movlw	d'3'		;disable common anode of both displays
		movwf	PORTA

Display1	movf	lsd,w		;place copy of value in w
		andlw	0x0f		;mask off upper nibbe
		call	table		;get 7 segment data from table and output from port B
		movwf	PORTB
		bcf	PORTA,1		;enable common anodes of led1
		call	dly5ms		;delay for 5ms
		movlw	0xff		;turn off portB
		movwf	PORTB
		bsf	PORTA,1		;disable common anodes of led1

		movf	msd,w		;exchange upper and lower nibbles of value and put in w
		swapf	value,w
		andlw	0x0f		;mask off upper nibble
		call	table		;get 7 segment data from table
		andlw	b'01111111'	;add decimal point
		movwf	PORTB		; output from PORTB
		bcf	PORTA,0		;enable common anodes for led2
		call	dly5ms		;delay for 5ms
		movlw	0xff		;turn off PORTB
		movwf	PORTB
		bsf	PORTA,0		;disable common anodes of led2
		goto	display1
;
;
;*******************decimal adjustment******************  
;
Daa		movf	value,w		;copy value to q
		andlw	0x0f		;mask off upper nibble
		sublw	d'9'		;subtract w from 9
		btfsc	STATUS,0	;check for borrow (c=0)
		goto	daa1		;no borrow so go to daa1
		movlw	d'6'		;w>9 so add 6 to value
		addwf	value,f

Daa1		swapf	value,w		;exchange upper and lower nibbles of value and put in w
		andlw	0x0f		;mask off upper nibble of w
		sublw	d'9'		;subtract w from 9
		btfsc	STATUS,0	;check for borrow (c=0)
		goto	daa2		;no borrow so go to daa2
		movlw	0x60		;w>0 (90) so add 60 to value
		addwf	value,f
Daa2		return
;
;***************5ms delay dynamic display********************  
;
Dly5ms		movlw	d'10'		;(165*3+5)*10 = 5ms
		movwf	r0

Dly5ms1		movlw	d'165'		;move 165 to w
		movwf	r1

Dly5ms2		decfsz	r1,f
		goto	dly5ms2
		decfsz	r0,f
		goto	dly5ms1
		retlw	d'0'
;
;*************************loop up table*****************  
;
Table		addwf	pc,f

		retlw	h'c0'		;0
		retlw	h'f9'		;1
		retlw	h'a4'		;2
		retlw	h'b0'		;3
		retlw	h'99'		;4
		retlw	h'92'		;5
		retlw	h'82'		;6
		retlw	h'f8'		;7
		retlw	h'80'		;8
		retlw	h'90'		;9

		end

For it to assemble case sensitivity needs turning off.

Mike.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top