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.

Still remain no output from portB

Status
Not open for further replies.

babboy12345

New Member
i had been build all my program....no any error,and i burn into my MCU and try it,but i still cannot get the output from portB,any1 can tell me why??

Code:
		LIST P=16F877A
		INCLUDE "P16F877a.inc"
		__CONFIG _CP_OFF & _WDT_OFF & _HS_OSC & _PWRTE_ON

		CHK1 	EQU 	0X21
		CNT1	EQU	0x22
		CNT2	EQU  	0x23

		count	EQU		0x20
		org		0x000
		nop		
		
		BSF		STATUS,RP0
		
		MOVLW	H'FF'
		MOVWF	TRISA
		movlw	H'00';
		movwf	TRISB;

		banksel	PORTA	
		BCF	STATUS,RP0
		clrf 	PORTB

		banksel	ADCON1
		movlw	b'10000000'
		movwf	ADCON1

		banksel	ADCON0
		movlw	b'10000001'
		movwf	ADCON0

getAD	movlw	007
		movwf	count
down	decfsz	count
		goto	down

		bsf		ADCON0,GO
wait	btfsc	ADCON0,GO
		goto	wait
		return		

delay	MOVLW	D'5'
		MOVWF	CNT2

CON1	MOVLW	H'FF'
		MOVWF	CNT1
		DECFSZ	CNT1,1
		GOTO	$-1
		DECFSZ	CNT2,1
		GOTO	CON1
		RETURN


start	call 	getAD		; get adc result store at adresh
		movlw	0xC8		; 
		subwf	ADRESH,1	; adc result in adresh will minus....
		btfsc	ADRESH,0	;...C8 and the answer store at adresh again..
		goto 	start		; if answer in adresh is not 0....then the program will jump to start again...
		btfsc	ADRESH,1
		goto 	start
		btfsc	ADRESH,2
		goto 	start
		btfsc	ADRESH,3
		goto 	start
		btfsc	ADRESH,4
		goto 	start
		btfsc	ADRESH,5
		goto 	start
		btfsc	ADRESH,6
		goto 	start
		btfsc	ADRESH,7
		goto 	start
		bsf     PORTB,1
		call 	delay
		END

say it cleary,i'm not familiar with writing,but i try many time to solve my program problems,but problems still occur,so i really need a help from you all. hundred thanks for those reply this thread!
 
hi,
Your program will crash after the Init and delays because of the RETURN after the 'wait'..

Code:
	LIST P=16F877A
		INCLUDE "P16F877a.inc"
		__CONFIG _CP_OFF & _WDT_OFF & _HS_OSC & _PWRTE_ON

		CHK1 	EQU 	0X21
		CNT1	EQU	0x22
		CNT2	EQU  	0x23

		count	EQU		0x20
		org		0x000
		nop		
		
		BSF		STATUS,RP0
		
		MOVLW	H'FF'
		MOVWF	TRISA
		movlw	H'00';
		movwf	TRISB;

		banksel	PORTA	
		BCF	STATUS,RP0
		clrf 	PORTB

		banksel	ADCON1
		movlw	b'10000000'
		movwf	ADCON1

		banksel	ADCON0
		movlw	b'10000001'
		movwf	ADCON0

;;; [COLOR="Blue"]THE PROGRAM WILL ENTER HERE AFTER THE INTIALISING[/COLOR]

getAD	movlw	007
		movwf	count
down	decfsz	count
		goto	down

		bsf		ADCON0,GO
wait	btfsc	ADCON0,GO
		goto	wait
		[COLOR="Blue"]return	;;;;;;;;; RETURN TO WHERE	 on 1st pass .???
[/COLOR]
delay	MOVLW	D'5'
		MOVWF	CNT2

CON1	MOVLW	H'FF'
		MOVWF	CNT1
		DECFSZ	CNT1,1
		GOTO	$-1
		DECFSZ	CNT2,1
		GOTO	CON1
		RETURN


start	call 	getAD		; get adc result store at adresh
		movlw	0xC8		; 
		subwf	ADRESH,1	; adc result in adresh will minus....
		btfsc	ADRESH,0	;...C8 and the answer store at adresh again..
		goto 	start		; if answer in adresh is not 0....then the program will jump to start again...
		btfsc	ADRESH,1
		goto 	start
		btfsc	ADRESH,2
		goto 	start
		btfsc	ADRESH,3
		goto 	start
		btfsc	ADRESH,4
		goto 	start
		btfsc	ADRESH,5
		goto 	start
		btfsc	ADRESH,6
		goto 	start
		btfsc	ADRESH,7
		goto 	start
		bsf     PORTB,1
		call 	delay
		END
 
