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.

Help with timer0 for 16f877

Status
Not open for further replies.

crowinu

Member level 2
Joined
Apr 1, 2005
Messages
48
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,621
16f877 timer0

hi guys,

i am doing a project for my schoolwork (PIC controlled dimmer) and i need to use the timer0. I need some help in using timer0. another thing i am using assembly language not c Neutral, i guess it makes it more diffcult. i need to do something like this, every 1s a small routine is called and is repeatitly done.
10x for any help

crowinu.
 

timer0 in c for 16f877

Adjust timer0 prescaler 1/16. Clock freq. should be 4 MHz. Timer0 increments one every 16x1us. it takes 4.096 ms for 256 count. Enable the timer0 interrupt. And increment a register (8-bit) in interrupt service routine of timer0. When the register value reaches the 244 (passed time is approximately 0,999424 sec), clear the register and set a flag.
In the main routine check the flag, if it is true, call the your subroutine.
 

dear friend y same the problem please is possible you put the code in c ccs to show how make???
 

hi friend i attach the led code using timer0 .i am used hitech c compiler

#include<pic.h>
/*---------------------------*/

void TMR0Init();

/*---------------------------*/

#define TMR0_TICK 250
#define TMR0_PRESCALE 3 //(FOSC=16MHz,Prescale=3),(FOSC=4MHz,Prescale=1)

#define TMR0_RELOAD (255 - (TMR0_TICK-6))
#define LED RD0

/*---------------------------*/

static unsigned int count;

/*---------------------------*/



//void main(){}

/*---------------------------*/

void TMR0Init(){
TMR0 = 0; // Clear TMR0
INTCON = 0; // Disable all interrupts and clear T0IF
OPTION &= 0xC0; // Turn off least 6 bits to configure tmr0
OPTION |= TMR0_PRESCALE; // set prescaler to 1:x
T0IE = 1; // Enable TMR0 interrupt
GIE = 1; // Enable the global interrupt
}
/*---------------------------*/

void interrupt
tmr0_isr(void){

if(TMR0IF){
TMR0 = TMR0_RELOAD;

count++;
if(count == 1000){
LED = !LED; //Toggles LED once per second
count = 0;
}

T0IF = 0;
}
}
/*---------------------------*/
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top