⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avr_detectedfrequency.txt

📁 AVR 检测频率源代码
💻 TXT
字号:

#include
#include
#include "lcd.h"
#include "bmp.h"

unsigned long counter;
unsigned char countlow;
unsigned char fre[]="00.000000";
unsigned char time[]="00:00:00";

#pragma interrupt_handler timer2_ovf_isr:iv_TIMER2_OVF
void timer2_ovf_isr(void)
{
unsigned char i;
//TCCR2=0;

PORTB &= ~0X02; //关闭闸门

//读取计数值
counter = TCNT1; //读取T/C1计数值(频率值的高16位)
counter = counter*256; //计算频率值的高16位
countlow = (PIND & 0b11000000)|(PINC & 0b00111111);
//读取计数值的低8位
counter = counter + countlow; //计算频率值

PORTD |= 0X01; //74LS393清零
TCNT1 = 0;

PORTD &= ~0X01; //关闭清零
TCNT2 = 0X80; //定时时间1秒

PORTB |= 0X02; //打开闸门

//实时时钟显示
time[7]++;

fre[0]=counter /10000000+0x30;
counter=counter %10000000;
fre[1]=counter /1000000+0x30; 字串7 
counter=counter %1000000;
fre[3]=counter /100000+0x30;
counter=counter %100000;
fre[4]=counter /10000+0x30;

counter=counter %10000;
fre[5]=counter /1000+0x30;
counter=counter %1000;
fre[6]=counter /100+0x30;
counter=counter %100;
fre[7]=counter /10 + 0x30;
fre[8]=counter %10 + 0x30;

LCD_write_String(0,2,fre);
LCD_draw_map(14,2,Bmp003,7,14); //显示小数点
LCD_draw_map(62,2,MHz,22,14); //显示频率单位

if ( time[7] > (9+0x30) )
{
time[6] ++;
time[7] -= 10;
}
if ( time[6] > (5+0x30) )
{
time[4] ++;
time[6] -= 6;
}
if (time[4]> (9+0x30))
{
time[3]++;
time[4]-=10;
}
if (time[3] > (5+0x30))
{
time[1]++;
time[3]-=6;
}
if (time[1]>(9+0x30))
{
time[0]++;
time[1]-=10;
}
LCD_write_String(2,4,time);
LCD_draw_map(16,4,Bmp002,7,14); //显示“:”字符
LCD_draw_map(37,4,Bmp002,7,14);

}

/******************************************************************************/
void main(void)
{
unsigned char i;
OSCCAL=0xA3; // 8M系统内部时钟校准

//设置MCU的I/O口
DDRB |= LCD_RST | LCD_DC | LCD_CE | SPI_MOSI | SPI_CLK ;

DDRB |= 0x02; //计数闸门
DDRD |= 0X01; //74LS393清零
//DDRD |= 0X08; //LED
//DDRD &= ~0X20;
DDRC &= 0B11000000;
DDRD &= 0B00111111;

SPSR |= BIT(SPI2X); // 设置SPI时钟倍速
SPCR |= BIT(SPE)|BIT(MSTR); // 使能SPI接口,主机模式,4M时钟

LCD_init();
//LCD_clear(); // 清屏
LCD_draw_map(12,0,Bmp001,60,13);

ASSR = 1 <
TCNT2 = 0X80; //定时时间1秒
TCCR2 = (1<<
TIMSK |= BIT(TOIE2); //允许TC2溢出中断 


TCCR1B |= BIT(CS12)|BIT(CS11)|BIT(CS10); //时钟外部T1输入,上升源驱动

SEI();

while(1)
{

}
}



3310液晶显示源代码:


#include  
#include  
#include "lcd.h" 
#include "6x8.h" 
#include "chinese.h" 

/*---------- 
LCD_init : 3310LCD初始化 

编写日期 :2004-8-10 
最后修改日期 :2004-8-10 
------------*/ 
void LCD_init(void) 
{ 
PORTB &= ~LCD_RST; // 产生一个让LCD复位的低电平脉冲 
delay_1us(); 
PORTB |= LCD_RST; 

PORTB &= ~LCD_CE ; // 关闭LCD 
delay_1us(); 
PORTB |= LCD_CE; // 使能LCD 
delay_1us(); 

LCD_write_byte(0x21, 0); // 使用扩展命令设置LCD模式 
LCD_write_byte(0xc8, 0); // 设置偏置电压 
LCD_write_byte(0x06, 0); // 温度校正 
LCD_write_byte(0x13, 0); // 1:48 
LCD_write_byte(0x20, 0); // 使用基本命令 
LCD_clear(); // 清屏 
LCD_write_byte(0x0c, 0); // 设定显示模式,正常显示 


PORTB &= ~LCD_CE ; // 关闭LCD 
//LCD_clear(); 
} 

/*-------- 
LCD_clear : LCD清屏函数 

编写日期 :2004-8-10 
最后修改日期 :2004-8-10 
-------------*/ 
void LCD_clear(void) 
{ 
unsigned int i; 

LCD_write_byte(0x0c, 0); 
LCD_write_byte(0x80, 0); 

for (i=0; i<504; i++) 
LCD_write_byte(0, 1); 
} 

/*--------- 
LCD_set_XY : 设置LCD坐标函数 

输入参数:X :0-83 
Y :0-5 

编写日期 :2004-8-10 
最后修改日期 :2004-8-10 
-----------*/ 
void LCD_set_XY(unsigned char X, unsigned char Y) 
{ 
LCD_write_byte(0x40 | Y, 0); // column 
LCD_write_byte(0x80 | X, 0); // row 
} 

/*----------- 
LCD_write_char : 显示英文字符 

输入参数:c :显示的字符; 

编写日期 :2004-8-10 
最后修改日期 :2004-8-10 
-------------------*/ 
void LCD_write_char(unsigned char c) 
{ 
unsigned char line; 


//c -= 32; 

//for (line=0; line<6; line++) 
//LCD_write_byte(font6x8[c][line], 1); 
for (line=0; line<7; line++) 
LCD_write_byte(font7x13[c][line], 1); 
for (line=7; line<14; line++) 
LCD_write_byte(font7x13[c][line], 1); 

} 

/*---------- 
LCD_write_char : 英文字符串显示函数 

输入参数:*s :英文字符串指针; 
X、Y : 显示字符串的位置 

编写日期 :2004-8-10 
最后修改日期 :2004-8-10 
------------*/ 
void LCD_write_String(unsigned char X,unsigned char Y,char *s) 
{ 
unsigned char line; 
unsigned char i="0"; 
while (*s) 
{ 
LCD_set_XY(X+i*7,Y); 
for (line=0; line<7; line++) 
LCD_write_byte(font7x13[*s-0X30][line], 1); 

LCD_set_XY(X+i*7,Y+1); 
for (line=7; line<14; line++) 
LCD_write_byte(font7x13[*s-0X30][line], 1); 
s++; 
i++; 
} 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -