|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Help interrupt : NEWBIE |
Posted: Wed Dec 06, 2006 12:56 pm |
|
|
Hi guys , i know it is probably simple , but i can't find why this simple code doesn't work
all i want a do with it , is to change the value set in timer1 using an analog input, varying the analog should change the speed of the blinking LED , i have been able to do it in 8 bits using Timer0 but not in 16 bit with timer1
Thanks for your help!!
Bruno
here the code
#include <16F676.h>
#device adc=10
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,BROWNOUT,NOMCLR
#use delay(clock=4000000) // 4MHz clock
long atime=0;
long itime=0;
byte i;
#INT_TIMER1
void Timer1()
{
set_timer1(atime);
if (itime==512)
{
output_low(PIN_A5);
output_high(PIN_A4);
}
else
{
output_low(PIN_A5);
output_low(PIN_A4);
}
if (i==1)
{
output_high(PIN_A1);
output_low(PIN_A2);
i=0;
}
else
{
output_low(PIN_A1);
output_high(PIN_A2);
i=1;
}
}
void main()
{
set_tris_a(0xf1); //
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
set_timer1(atime);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_DIV_16);
while(1==1)
{
set_adc_channel(0);
itime=read_adc();
delay_us(50);
atime=itime;
}
} |
|
|
mindstorm88
Joined: 06 Dec 2006 Posts: 102 Location: Montreal , Canada
|
Re: Help interrupt : NEWBIE SOLVED |
Posted: Wed Dec 06, 2006 12:58 pm |
|
|
Oups i'm the author
Anonymous wrote: | Hi guys , i know it is probably simple , but i can't find why this simple code doesn't work
all i want a do with it , is to change the value set in timer1 using an analog input, varying the analog should change the speed of the blinking LED , i have been able to do it in 8 bits using Timer0 but not in 16 bit with timer1
Thanks for your help!!
Bruno
here the code
#include <16F676.h>
#device adc=10
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,BROWNOUT,NOMCLR
#use delay(clock=4000000) // 4MHz clock
long atime=0;
long itime=0;
byte i;
#INT_TIMER1
void Timer1()
{
set_timer1(atime);
if (itime==512)
{
output_low(PIN_A5);
output_high(PIN_A4);
}
else
{
output_low(PIN_A5);
output_low(PIN_A4);
}
if (i==1)
{
output_high(PIN_A1);
output_low(PIN_A2);
i=0;
}
else
{
output_low(PIN_A1);
output_high(PIN_A2);
i=1;
}
}
void main()
{
set_tris_a(0xf1); //
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
set_timer1(atime);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_DIV_16);
while(1==1)
{
set_adc_channel(0);
itime=read_adc();
delay_us(50);
atime=itime;
}
} |
Last edited by mindstorm88 on Thu Dec 07, 2006 8:23 am; edited 1 time in total |
|
|
mindstorm88
Joined: 06 Dec 2006 Posts: 102 Location: Montreal , Canada
|
|
Posted: Thu Dec 07, 2006 8:22 am |
|
|
Sorry guys , don't waste your time on it !!!, everything is working OK , my loop is so long that i could not see the speed change of the leds !!!! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|