View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 07, 2011 2:48 pm |
|
|
OK, then the first thing you need to do is to fix this:
Quote: |
#int_timer0
int16 p,q;
timer0_isr()
{
p++;
q++;
}
|
You can't put anything between the #int_xxxx statment and the isr
function. If you do that, the isr code will not be compiled (and the
compiler will not tell you this). You can see this in the .LST file, shown
below. Notice there is no ASM code generated:
Code: |
.................... #int_timer0
....................
.................... int16 p,q;
.................... timer0_isr()
.................... {
.................... p++;
.................... q++;
.................... }
....................
.................... void main()
.................... {
|
This is the correct way:
Code: |
int16 p,q;
#int_timer0
timer0_isr()
{
p++;
q++;
}
|
Compile it as above, and notice that you now get ASM code generated:
Code: |
.................... int16 p,q;
....................
.................... #int_timer0
.................... timer0_isr()
.................... {
.................... p++;
*
0037: INCF 28,F
0038: BTFSC 003.2
0039: INCF p+1,F
.................... q++;
003A: INCF 2A,F
003B: BTFSC 003.2
003C: INCF q+1,F
.................... }
....................
003D: BCF 00B.2
003E: BCF 00A.3
003F: BCF 00A.4
0040: GOTO 01B
.................... void main()
.................... {
|
So you need to fix that part of your program, and then you can continue
with the program development. |
|
|
freedom
Joined: 10 Jul 2011 Posts: 54
|
|
Posted: Sat Oct 08, 2011 7:53 am |
|
|
Dear PCM programmer
Thanks a lot for your kind help and guideline.
I start to learn c by this book "Programming 8-bit PIC Microcontrollers in C
by Martin P.Bates".
Do you have have any good suggestion on book/tutorial for the beginner like me please help.
If so, please provide me some link.
Thank you once again. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
freedom
Joined: 10 Jul 2011 Posts: 54
|
|
Posted: Sun Oct 09, 2011 5:50 am |
|
|
thanks a lot |
|
|
freedom
Joined: 10 Jul 2011 Posts: 54
|
|
Posted: Sun Oct 09, 2011 8:35 am |
|
|
Now the code is working but I suspect a problem while I simulate it with Proteus 7.7.
I suspect timing is not accurate as I want to do start the timer at the point that is noted in the code.
what to do:
Code: |
#include <16F877A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#include <flex_LCD420.c>
int16 p,q;
#int_timer0
timer0_isr()
{
p++;
q++;
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_4);
enable_interrupts (INT_TIMER0);
enable_interrupts(global);
set_timer0(6);
lcd_init();
// Clear the LCD.
printf(lcd_putc, "\f");
delay_ms(50);
printf(lcd_putc, "\f PIC Experiment");
printf(lcd_putc, "\n--------------------");
printf(lcd_putc, "\nNice Day ");
while(1)
{
if (!input(pin_D0)) // switch 1
{output_high(pin_C0);} // I want to start the timer at this point
if (p==1000)
{output_low(pin_C0);
p=0;}
if (!input(pin_D1)) // switch 2
{output_high(pin_C1);} // I want to start the timer at this point
if (q==500)
{output_low(pin_C1);
q=0;}
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sun Oct 09, 2011 9:49 am |
|
|
You have two and only Two options.
1) Hack into Proteus and FIX one of the many bugs and errors that it has....
2) Get RID of PROTEUS and use real hardware !
I suspect that option #2 is your only choice. |
|
|
freedom
Joined: 10 Jul 2011 Posts: 54
|
|
Posted: Sun Oct 09, 2011 1:55 pm |
|
|
Thanks temtronic
Actually I suspect there is a bug in my code not in Proteus.
Anyway, in my code is it really timing accurately as per my desire .
Maybe I mistake something. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 09, 2011 5:20 pm |
|
|
My advice is to make a more simple program. Just use one button and
one LED. Get that working reliably. Then add more features later. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Oct 10, 2011 12:29 am |
|
|
Quote: | I want to do start the timer at the point that is noted in the code. |
But you don't. Starting the timer would involve resetting the timer variable. |
|
|
freedom
Joined: 10 Jul 2011 Posts: 54
|
|
Posted: Mon Oct 10, 2011 3:42 am |
|
|
Many thanks FvM for your valued suggestion.
You are right.
Now its working. |
|
|
|