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.

18F2520-how to use timer0

Status
Not open for further replies.

hemnath

Advanced Member level 3
Joined
Jun 24, 2012
Messages
702
Helped
61
Reputation
120
Reaction score
57
Trophy points
1,308
Location
Chennai
Activity points
6,588
i did programming using delays. looking forward to do with timer0.
compiler - CCS c compiler
pic - 18F2520.
internal oscillator - 4MHz

Please help how to start with? how to calculate time?

thanks in advance :)
 

thanks for ur information. i'm blinking the led with 5 sec delay. please tell that i'm doing it right?

HTML:
#include "18F2520.h"
#fuses HS, NOPROTECT, INTRC_IO
#use delay(clock=4000000)			// 4MHZ internal clock 
//	fout = fclk/(4*prescaler* (256-TMR0)*count)
// 	for prescaler = 1 : 256 and TMR0 = 0
//	if need 5sec delay
//	Tout = 1/fout = 1/0.2Hz = 5sec 
//	count = 4Mhz/(4*256*(256-0)*0.2Hz) = 76.29 = 76 counts(approxi)

unsigned int count;

#int_RTCC
void clock_isr()
{
set_timer0(0);
count++;
if(count==76)				// 76 for 5sec delay // 15 for 1 sec delay
{
output_high(PIN_B7);
count=0;
}
}

void main()
{
set_tris_b(0x00);
setup_oscillator(OSC_4MHZ);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT);
enable_interrupts(INT_TIMER0); 
enable_interrupts(GLOBAL); 
while(1)
{
output_high(PIN_B6);
}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top