资源描述
/* MCU Xtal Freq. 12.000MHz */
/* Contains 0802 LCM Driver */
/* 1 Second Gate */
#include
#include
#define LCD_RS P3_0 /* Switch Register: Command/Data */
#define LCD_RW P3_1 /* Switch Mode:!Write/Read */
#define LCD_EN P3_4 /* LCD Operation Enable */
#define LCD_DATA P1
#define LCD_CLEAR 0x01
#define MAX_X 0x10 /* Defines How Many LTR Can Be Disp.In a Row. */
#define MAX_Y 0x02 /* Defines How Many LTR Can Be Disp.In a Line. */
#define uchar unsigned char
#define uint unsigned int
/* The Declaration of Some Functions about LCD Driver */
void Delay5ms(void);
void Delay400ms(void);
void LCD_WrtCmd(uchar Command, Busy_C);
void Init_LCD(void);
uchar Get_LCD_Status(void);
void LCD_WrtData(uchar Data);
void Putcharxy(uchar x,uchar y,unsigned disp_data);
void Outtextxy(uchar x,uchar y,uchar *disp_data);
/* For Counter */
uchar timer0_count = 0, timer1_count = 0;
uchar temp1, temp2, temp3;
uchar tag = 0;
/* Timer0 */
void timer0() interrupt 1 using 1
{
timer0_count ++;
if (timer0_count==16) {
EA = 0;
tag = 1;
TR1 = 0;
TR0 = 0;
temp1=timer1_count;
temp2=TH1;
temp3=TL1;
TH0=189;
TL0=208;
timer1_count=0;
TH1=0;
TL1=0;
TR0=1;
TR1=1;
EA=1;
timer0_count=0;
}
}
void timer1() interrupt 3 using 2
{
timer1_count ++;
}
/* Main Function */
void main(void)
{
unsigned long count;
uchar freq[9];
unsigned long res;
uchar i;
Delay400ms();
Init_LCD();
Outtextxy(0,0,"HAM FREQ");
Outtextxy(0,1,"COUNTER!");
for(i=5;i>0;i--) Delay400ms();
TMOD = 0X51; //TMR1 external input: 0x51
IE = 0X8A;
IP = 0X08; //Timer1 piority higher than timer0
TH0= 189;
TL0= 208;
TH1 = 0;
TL1 = 0;
TR0 = 1; //start TMR0 here
TR1 = 1;
while(1)
{
if(tag){
count = temp1 * 65536;
count = count + temp2*256;
count = count + temp3;
res=100000;
for(i=0;i<8;i++)
{
if(i==2) continue;
if(i==6) continue;
freq=count/res+'0';
count%=res;
res/=10;
}
freq[2]=',';
freq[6]='.';
freq[8]='\0';
Outtextxy(0,0,"Freq:kHz");
Outtextxy(0,1,freq);
}
}
}
void Init_LCD(void)
{
LCD_DATA=0;
LCD_WrtCmd(0x38,0);
/* Two Lines, 5x7 Font Style, No Cursors, No Blink */
Delay5ms();
LCD_WrtCmd(0x38,0);
Delay5ms();
LCD_WrtCmd(0x38,0);
Delay5ms();
LCD_WrtCmd(0x38,1);
LCD_WrtCmd(0x80,1);
LCD_WrtCmd(LCD_CLEAR,1);
LCD_WrtCmd(0x06,1);
LCD_WrtCmd(0x0c,1);
}
uchar Get_LCD_Status(void)
{
LCD_DATA=0xff;
LCD_EN=0;
LCD_EN=0;
LCD_RW=1;
LCD_RS=0;
LCD_EN=1;
while(LCD_DATA & 0x80);
LCD_EN=0;
return LCD_DATA;
}
void LCD_WrtData(uchar Data)
{
LCD_EN=0;
Get_LCD_Status();
LCD_DATA=Data;
LCD_RS=1;
LCD_RW=0;
LCD_EN=0;
LCD_EN=0;
LCD_EN=1;
LCD_EN=1;
LCD_EN=0;
}
void LCD_WrtCmd(uchar Command, Busy_C)
{
LCD_EN=0;
if(Busy_C) Get_LCD_Status();
LCD_DATA=Command;
LCD_RS=0;
LCD_RW=0;
LCD_EN=0;
LCD_EN=0;
LCD_EN=1;
LCD_EN=1;
LCD_EN=0;
}
void Putcharxy(uchar x,uchar y,unsigned disp_data)
{
y=y&(MAX_Y-1);
x=x&(MAX_X-1);
if(y) x+=0x40;
x+=0x80;
LCD_WrtCmd(x,1);
LCD_WrtData(disp_data);
}
void Outtextxy(uchar x,uchar y,uchar *disp_data)
{
uchar char_length,j;
char_length=strlen(disp_data);
y=y&(MAX_Y-1);
x=x&(MAX_X-1);
for (j=0;j<CHAR_LENGTH;J++)
{
Putcharxy(x,y,disp_data[j]);
x++;
}
}
void Delay5ms(void)
{ uint i=6025;while(i--); }
void Delay400ms(void)
{
uchar i=5; uint j;
while(i--)
{ j=7888; while(j--); }
}
展开阅读全文