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.

please check whether it is right or not

Status
Not open for further replies.

samarth123

Newbie level 6
Joined
Feb 13, 2010
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,371
i am trying to do a simple stuff with 16f877. thing is that PORTB shud start toggling as soon as PORTA.0 is made high. I am posting the code please go through it.
Code:
list p=16F877A,r=hex
	#include <P16F877A.inc>





	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF 	; config suitable for 20 meg hz  crystal


	cblock	0x20		;***** VARIABLE DEFINITIONS
	d1					; delay routine work files
	d2
	d3
	endc


	org 0x00

	goto start

start
	banksel	ADCON1		
	movlw	0x06		
	movwf	ADCON1

	banksel TRISB
	movlw	0x00		
	movwf 	TRISB
	banksel TRISA
	movlw 0x3f
	movwf TRISA
	banksel PORTA
	clrf PORTB
here
	btfss PORTA,0
	goto here
up
	comf PORTB
	call delay500
	goto up	



delay500			; delay of 500ms using 20meg hz crystal
	movlw	0x16
	movwf	d1
	movlw	0x74
	movwf	d2
	movlw	0x06
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0

	return

	end
 

Have you tried using mplab sim as the debugger, stepping through the code to see whats going on?
 

Hi,

Thought I recognised my old code example - it still works ok, and yes it does toggle Port B when Port A,0 is switched high.

Think you have a problem with your hardware, can you show the circuit and oscillator you are using.
Have you got Mclre Pin1 pulled up high ?
Are you building it on a breadboard or soldered on a board ?
 

i am using ready mini project board pic of it i have attached.
What is mclre pin1?
how and why to make it high?
 

Attachments

  • project board pic.JPG
    project board pic.JPG
    48.5 KB · Views: 109

Hi,

Its good you are using a ready made board like that, it avoids so many problems.
The board has already got Mclre pulled up.

It also has a 4 meg crystal, that code is designed for a 20meg one.
You need to change this bit of code on the Config line _HS_OSC to _XT_OSC

The code will work but flash every 2 seconds becuase of the different crystal.

If it does not work, then remove these two lines of code, so the program just acts as a simple flasher
here
btfss PORTA,0
goto here

How have you got the switch wired to PORTA,0 ? Are you using any resistors with it ?
 

Your __config statement doesn't show the MCLR setting. Maybe it is set active/on. There is a weak pull up on that pin. If it is on, you should add a resistor of 10K to 40K to Vdd (+5V). The resistor value is really unimportant unless you are doing in circuit serial programming. MCLR is a reset and resets the MCU when it is low.

If you are using MPLab, go to the configuration button (configure>configuration bits) and see what needs to be set. If you uncheck "set in code" box you can see all the choices.

John
 

Your __config statement doesn't show the MCLR setting. Maybe it is set active/on. There is a weak pull up on that pin. If it is on, you should add a resistor of 10K to 40K to Vdd (+5V). The resistor value is really unimportant unless you are doing in circuit serial programming. MCLR is a reset and resets the MCU when it is low.

If you are using MPLab, go to the configuration button (configure>configuration bits) and see what needs to be set. If you uncheck "set in code" box you can see all the choices.

John

Hi Jpanhalt,

Afraid in this instant with the 16F877A the Mclre in the Config line is not applicable. Mclre can only be used for programming or Reset on these older chips, unlike the more modern ones.

The OPs picture shows Mclre is correctly fitted with a 10K pull up with a Reset switch to ground.
 

actually i have developed the program in such a way that PORTB should start toggling as soon as i supply RA.0 with 5v i.e as logical 1. when i simulate it in MPLABsim it worked correctly, but in board PORTB started toggling even though i had not supplied RA.) with 5v. I am not getting what is the problem, my main intention is that input should control the operations i.e input should trigger the operations on the 16f877a. Please help me...
 

Hi,

The code works fine, I think you may not have the switch wired correctly.

This circuit works fine ( although not shown, it does need the crystal and caps on the real hardware)
 

Attachments

  • ScreenShot001.jpg
    ScreenShot001.jpg
    63.6 KB · Views: 62

sir even i tried the circuit given by u, but it is not reading input from RA.0 at all simply as soon as u switch on the supply it starts toggling..please help me
 

sir even i tried the circuit given by u, but it is not reading input from RA.0 at all simply as soon as u switch on the supply it starts toggling..please help me

Hi,

I do not have the circuit diagram for your dev board, there might be something else attached to it ?

Try a different pin of PortA , or better still read from Port D ,0 afer setting it to digital INputs with TRISD


If you have a volt meter, check what happens at the input pin when you close and open the switch, do you get a true + 5v and 0v ?


Also try changing your BSFSS to BSFSC so it will only run when the switch is closed to 0V.
 

ya sir i do have voltmeter am testing using that itself....wen i executed the following piece of code PORTB stopped toggling when +5v was supplied to RA0. Code is as follows
Code:
here
	btfsc PORTA,0
	goto here
	comf PORTB
	call delay500
	goto here
 

ya sir i do have voltmeter am testing using that itself....wen i executed the following piece of code PORTB stopped toggling when +5v was supplied to RA0. Code is as follows
Code:
here
	btfsc PORTA,0
	goto here
	comf PORTB
	call delay500
	goto here



Hi,

So its all working ok then... ?
 

ya it is working sir but it is not working as i planned and programmed. I had Planned it to start toggling wen RA0 is made high instead it is sopping wen RA0 is made high. If possible please send the correct piece of code sir. and another doubt sir, why EXOR gate is called as friendly gate?
 

Code:
here
	btfsc PORTA,0    ;Bit test file, skip if clear ??? 
	goto here
	comf PORTB
	call delay500
	goto here

Change this line

Code:
here
	btfss PORTA,0    ; Bit test file, skip if set.
	goto here
	comf PORTB
	call delay500
	goto here

Then it should do what you want.
 

even i tried the same sir but even it is not working... i think it starts torggling coz when i make PORTA as input port and measure voltage accross PORTA initially it shows some 3v so i think this voltage is acting as logical 1 to the PORTA n coz of dis it starts toggling as soon as power is on. n please if possible please send embedded c code for the same with configuration so that i can use the code directly. n i am using HiTechC.
 

even i tried the same sir but even it is not working... i think it starts torggling coz when i make PORTA as input port and measure voltage accross PORTA initially it shows some 3v so i think this voltage is acting as logical 1 to the PORTA n coz of dis it starts toggling as soon as power is on. n please if possible please send embedded c code for the same with configuration so that i can use the code directly. n i am using HiTechC.

Hi,


Have just run your code, the original loop and the later loop, both work fine in Simulation and on my pic16f877A.

Have attached the assembler and hex file for you to run.

Think you have got a problem with your hardware, please show your switch circuit and if you have a diagram of your dev board.

If you are measuring 3v on RA0 then something is likely to be wrong .


If you are doing assembler, why the sudden change to C ?
 

Attachments

  • billyboy.rar
    762 bytes · Views: 43

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top