?? cap.c
字號:
#include"reg51.h"
#include"51usb.h"
#define uchar unsigned char
#define uint unsigned int
/*************初始化定時器及計數(shù)器的函數(shù)*******************************/
void initsys();
void display();
void delay1(uint ticks);
void LCD_en_command(unsigned char command);//write command function
void LCD_en_dat(unsigned char temp);//write data function
//數(shù)據(jù)
unsigned char code Tab[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
uchar index=0;
uchar ShuMa[6]={0,0,0,0,0,0};//lcd緩沖區(qū)
/////////////中斷程序////////////////
uint i=4000;
uchar bdata flag=0;
sbit time_flag=flag^0;
uint Frequency =0;
unsigned long Frequency1 =0;
uchar High=0;
uchar Low=0;
/***********************************************/
void delay1(uint ticks)
{
uchar i;
for(;ticks!=0;ticks--)for(i=100;i!=0;i--);
}
void ISR_Timer0() interrupt 1
{//Timer0 中斷服務(wù)程序;Timer0 內(nèi)部時鐘模式2
//250us*4000=1000000us=1000ms=1s
if(--i==0)
{
High= TH1; //讀取高位
Low=TL1; //讀取低位
TH1=0;
TL1=0;
time_flag=1;
i=4000;
}
}
/******************************電容測量的程序********************************/
void cap()
{
display(); //刷新lcd
if(time_flag) //刷新顯示緩沖區(qū)
{
Frequency=High;
Frequency<<=8;
Frequency+=Low;
/***********************公式計算****************************/
Frequency1=4800000/Frequency;
/**********************************************************/
ShuMa[5]=Frequency1%10;
Frequency1/=10;
ShuMa[4]=Frequency1%10;
Frequency1/=10;
ShuMa[3]=Frequency1%10;
Frequency1/=10;
ShuMa[2]=Frequency1%10;
Frequency1/=10;
ShuMa[1]=Frequency1%10;
Frequency1/=10;
ShuMa[0]=Frequency1%10;
time_flag=0;
}
}
void initsys()
{
TMOD=0x52;//Timer1外部計數(shù),模式1(16位模式);Timer0 內(nèi)部時鐘模式2
TH1=0;
TL1=0;
TH0=6; // Timer0 250us中斷一次
TL0=6;
ET0=1;
TF0=0;
EA=1;
TR0=1;
TR1=1;
}
void display()
{
delay1(10); //延時
LCD_en_command(0x84);
LCD_en_dat(Tab[ShuMa[index]]);
index++;
delay1(10);
LCD_en_command(0x85);
LCD_en_dat(Tab[ShuMa[index]]);
index++;
delay1(10);
LCD_en_command(0x86);
LCD_en_dat(Tab[ShuMa[index]]);
index++;
delay1(10);
LCD_en_command(0x87);
LCD_en_dat(Tab[ShuMa[index]]);
index++;
delay1(10);
LCD_en_command(0x88);
LCD_en_dat(Tab[ShuMa[index]]);
index++;
delay1(10);
LCD_en_command(0x89);
LCD_en_dat(Tab[ShuMa[index]]);
index++;
delay1(10);
index=0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -