/*****************************************************
S1:校正。 拨至“校正”位置,开始自校,等屏上显示频率稳定后拨至“测量”位置 ,显示标准电容和电感值。同时按B1和B2退出校正模式。
S2: 1-2接通。脉冲测量频率最大6MHz,不能调触发电平;2-3接通,脉冲测量频率最大1MHz,可调整触发电平,用T1设定,JP1短接显示屏显示触发电平大小。
B1:
电容测量时: 按下回零
电感测量时: 按下回零
频率测量时: 按下切换显示频率或周期时间
脉冲测量时:按下切换显示频率+占宽比或周期时间+占宽比或高低电平时间
计数器时:按下回零
温度测量时:按下设定上下温度报警点
B2:
频率测量时:按下按频率测量-〉脉冲测量-〉计数器-〉温度测量-〉频率测量 循环切换
电容电感测量时:按下开始频率测量
设定温度报警点时:设定温度加
B3:
频率测量时:按下开始电容电感测量
电容电感测量时:测量电感或电容切换
计数器时:按下暂停或重启
设定温度报警点时:设定温度减
进入温度测量功能时查一遍18B20的个数,然后按查到的个数显示各个器件的温度。
Chip type : ATmega88V
Clock frequency : 16.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 128
*****************************************************/
#include <mega88.h>
#include <delay.h>
#include <stdlib.h>
#include "lcd1602.h"
#asm
.equ __w1_port=0x08 ;PORTC
.equ __w1_bit=0
#endasm
//#include <1wire.h>
#include <ds18b20.h>
#define LCD_EN_PORT PORTD
#define LCD_EN_DDR DDRD
#define LCD_EN (1<<7) //
#define LCD_RS_PORT PORTB
#define LCD_RS_DDR DDRB
#define LCD_RS (1<<5) //
#define LCD_DATA_PORT PORTB
#define LCD_DATA_DDR DDRB
#define LCD_DATA_BIT 0b00011110 //
flash unsigned char data[8]={0x0C,0x0C,0x03,0x04,0x04,0x04,0x03,0x00};//℃
flash unsigned char data1[8]={0x04,0x0E,0x15,0x04,0x04,0x04,0x04,0x00};//↑
void LCD_en_write(void) //液晶使能
{
LCD_EN_PORT|=LCD_EN;
delay_us(12);
LCD_EN_PORT&=~LCD_EN;
delay_us(12);
}
void LCD_write_low(unsigned char temp)
{
LCD_DATA_PORT&=~LCD_DATA_BIT; //清高四位
LCD_DATA_PORT|=(temp<<1)&LCD_DATA_BIT; //写低四位
LCD_en_write();
}
void LCD_write_high(unsigned char temp)
{
LCD_DATA_PORT&=~LCD_DATA_BIT; //清高四位
LCD_DATA_PORT|=(temp>>3)&LCD_DATA_BIT; //写低四位
LCD_en_write();
}
void LCD_write_command(unsigned char command) //写指令
{
delay_us(20);
LCD_RS_PORT&=~LCD_RS; //RS=0
LCD_write_high(command);
LCD_write_low(command);
}
void LCD_write_data(unsigned char data) //写数据
{
delay_us(16);
LCD_RS_PORT|=LCD_RS; //RS=1
LCD_write_high(data);
LCD_write_low(data);
}
void LCD_clear(void) //清屏
{
LCD_write_command(0x01);
delay_ms(2);
}
void LCD_inital(void)
{
LCD_DATA_DDR|=LCD_DATA_BIT; //数据口方向为输出
LCD_EN_DDR|=LCD_EN; //设置EN方向为输出
LCD_RS_DDR|=LCD_RS; //设置RS方向为输出
LCD_write_low(0x03);
delay_ms(20);
LCD_write_low(0x03);
delay_us(200);
LCD_write_low(0x03);
delay_us(20);
LCD_write_low(0x02); //4位显示
LCD_write_command(0x28); //4位,设定两行
LCD_write_command(0x0C); //显示开
LCD_write_command(0x01); //清屏
delay_ms(2);
}
void write_user_capter(unsigned char ascii,flash unsigned char *z)
//ascii为与要定义的图案对应的ascii码值(0到7间任选)
//z为字码定义数组
{
unsigned char address=0,i,temp=0;
temp=(ascii&0x07)<<3;
for(i=0;i<8;i++)
{
address = 0x40 +temp+ i;
LCD_write_command( address );
delay_us(5);
LCD_write_data ( *(z++));
delay_us(5);
}
}
void LCD_goto_xy( unsigned char x, unsigned char y ) //写地址函数
{
unsigned char address;
if (y == 0) address = 0x80 + x;
else address = 0xc0 + x;
LCD_write_command( address);
}
void LCD_put_c( unsigned char data) //列x=0~15,行y=0,1
{
LCD_write_data( data);
}
void LCD_put_str(unsigned char X,unsigned char Y, flash unsigned char *s) //列x=0~15,行y=0,1
{
LCD_goto_xy( X, Y ); //写地址
while (*s) // 写显示字符
{
LCD_write_data( *s );
s ++;
}
}
void LCD_put_str2(unsigned char X,unsigned char Y, unsigned char *s) //列x=0~15,行y=0,1
{
LCD_goto_xy( X, Y ); //写地址
while (*s) // 写显示字符
{
LCD_write_data( *s );
s ++;
}
}
#define MAX_DS1820 2 // maximum number of DS1820 devices connected to the 1 Wire bus
#define TCNT1 (*(unsigned int *)0x84)
#define ICR1 (*(unsigned int *)0x86)
#define T0_OFF TCCR0B=0x00
#define T0_ON TCCR0B=0x05
#define SET_T0_TIME TCNT0=0x64
#define T1_OFF TCCR1B=0x00
#define T1_ON TCCR1B=0x07
#define C_stand 900.0 //标准电容值(pF)
#define B1 PIND.2
#define B2 PIND.3
#define B3 PIND.6
#define K1 PORTD.1
#define K2 PORTD.0
#define AD_IE_OFF ADCSRA&=~(1<<7)
#define AD_IE_ON ADCSRA|=(1<<7)
#define AD_START ADCSRA|=(1<<6)
unsigned char str[10];
unsigned char rom_codes[MAX_DS1820][9];
unsigned char alarm_rom_codes[MAX_DS1820][9];
unsigned char time0_expend; //定时器0扩展计数器
unsigned char trig_time; //频率闸门时间
unsigned char mode;
unsigned char tempture_mode;
unsigned char ds18B20_devices;
unsigned char temp_tp,temp_bs,;
unsigned int top_time,base_time,count_h;
unsigned char Capture_div;
float trig_voltage;
unsigned long frequnce;
bit t1_over_flower;
bit error_over_flower;
bit lower_pri;
bit save_stray;
bit init_senor;
unsigned char mode_using;
bit test_complete;
bit zero;
eeprom float c1;
eeprom float l1;
eeprom signed int alarm_t1_max,alarm_t1_min,alarm_t2_max,alarm_t2_min;
eeprom unsigned long f1;
signed int alarm[4];
float cs;
float ls;
float cx;
float lx;
void int_inital_on(void)
{
EICRA=0x0A;
EIFR=0x03;
EIMSK=0x03;
PCIFR=0x04;
PCICR=0x04;
PCMSK2=0x40;
}
void int_inital_off(void)
{
EIMSK=0x00;
EIFR=0x03;
PCMSK2=0x00;
PCIFR=0x04;
}
void cal_set_par(unsigned long f2)
{
c1=C_stand*f2*f2/((float)f1*f1-(float)f2*f2);
l1=(1000000000000000000.0/(39.4784176*f1*f1*c1));
}
float cal_c(unsigned long f2)
{
float temp;
temp=(((float)f1*f1)/((float)f2*f2)-1)*c1;
//temp=((1.0/(39.4784176*l1*(1.0E-6)*f2*f2)))*(1.0E12)-c1;
return temp;
}
float cal_l(unsigned long f2)
{
float temp;
temp=(((float)f1*f1)/((float)f2*f2)-1)*l1;
//temp=(1.0/(39.4784176*c1*(1.0E-12)*f2*f2))*(1.0E6)-l1;
return temp;
}
void disp_trig_vol(void)
{
LCD_put_str(0,0,"Trig: V/ S");
ftoa(trig_voltage,2,str);
LCD_put_str2(5,0,str);
ftoa(trig_time/100.0,2,str);
LCD_put_str2(11,0,str);
}
void disp_fr_vol(unsigned char x,unsigned char y,float frec)
{
if(frec<1000)
{
ftoa(frec,2,str);
LCD_put_str2(x,y,str);
}
else
{
if(frec<1000000)
{
ftoa(frec/1000.0,3,str);
LCD_put_str2(x,y,str);
LCD_put_c('K');
}
else
{
ftoa(frec/1000000.0,4,str);
LCD_put_str2(x,y,str);
LCD_put_c('M');
}
}
LCD_put_c('H');
LCD_put_c('z');
}
void disp_fr(void)
{
delay_ms(200/trig_time);
LCD_put_str(0,1," ");
LCD_put_str(0,1,"Freq=");
disp_fr_vol(5,1,frequnce);
if(lower_pri==1)
{
if(trig_time<100)
trig_time*=10;
else
trig_time=200;
}
}
void disp_cycle(void)
{
delay_ms(200/trig_time);
LCD_put_str(0,1," ");
LCD_put_str(0,1,"Cycle=");
if(frequnce<1000)
{
if(frequnce==0)
{
LCD_goto_xy(7,1);
LCD_put_c(1);
LCD_put_c(' ');
LC.rar_AVR 电感_LC_电感测试仪
版权申诉
167 浏览量
2022-09-21
07:24:35
上传
评论
收藏 6KB RAR 举报
JaniceLu
- 粉丝: 78
- 资源: 1万+