Tak
Joined: 22 Apr 2012 Posts: 6
|
16f887 timer problem |
Posted: Sun Apr 22, 2012 10:36 pm |
|
|
Code: |
#include "16f887.h"
#device adc=8
#device *=16
#include "ham.h" // contain ADC set up.
#include <stdio.h>
#FUSES HS, NOWDT
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
volatile int8 a=0;
#int_TIMER1
void TIMER1_isr()
{
set_timer1(20000);
}
void main()
{
set_tris_d(0x00);
set_tris_a(0x00);
output_a(0xff);
cau_hinh_adc(); //set up adc
setup_timer_1(RTCC_INTERNAL|RTCC_DIV_16);
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(int_TIMER1);
set_timer1(20000);
//enable_interrupts(GLOBAL);
while(1)
{
a=read_adc();
printf(" %u",a);
output_d(a);
delay_ms(500);
}
}
|
I try to read ADC and send the value to PC's COM port. Everything worked fine. After that, i decide to make sample with Timer1 and it doesn't work any more. I tested again with this:
Code: |
#int_TIMER1
void TIMER1_isr()
{
set_timer1(20000);
output_d(a);
}
void main()
{
set_tris_d(0x00);
set_tris_a(0x00);
output_a(0xff);
cau_hinh_adc(); //set up adc
setup_timer_1(RTCC_INTERNAL|RTCC_DIV_16);
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(int_TIMER1);
set_timer1(20000);
enable_interrupts(GLOBAL); // enable this
while(1)
{
a=read_adc();
printf(" %u",a);
delay_ms(500);
}
}
|
COM port still get value from ADC but leds haven't run at all. Every code I put in TIMER1_isr() 's not run too . I use CCS 4.104
Thanks for any advices=.= |
|