Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

PIC 16F877A coding problem with using portB as an output

Status
Not open for further replies.

Sreeraj T.K

Newbie level 1
Joined
Dec 18, 2005
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,295
hi,
first time i am using PIC micro controller.
i m using Hi-Tech C for programming.
i face one problem while using portB as output.
the code is as follows:


-----------------------------------------------------------------------------

#include<pic.h>
#define DATA PORTB
void pic_init();
void delayMs(unsigned char k);
void main()
{
int i;
pic_init();
while(1)
{
DATA=0xAA;
delayMs(2000);
DATA=0x55;
delayMs(2000);

}
}
/**********************************************************************************************/
void delayMs(unsigned char k)
{

unsigned int j,p,q;
q = k * 87;
for(j=0;j<q;j++)
{
for(p=0;p<3;p++);
}

return;
}

/**********************************************************************************************/
void pic_init()
{

TRISC = 0x00; //RC0-RC7->D0-D7.
PORTC = 0x00;

TRISB = 0x00;
PORTB = 0x00;
return;
}

-----------------------------------------------------------------------------------
i made the delay for two seconds
i used 20MHz crystal.
the output i tested by using LEDs.
but i didnt get the desired time intervel and also LEDs blinks faster when i touch the crystal.
what is the problem?
how it can be rectified?
is there any problem for using PORTB?


[/code]
 

arash_micro

Member level 5
Joined
Jan 25, 2005
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
739
PIC 16F877A project

Hi.
I think when freq goes to 16f877 or other micros the micro div it by 4 or 8 or etc.
Calculate the time with this knowledge .

When you touch the crystal ,you give many and many nois to the micro.Thats true that micro

doesn't work good when you touch it.
 

alzomor

Advanced Member level 2
Joined
Jun 9, 2005
Messages
678
Helped
39
Reputation
78
Reaction score
8
Trophy points
1,298
Location
Cairo
Activity points
6,417
Re: PIC 16F877A project

Hi

1st the instruction cycle is 4 times the clock cycle
2nd make sure that you selected the proper crystal type and configered your Micro to this crystal (LP , XT , RC , HS) check the crystal chapter of data sheets .
for 20MHz you need to use HS mode
3rd make sure that you used the correct Capacitance value with your crytal .
for HS 20MHz you need to use value in range from 15pf to 33 pf
4th in your PCB layour place the crytal as near as possible with the micro pins for crystal input
5th put the crytal capacitors As near as possible to the crytal and the micro

when you put you hand on the crystal you add stray capacitance

Salam
Hossam Alzomor
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top