登录 免费注册 首页 | 行业黑名单 | 帮助
维库电子市场网
技术交流 | 电路欣赏 | 工控天地 | 数字广电 | 通信技术 | 电源技术 | 测控之家 | EMC技术 | ARM技术 | EDA技术 | PCB技术 | 嵌入式系统
驱动编程 | 集成电路 | 器件替换 | 模拟技术 | 新手园地 | 单 片 机 | DSP技术 | MCU技术 | IC 设计 | IC 产业 | CAN-bus/DeviceNe

我也贴一个测频率的,CV_AVR ,SO EASY.

作者:seeseatv 栏目:单片机
我也贴一个测频率的,CV_AVR ,SO EASY.
void main(void)
{
// Declare your local variables here
CHAR t0_counter;
inits();
while (1)
      {// Place your code here
       t0_counter = 0;     
       TCNT0=0;
       delay_ms(100);                   //延时100MS,CVAVR自带的函数.
       t0_counter = TCNT0;
       if (TIFR&0x01) putCHAR(0x01);
       TIFR&=0xFF;
       TIFR&=0xFE;
       putCHAR(t0_counter);
       putCHAR(0x00);
       };
}

CVAVR 中最好用不过delay_us() 和delay_ms() 了.我写模拟串口都用它们,一下子SO EAZY ,呵呵. 这两个函数其实也是累加延时程序,代码效率相当高的.

2楼: >>参与讨论
seeseatv
CV 生成的初始化代码
/*********************************************
This program was produced by the
CodeWizardAVR V1.23.8c Professional
Automatic Program Generator
?COPYRIGHT 1998-2003 HP InfoTech s.r.l.
http://www.hpinfotech.ro
e-mail:office@hpinfotech.ro

Project :
Version :
Date    : 2003-9-4
Author  : Notrue                          
Company :                                 
Comments: 如需转载,请注明出处 :)


Chip type           : ATMEGA8L
Program type        : Application
Clock frequency     : 4.000000 MHz
MEMORY MODEL        : Small
External SRAM size  : 0
Data Stack size     : 256
*********************************************/

#include <mega8.h>

// STANDARD Input/OUTPUT functions
#include <stdio.h>
#include <delay.h>

#define s_uart_baud_rate 4800

// Declare your GLOBAL variables here

void inits(void)
{// Input/OUTPUT PORTs initialization
// PORT B initialization
// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out
// State0=1 State1=1 State2=1 State3=1 State4=1 State5=1 State6=1 State7=1
PORTB=0xFF;
DDRB=0xFF;

// PORT C initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T
PORTC=0x00;
DDRC=0x00;

// PORT D initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: T0 pin Falling Edge
TCCR0=0x06;
TCNT0=0x00;

// Timer/Counter 1 initialization
// Clock source: SYSTEM Clock
// Clock VALUE: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A OUTPUT: Discon.
// OC1B OUTPUT: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: SYSTEM Clock
// Clock VALUE: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 OUTPUT: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
GICR|=0x00;
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART RECEIVER: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 19200
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x0C;

// ANALOG Comparator initialization
// ANALOG Comparator: Off
// ANALOG Comparator Input Capture by Timer/Counter 1: Off
// ANALOG Comparator OUTPUT: Off
ACSR=0x80;
SFIOR=0x00;
}

参与讨论
昵称:
讨论内容:
 
 
相关帖子
89C2051能用AVR GCC吗?
我把正版的CVAVR1.238 的LICENSE弄没了,急用,请帮帮忙啊!
如何同时存取TCNT1H,TCNT1L
贴一个LCD通讯的程序-标准接口
谁能讲讲mega系列里熔丝位配置。
免费注册为维库电子开发网会员,参与电子工程师社区讨论,点此进入


Copyright © 1998-2006 www.dzsc.com 浙ICP证030469号