Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

problem with pic16F876 mikroc

Status
Not open for further replies.

hamzabougui100

New Member
j ai un probleme avec mon program pic16f876 qui n'arrive pas a affiché fréqence
elle s'affcihe toujour 0
I have a problem with my program pic16f876 that can not get displayed Frequency
she is still showing 0
grgr.jpg
 
// Lcd pinout settings
sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D7 at RB2_bit;
sbit LCD_D6 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D4 at RB5_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB5_bit;
int val,freq,hum;
char humid[7];
void data_converstion(void){
IntToStr(hum,humid);
}
void display1(void)
{
lcd_out(1,1,"hum=");
lcd_out(1,13,Ltrim(humid));
lcd_Chr_Cp('%');
lcd_Chr_Cp(' ');
}
void interrupt(void)
{
if(T1CON.TMR1ON==0)
{
T1CON.TMR1ON=1;
INTCON.INTF=0;
}
else if(T1CON.TMR1ON==1)
{
T1CON.TMR1ON=0;
val=(TMR1H<<8)|(TMR1L);
INTCON.INTE=0;
freq=(50/val);
hum=565-freq/13;
TMR1H=0;
TMR1L=0;
INTCON.INTE=1;
INTCON.INTF=0;
}
}






void main() {
long count;
count=0;
TMR1H=0;
TMR1L=0;
INTCON.GIE=1;
INTCON.INTE=1;
OPTION_REG.INTEDG=0;
ADC_Init();
Lcd_Init();
freq=0;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,4,"FEGAS & ");
Lcd_Out(2,6,"NAMANE");
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
for(;;)
{
data_converstion();
display1();
}






}
 
Can you edit your code and use code tags.

Edit, first look and I can't see any config settings.

Mike.
 
val=(TMR1H<<8)|(TMR1L);
Firstly! This line will not convert TMR1H to an int so the high val is shifted out
val=((int)TMR1H<<8)|(TMR1L); use a cast.

freq=(50/val);
hum=565-freq/13;
Secondly! Same here!!

freq and val are not float or double types so I don't think freq will hold the answer you are looking for.

if(T1CON.TMR1ON==0)
{
T1CON.TMR1ON=1;
INTCON.INTF=0;
}
else if(T1CON.TMR1ON==1)
{
T1CON.TMR1ON=0;

Thirdly...... What's happening here! Not sure why you need to toggle the timer?

Lastly! Try not to use complex maths inside an ISR... I know this is only 100hz but you are using a timer and it may be incorrect.
 
Je ne sais pas comment résoudre ce problème, si vous voulez me faire la bonne formule, et pour 100hz c'est juste un exemple même avec une autre fréquence ça reste toujours 0
 
I do not know how to solve this problem, if you want to make me the right formula, and for 100hz it is just an example even with another frequency it remains always 0
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top