Last edited:
i change the 1st part le....so the remaining,how to solve it???

Code:
		LIST P=16F877A
		INCLUDE "P16F877a.inc"
		__CONFIG _CP_OFF & _WDT_OFF & _HS_OSC & _PWRTE_ON

CHK1 	EQU 	0X21
CNT1	EQU		0CH
CNT2	EQU		0DH

count	EQU		0x20
		org		0x000
		nop		
		
		BSF		STATUS,RP0
		
		MOVLW	H'FF'
		MOVWF	TRISA
		movlw	H'00';
		movwf	TRISB;

		banksel	PORTA	
		BCF		STATUS,RP0
		clrf 	PORTB

		banksel	ADCON1
		movlw	b'10000000'
		movwf	ADCON1

		banksel	ADCON0
		movlw	b'10000001'
		movwf	ADCON0
		goto	start

getAD	movlw	007
		movwf	count
down	decfsz	count
		goto	down

		bsf		ADCON0,GO
wait	btfsc	ADCON0,GO
		goto	wait
		return		

delay	MOVLW	D'5'
		MOVWF	CNT2

CON1	MOVLW	H'FF'
		MOVWF	CNT1
		DECFSZ	CNT1,1
		GOTO	$-1
		DECFSZ	CNT2,1
		GOTO	CON1
		RETURN


start   call 	getAD		; get adc result store at adresh
		movlw	0xC8		; 
		subwf	ADRESH,1	; adc result in adresh will minus....
		btfsc	ADRESH,0	;...C8 and the answer store at adresh again..
		goto 	start		; if answer in adresh is not 0....then the program will jump to start again...
		btfsc	ADRESH,1
		goto 	start
		btfsc	ADRESH,2
		goto 	start
		btfsc	ADRESH,3
		goto 	start
		btfsc	ADRESH,4
		goto 	start
		btfsc	ADRESH,5
		goto 	start
		btfsc	ADRESH,6
		goto 	start
		btfsc	ADRESH,7
		goto 	start
		bsf     PORTB,1
		call 	delay
		END



my project is i use frequency generator as input (1v sine wave) to MCU,after ADC,the MCU will minus the 1v,then becum zero,if zero,turn on portb. If after minus not equal to zero, redo again until get zero.
 
my project is using music as a input, and the analog input go to MCU. MCU will ADC the input and minus with the value what i set. For example, i was set subtract the adresh value with 0xC8(this stand for 1v), if my input also 1v, then will have zero there,if zero, the MCU will turn on my portB. Portb will send a signal to relay to turn on my water pump. Is that clear???because my english language is poor,if not understand,i will explain it again
 
How are you going to tell the difference between noise and music? You need a form of tone decoding or dsp if you want it to be tone driven otherwise any noise will trigger your relay.
 
I MODIFY MY PROGRAM AGAIN,IS THAT NOW ALL CORRECT???

Code:
		LIST P=16F877A
		INCLUDE "P16F877a.inc"
		__CONFIG _CP_OFF & _WDT_OFF & _HS_OSC & _PWRTE_ON

CHK1 	EQU 	0X21
CNT1	EQU		0CH
CNT2	EQU		0DH

count	EQU		0x20
		org		0x000
		nop		
		
		BSF		STATUS,RP0
		
		MOVLW	H'FF'
		MOVWF	TRISA
		movlw	H'00';
		movwf	TRISB;
		BCF		STATUS,RP0
		
  		BANKSEL	PORTA	
		clrf 	PORTB

		BANKSEL	ADCON1
		movlw	b'10000000'
		movwf	ADCON1

		BANKSEL	ADCON0
		movlw	b'10000001'
		movwf	ADCON0
		goto	start



getAD	bsf		ADCON0,GO
		btfsc	ADCON0,GO
		goto	$-1 
		
		movf	ADRESH,W
		return		

delay	MOVLW	D'5'
		MOVWF	CNT2

CON1	MOVLW	H'FF'
		MOVWF	CNT1
		DECFSZ	CNT1,1
		GOTO	$-1
		DECFSZ	CNT2,1
		GOTO	CON1
		RETURN


