می خواهم با واحد کپچر تایمر یک در مگا 16 فرکانس متر بسازم./************************************************** ***
This program was produced by the
CodeWizardAVR V1.24.6 Standard
Automatic Program Generator
© Copyright 1998-2005 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
e-mail
ffice@hpinfotech.com
Project :
Version :
Date : 7/14/2008
Author : ali
Company : ali
Comments:
Chip type : ATmega16
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega16.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
#include<stdio.h>
#include<delay.h>
#include<math.h>
#include<stdlib.h>
volatile unsigned int st,so,T1,n,y=0;
float f;
long int T;
unsigned char lcd[30],str[30];
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
n=n++;
}
interrupt [TIM1_CAPT] void timer1_capt_isr(void)
{ if(y==0){
y=1;
T1=ICR1L+ICR1H*256;
TCCR1B=0X01;
ICR1L=0X00;
ICR1H=0X00;
if(T1>=st){T=(n*65536)+(T1 - st);
}
if(T1<st){
T=(((n-1)*65536)+(T1 - st));}
st=T1;
}
else{y=0;
so=ICR1L+ICR1H*256;
TCCR1B=0X41;
ICR1L=0X00;
ICR1H=0X00;
}
}
void main(void)
{
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
TCCR1A=0x00;
TCCR1B=0xC1;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
TIMSK=0x24;
lcd_init(16);
// Global enable interrupts
#asm("sei"
while (1)
{T=abs(T);
f=(float)1.0/T;
f=f*100000;
ftoa(f,8,str);
sprintf(lcd,"%6d",str);
lcd_clear();
lcd_puts(lcd);
delay_ms(10);
};
} اینهم برنامه است اما درست جواب نمی دهد. لطفا راهنماییم کنید؟
This program was produced by the
CodeWizardAVR V1.24.6 Standard
Automatic Program Generator
© Copyright 1998-2005 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date : 7/14/2008
Author : ali
Company : ali
Comments:
Chip type : ATmega16
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
************************************************** ***/
#include <mega16.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
#include<stdio.h>
#include<delay.h>
#include<math.h>
#include<stdlib.h>
volatile unsigned int st,so,T1,n,y=0;
float f;
long int T;
unsigned char lcd[30],str[30];
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
n=n++;
}
interrupt [TIM1_CAPT] void timer1_capt_isr(void)
{ if(y==0){
y=1;
T1=ICR1L+ICR1H*256;
TCCR1B=0X01;
ICR1L=0X00;
ICR1H=0X00;
if(T1>=st){T=(n*65536)+(T1 - st);
}
if(T1<st){
T=(((n-1)*65536)+(T1 - st));}
st=T1;
}
else{y=0;
so=ICR1L+ICR1H*256;
TCCR1B=0X41;
ICR1L=0X00;
ICR1H=0X00;
}
}
void main(void)
{
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
TCCR1A=0x00;
TCCR1B=0xC1;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
TIMSK=0x24;
lcd_init(16);
// Global enable interrupts
#asm("sei"

while (1)
{T=abs(T);
f=(float)1.0/T;
f=f*100000;
ftoa(f,8,str);
sprintf(lcd,"%6d",str);
lcd_clear();
lcd_puts(lcd);
delay_ms(10);
};
} اینهم برنامه است اما درست جواب نمی دهد. لطفا راهنماییم کنید؟
دیدگاه