|
|
View previous topic :: View next topic |
Author |
Message |
sumesh89
Joined: 17 Dec 2011 Posts: 2 Location: Kerala
|
RPS Counter Help |
Posted: Sun Dec 25, 2011 9:41 pm |
|
|
My code is given below, no errors shown when compiling. But here the Timer1 interrupt flag (TMR1IF) not come to set. Pls help
Code: | #include "16f877a.h"
#fuses XT,NOWDT,NOBROWNOUT,NOPROTECT
#use delay(clock=1000000)
#define use_portb_lcd TRUE
#include "lcd.c"
//// Timer0 Module
#byte TMR0 = 0x01
#byte PORTA = 0x05
#byte TRISA = 0x85
#byte OPTION_REG = 0x81
#byte INTCON = 0x0b
#bit gie = INTCON.7
#bit peie = INTCON.6
#bit t0ie = INTCON.5
//#bit inte = INTCON.4
//#bit rbie = INTCON.3
#bit t0if = INTCON.2
//#bit intf = INTCON.1
//#bit rbif = INTCON.0
#bit t0cs = OPTION_REG.5
#bit t0se = OPTION_REG.4
#bit psa = OPTION_REG.3
//// Timer1 Module
#byte TMR1L = 0x0e
#byte TMR1H = 0x0f
#byte PIR1 = 0x0c
#byte PIE1 = 0x8c
#byte T1CON = 0x12
#bit T1CKPS1 = T1CON.5
#bit T1CKPS0 = T1CON.4
#bit T1OSCEN = T1CON.3
#bit T1SYNC = T1CON.2
#bit TMR1CS = T1CON.1
#bit TMR1ON = T1CON.0
#bit TMR1IF = PIR1.0
#bit TMR1IE = PIE1.0
#byte TMR1L = 0x0e
#byte TMR1H = 0x0f
void timer()
{
TMR1IF=0;
T1CKPS1=0;
T1CKPS0=1;
T1SYNC=1;
TMR1CS=0;
T1OSCEN=0;
TMR1IE=1;
TMR1H:TMR1L=0x3CAF;
//TMR1ON=1;
}
void main()
{
int16 count;
setup_adc_ports(NO_ANALOGS);
lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc, "\f Thenga");
delay_ms(3000);
lcd_gotoxy(1,1);
printf(lcd_putc, "RPS COUNTER");
delay_ms(3000);
TRISA=255;
PORTA=255;
while(1)
{
timer();
TMR1ON=1;
T0IF=0;
TMR0=0;
T0CS=1;
PSA=1;
T0SE=0;
T0IE=1;
PEIE=0;
GIE=0;
while(!TMR1IF);
T0IF=0;
TMR1IF=0;
TMR1ON=0;
lcd_gotoxy(2,2);
printf(lcd_putc, "\f RPS = %s", count);
delay_ms(600);
TMR1IF=0;
T0IF=0;
}
} |
_________________ the more i think the confused i get |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 26, 2011 12:15 pm |
|
|
Let me give you a tip about this forum. Nobody wants to look at register
level code on this forum (unless we have to, in order to fix a compiler bug).
If you are on the CCS forum, you should write code that uses CCS functions.
If you want to do a tachometer project, there are several long threads
with sample code, and that explain every little detail and every possible
bug or feature that you need. Just search for "tachometer" (without the
quotes) in the forum's search page and read all those threads.
http://www.ccsinfo.com/forum/search.php |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9228 Location: Greensville,Ontario
|
|
Posted: Mon Dec 26, 2011 12:19 pm |
|
|
Also when you do access registers directly be sure to add comments as to WHAT you are doing !
ie: T1CKPS1=0;
T1CKPS0=1;
I'll lay odds 3 hours from now you can't tell us what these 2 lines of code actually do and why they are required.
Comments do not cost you any code space. |
|
|
|
|
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
|