start   call 	getAD		; get adc result store at adresh
		movlw	0x29		; 
		subwf	ADRESH,1	; adc result in adresh will minus....
		btfsc	ADRESH,0	;...C8 and the answer store at adresh again..
		goto 	start		; if answer in adresh is not 0....then the program will jump to start again...
		btfsc	ADRESH,1
		goto 	start
		btfsc	ADRESH,2
		goto 	start
		btfsc	ADRESH,3
		goto 	start
		btfsc	ADRESH,4
		goto 	start
		btfsc	ADRESH,5
		goto 	start
		btfsc	ADRESH,6
		goto 	start
		btfsc	ADRESH,7
		goto 	start
		bsf     PORTB,1
		call 	delay
		END
 
hi.
The call to getAD, loads the Wreg with ADRESH, as soon as it RETURNs to the calling subr, you are immediately overwriting the Wreg with 0x29.!!

Can you tell us exactly what you want the program to do.?


Code:
getAD		bsf	ADCON0,GO
		btfsc	ADCON0,GO
		goto	$-1 
		
		movf	ADRESH,W   [COLOR="Blue"];you are saving ADRESH in W, then RETURNING[/COLOR]
		return		

delay	MOVLW	D'5'
		MOVWF	CNT2

CON1	MOVLW	H'FF'
		MOVWF	CNT1
		DECFSZ	CNT1,1
		GOTO	$-1
		DECFSZ	CNT2,1
		GOTO	CON1
		RETURN


start   call 	getAD		; get adc result store at adresh
		movlw	0x29	; [COLOR="Blue"]you are now replacing the ADRESH value with 29h...!!!!!![/COLOR]
 
		subwf	ADRESH,1	; adc result in adresh will minus....
 
Last edited:
actually i want to send a 0.1V sine wave from frequency generator to PIC to convert from A to D. After convert ,i will subtract it with 0x29 (0x29 = 0.1V). If i get value equal to zero,it will show me the output.This is my code after modification, is that still got any error?

Code:
		LIST P=16F877A
		INCLUDE "P16F877a.inc"
		
status	EQU	0x03
TRISA	EQU	0X85
PORTA	EQU	0X05
TRISB	EQU	0X86
PORTB	EQU	0X06
CHK1 	EQU 	0X21
CNT1	EQU	0CH
CNT2	EQU	0DH
count	EQU	0x20h
NumH	equ	0x22h

		org		0x000
		nop		
		
		BSF		STATUS,RP0
		
		MOVLW	H'FF'
		MOVWF	TRISA
		movlw	H'00';
		movwf	TRISB;

		banksel	PORTA	
		BCF		STATUS,RP0
		clrf 	PORTB

		banksel	ADCON1
		movlw	b'10000000'
		movwf	ADCON1

		banksel	ADCON0
		movlw	b'10000001'
		movwf	ADCON0
		goto	start

getAD		bsf	ADCON0,GO
		btfsc	ADCON0,GO
		goto	$-1
		
		banksel	ADRESH
		movf 	ADRESH,w
		movwf	NumH
		return		

delay		MOVLW	D'5'
		MOVWF	CNT2

CON1		MOVLW	H'FF'
		MOVWF	CNT1
		DECFSZ	CNT1,1
		GOTO	$-1
		DECFSZ	CNT2,1
		GOTO	CON1
		RETURN

start	call 	getAD		; get adc result store at NumH
		sublw	0x29	 ;adc result in NumH will minus with 0x29....
		btfss	status,2 ;jump to  bsf if after subwf is = zero
		goto	start	;if not = zero,start again
		bsf	PORTB,0
		call	delay
		end
 
Last edited:
CNT1,CNT2 they are override PIR1,PIR2 if you use PIEx interrupt it has big problem,

As you set for ADCONx, your Pic recomment run at max 1.25Mhz and 10bit result:
ADRESH=0-3, ADRESL=0-0xFF , xxxxxx11 11111111
so you never get ADRESH=0x29

if you clear bit7 of ADCON1 then result 11111111 11xxxxxx ,this good if you just want only 8bit value
ADRESH=0-0xFF ADRESL=11xxxxxx use only bit7 & bit6
check datasheet 16f877A ,chapter 11 for correct value
Code:
getAD		bsf	ADCON0,GO
	[COLOR="Red"];wait 20uS or more for ADC internal work[/COLOR]
	btfsc	ADCON0,GO
		goto	$-1
;;;;
;;;;
		call	delay
     [COLOR="Red"] still run, till the end of memory then start from 0  [/COLOR]
		end

actually i want to send a 0.1V sine wave from frequency generator to PIC to convert from A to D. After convert ,i will subtract it with 0x29 (0x29 = 0.1V). If i get value equal to zero,it will show me the output.This is my code after modification, is that still got any error?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top