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.

[SOLVED] PIC16F887 Internal and External Clock Timers

Status
Not open for further replies.

tahir4awan

Full Member level 4
Joined
Nov 29, 2010
Messages
208
Helped
16
Reputation
32
Reaction score
17
Trophy points
1,308
Location
Germany
Activity points
3,084
I wrote two programs just to check how PIC timer works with internal and external clock. But when I check both my program on ISIS Proteus 7 they are working abnormal. Please also check my code that, are they written correctly. Note that are not for specific purpose I just want to check timers.

For internal clock
===========================================================

int count = 0;
void main()
{

TRISB = 0x00;
TMR0 = 0;
GIE_bit = 1;
PEIE_bit = 1;
T0IE_bit = 1;
T0IF_bit = 0;
T0CS_bit = 1;
T0SE_bit = 0;
PSA_bit = 0;
PS0_bit = 1;
PS1_bit = 1;
PS2_bit = 1;

while(1){

if(!T0IF_bit) {

count++;

if(count==15)

PORTB = 0x01;

else if(count==30)

PORTB = 0x02;

else if(count==45)

PORTB = 0x03;

else if(count==60)

PORTB = 0x04;

}
}
}

===========================================================

and for external clock. There is also a problem in ISIS Proteus that with external clock it is only working with clock speed given in PIC option. Is there any option to disable internal clock so we can input pulse from RA4 pin.

===========================================================


void main()
{
ANSEL = 0;
ANSELH = 0;
TRISB = 0x00;
TRISA.RA4 = 1;
TMR0 = 0;
GIE_bit = 0;
PEIE_bit = 0;
T0IE_bit = 0;
T0IF_bit = 0;
T0CS_bit = 0;
T0SE_bit = 0;
PSA_bit = 0;
PS0_bit = 0;
PS1_bit = 0;
PS2_bit = 0;

while(1){
if(TMR0==5) {

PORTB = 0xFF;

else if(TMR0==10)

PORTB = 0xAF;

else if(TMR0==15)

PORTB = 0xAA;

else if(TMR0==20)

PORTB = 0xCC;

}
}
}

===========================================================
 

In the first bit of code you have enabled the timer interrupt but you have no interrupt routine?
When the timer overflows, the code will jump to the interrupt vector, which in your case, doesn't exist.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top