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.

[PIC] output problem in PIC microcontroller

Status
Not open for further replies.

Ghosh Debalina

Newbie level 5
Joined
Mar 6, 2014
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
60
I am trying to get output from PIC16f874a.I have written the following program but unablwe to get high output voltage so led is not glowing. Can anybody help me.its urjent.
Code:
#include <p16f874A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BOREN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
Status EQU 03h
TRISB EQU 86h
PORTB EQU 06h
LED EQU 0x05
CBLOCK 0x20
; Variables used in delay routine
Kount100us
Kount1ms
Kount100ms
ENDC
org 0x0000 ; processor reset vector
goto start
org 0x04 ; go to beginning of program
start: 
BANKSEL TRISB 
bcf TRISB,LED
BANKSEL PORTB
;CLRF PORTB ; switch to bank1

loop:
bsf PORTB,LED
call delay100ms ;TURN the muscle on by first putting it into
bcf PORTB,LED
call delay100ms
goto loop
delay100us:
movlw 0xA5
movwf Kount100us
R100us decfsz Kount100us
goto R100us
return
delay1ms:
movlw 0x0A
movwf Kount1ms
R1ms call delay100us
decfsz Kount1ms
goto R1ms
return
delay100ms:
movlw 0x64
movwf Kount100ms
R100ms call delay1ms
decfsz Kount100ms
goto R100ms
return
END
 

Hi,

Your code is difficult to read, because it is unformatted an not very good documented.

I just read the last lines.
Goto....
Return...
End..


The program may never reach the "return". Check if this is what you want.
 

You appear to be using MPLAB or MPLABX as your assembler. Please start by copying the template code Microchip supply to a new project then adding your own code to it. It will structure the program for you and also include the names of all the registers and bits in them so you don't have to do it yourself.

As for the actual program please note that any instruction in the first column will be treated as a label (Symbol) so it should not assemble without lots of errors.

The end lines are OK, just difficult to read. It's short loop toggling PORTB,5 followed by two subroutines to create delays but without indentation, blank lines and comments it isn't at all clear what they are.

Brian.
 

Code:
include <p16f874A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BOREN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

Status EQU  03h
TRISB  EQU  86h
PORTB  EQU 	06h
LED    EQU 	0x05

CBLOCK 0x20
; Variables used in delay routine
Kount100us
Kount1ms
Kount100ms
ENDC

org 0x0000 		; processor reset vector
	goto start

	org 	0x04 	; go to beginning of program
start: 

	bsf    status,rp0	 
	bcf    TRISB,LED
	bcf    status,rp0
				;CLRF PORTB ; switch to bank1

loop:
	
	bsf 	PORTB,LED
	call 	delay100ms 	;TURN the muscle on by first putting it into
	bcf 	PORTB,LED
	call 	delay100ms
	bsf 	PORTB,LED
	goto 	loop
	
delay100us:
	movlw 	0xA5
	movwf 	Kount100us
	
R100us 
	decfsz 	Kount100us,1
	goto 	R100us
	retlw   00
	
delay1ms:
	movlw 	0x0A
	movwf 	Kount1ms
	
R1ms 
	call 	delay100us
	decfsz 	Kount1ms,1
	goto 	R1ms
	retlw   00
	
delay100ms:
	movlw 	0x64
	movwf 	Kount100ms
	
R100ms 
	call 	delay1ms
	decfsz 	Kount100ms,1
	goto 	R100ms
	retlw   00
	
	
	
END
 

That's much better formatting but why remove the banksel directives and change all the return to retlw? They were correct before.
I still recommend using the Microchip template.

Brian.
 

The program appears to be correct from a casual read of it. You should post the circuit as well, you may have made a mistake. The first step in debugging a program like this is simply to get the LED to light. A 100mS is a bit fast but you should be able to see the LED flicker.
 

Now my circuit is working but problem is that i am getting led laways on. I have given 6 seconds delay to properly watch the on off of Leds but leds are not off. I have checked simulation resut in mpsim..it is showing correct result.Problem is in oscillator. i have measured the output if my 4 pin crystal 20 Mhz oscillator and in oscilloscope it is showing only 50 hz. I dont understand how to fix this problem?
 

Show me the 6 second delay
 

Now my Led s are working as per the program. Now problem is ,in output I am getting 2.5 volt while in output i have given 5 volt. Please help me in this case.
 

Now my Led s are working as per the program. Now problem is ,in output I am getting 2.5 volt while in output i have given 5 volt. Please help me in this case.

The answer you will find in ucontroller and led datasheet.
It' s hard to connect a dvm to your given code. ;-)

Do you really thik one can find out about voltage and currents with your given information?
Schematic, part numbers, datasheets. ???

Klaus
 

The answer you will find in ucontroller and led datasheet.
It' s hard to connect a dvm to your given code. ;-)

Do you really thik one can find out about voltage and currents with your given information?
Schematic, part numbers, datasheets. ???

Klaus

The output is 5v then 0v then 5v then 0v and the mid-voltage is 2.5v That is what you are detecting.
 

Hi,

What else do you expec t if you run a loop with 100ms ON and 100ms OFF?

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top