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.

testing the pic problem

Status
Not open for further replies.

Hetal

New Member
hii

i am trying to test my pic.. however i am incurring some problems.. i am doing a basic test of switchign on and off of the leds ..

here is the code i used

Code:
#include<P16f877.inc>

    LIST p=16F877
	errorlevel 1,-302	;to disable MPLAB bank warnings.
COUNT1 equ 08h 
org 0 


   bsf STATUS,5
	clrf TRISB
    clrf TRISC 
    clrf TRISD  
    bcf STATUS,5
 	    
       
LED 

	 	movlw	b'00000001'  ; red on
		movwf	PORTB
		call	Delay
	   	call	Delay
		movlw	b'00000000'  ; red oFF
		movwf	PORTB
	
	
		movlw	b'00000001'; yellow on
		movwf	PORTC
		call	Delay
	    movlw	b'00000000'  ; yellow off 
		movwf	PORTC
	
		movlw	b'00000001'; green on
		movwf	PORTD
		call	Delay
  		movlw	b'00000000'  ; green off 
		movwf	PORTD
		
	    goto    LED 		






Delay   decfsz COUNT1,1 
        goto Delay
		return
		

		



;********************************************************
;            END of control processing
;********************************************************
	end

my concern is that i can only see the red light blinking i cannot see all the lights blinking in an orderly fashion..

my second ques.. is my delay always starts from ff even though i have put my count value as 08h

:confused:
 
Hetal said:
my second ques.. is my delay always starts from ff even though i have put my count value as 08h

You haven't set your count value to anything, it will be a random value the first time it runs. If you want to initialise it to 8 you need to add initialisation lines to the beginning of your delay routine (check my tutorial delay routines).

Also, you're allocating the name 'count1' to a non-GPR address (actually to PortD), GPR's start at 0x20 on the 16F877.
 
thank u

well thanks ..

now i got my code to be like this

is it rite ?

Code:
#include<P16f877.inc>

    LIST p=16F877
	errorlevel 1,-302	;to disable MPLAB bank warnings.

cblock 	0x20 			;start of general purpose registers
		count1 			;used in delay routine
		counta 			;used in delay routine 
		countb 			;used in delay routine
	endc

org 0 


   bsf STATUS,5
	movlw 00h
    movwf TRISB 
    movwf TRISC 
    movwf TRISD   
    bcf STATUS,5
 	    
       
LED 

	 	movlw	b'00000001'  ; red on
		movwf	PORTB
		call	Delay
	   	call	Delay
		movlw	b'00000000'  ; red oFF
		movwf	PORTB
	
	
		movlw	b'00000001'; yellow on
		movwf	PORTC
		call	Delay
	    movlw	b'00000000'  ; yellow off 
		movwf	PORTC
	
		movlw	b'00000001'; green on
		movwf	PORTD
		call	Delay
  		movlw	b'00000000'  ; green off 
		movwf	PORTD
		
	    goto    LED 		





Delay	movlw	d'500'			;delay 500 ms (20 MHz clock)
	    movwf	count1
d1  	movlw	0xC7
    	movwf	counta
    	movlw	0x01
	   movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	retlw	0x00


		

		



;********************************************************
;            END of control processing
;********************************************************
	end

is it rite that if i put 500 ms since i have a 20 mhz clock?


when i simulate it..its taking forever..for the delay loop, howevr is it that when i place it on the board it will be fine?

thnks
 
Hetal said:
is it rite that if i put 500 ms since i have a 20 mhz clock?

It can't be, because you can't put 500 into an eight bit variable, the maximum possible value is 255.

when i simulate it..its taking forever..for the delay loop, howevr is it that when i place it on the board it will be fine?

thnks

As the simulator isn't real time, it will take ages! - but I never use simulators!.
 
still not workign

oki have changed the code aand put d'255' instead of d'500'

i tried the circuit i am still geting only the red light on.. which is conected to pin rb0 the others are nto even lighting.. moreover my pic is also heating up quite fast
 
Hetal said:
oki have changed the code aand put d'255' instead of d'500'

i tried the circuit i am still geting only the red light on.. which is conected to pin rb0 the others are nto even lighting.. moreover my pic is also heating up quite fast

Do you have series resistors feeding the LED's?, and what value are they?.
 
series resistance

the series resistance is 56 ohms for all three and my leds are arnd 3 volts (7mm led)
 
Hetal said:
the series resistance is 56 ohms for all three and my leds are arnd 3 volts (7mm led)

That would be around 35mA per LED, which is rather high - but as the others aren't even lighting I would suggest you check for shorts, you may be shorting the outputs.

Another obvious thing you're not doing, is disabling the analogue inputs - these are ON by default, you need to disable those if you're not using them.
 
Nigel Goodwin said:
Another obvious thing you're not doing, is disabling the analogue inputs - these are ON by default, you need to disable those if you're not using them.


but arnt only port a pins.. also anlogue inputs , i am using port c,d,b

i chekd the circuitry .. i dont htink ihave shorted any outputs.. however i have noticed somehting .. when i remove the vss pin. on pin 12 from the right side of the pic.. the other.. 2 led.. whcih are below those two pins. seem to b on!!!!

is there ane other thing that could be the problem
?
 
advice needed

i have acome across sumthing else.. since my pic is running at only 5 volts do i have to while feeding in the pic.. enable low voltage program.. and should i input the low voltage through rb3.. this is wht i read somewhere
 
Ports A and E are analogue, but it's good practice to disable them during initialisation - that way you don't forget :)

As with anything, you need to fault find, for a start simplify your code - just turn ALL pins high:

movlw 0xFF
movwf PortB
movwf PortC
movwf PortD

Make this the only code in your LED loop, all LED's should be permanently lit then.

You don't need to enable low-voltage programming unless you're doing low-voltage programming, and you've never suggested you were?.
 
unfortunately againt only the red led connected to port b .. is on
portc and portd are off..

moreover since the code said that all the pins in portb are output i tried connecting the other 2 leds to portb too..unfortunately only .. the red one lights all the time
 
OK, next add a delay between each LED, like this:
call Delay
movlw 0xFF
movwf PortB
call Delay
movlw 0xFF
movwf PortC
call Delay
movlw 0xFF
movwf PortD

This time the LED's should light in sequence, 1/4 second apart (assuming you've still got 255 as the value in W).
 
now the weird thing is wherever i connect it the leds remain on.. i tried changing the program.. could u tell me how to chek next
 
now the weird thing is wherever i connect it the leds remain on.. i tried changing the program.. could u tell me how to chek next
 
sorry

sorry i had one big mistake in the circuit did not cnnect the vss to the ground ..when i did soo.. i got the same result .. when i tried ur first... prog

all leds cannt be on.. using tht code.. i still have the prob of .. portc and portd not working.. only port b . tht also . only pin rb0
 
well i think that .. the problem is with my leaper.. we had just bought this leaper.. and it was leaper pstart.. i tried . to chek it doesnt support my device... although the shop ppl .. guaranteed that it will work with my pic.. that is 16f877
 
well i chekd with the shop

i chekd with the shop and they said it does workk.. however.. i have one question in mplab ..when i was.. building it .. i get the error message [302] ensurre bank bits are rite


this is my code and still i get tht error..

Code:
bsf status,5
movlw 00h
movwf trisb
bcf status,5
 
sorry but another question ..whtver program i feed in the pic.. the pin rb0 remains on... now my question is it ttht the pic doesnt work anemore.. how can we find tht out???
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top