?? 130.c
字號:
#include<reg52.h>
#include<math.h>
#include <intrins.h>
#include <absacc.h>
#define DB P2 /*LCD8位數據*/
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit RS=P1^7; /*LCD RS*/
sbit RW=P1^6; /*LCD RW*/
sbit E=P1^5; /*LCD E */
long data fout; /*輸出頻率*/
void delay(int b) /*延時控制程序*/
{int i;
for(i=0;i<b;i++);
}
void clearlcd(void) /*清屏*/
{RS=0;
RW=0;
DB=0x01;
E=1;
delay(1520);
E=0;
}
void Readbusy(void) /*判斷是否忙*/
{RS=0;
RW=1;
E=1;
E=1;
while(DB^7==1) /*忙一直判斷*/
{if(DB^7==0)break;} /*不忙跳出*/
E=0;
}
void Write(unsigned c) /*寫入LED*/
{RS=1;
RW=0;
DB=c;
E=1;
E=1;
E=0;
}
void Display(void) /*顯示*/
{int a;
uchar b;
b=0x7A; /* z */
Readbusy();
Write(b);
b=0x48; /* H */
Readbusy();
Write(b);
a=fout%10000;
b=0x30|a;
Readbusy();
Write(b);
a=fout%1000/10;
b=0x30|a;
Readbusy();
Write(b);
a=fout%100/100;
b=0x30|a;
Readbusy();
Write(b);
a=fout%10/1000;
b=0x30|a;
Readbusy();
Write(b);
a=fout/10000;
b=0x30|a;
Readbusy();
Write(b);
}
void Setlcd(unsigned c) /*設置LED*/
{RS=0;
RW=0;
DB=c;
E=1;
E=1;
E=0;
}
void Rstlcd(void) /*初始設置*/
{delay(15000);
Setlcd(0x38);
delay(4100);
Setlcd(0x38);
delay(4100);
Setlcd(0x38);
delay(4100);
Setlcd(0x38);
delay(4100);
Setlcd(0x30); /*第二行SET Function*/
delay(160);
Setlcd(0x08); /*關顯示*/
delay(160);
clearlcd(); /*清楚顯示*/
delay(160);
Setlcd(0x05); /*輸入模式設定*/
delay(160);
Setlcd(0x0F); /*開顯示*/
}
void Home(void) /*光標復位*/
{RS=0;
RW=0;
DB=0x02;
E=1;
delay(1520);
E=0;
}
void main(void) /*主函數*/
{fout=0;
Rstlcd();
Readbusy(); /*初始LCD*/
Setlcd(0x80);
Readbusy(); /*判斷是否忙*/
Display();
while(1)
{Readbusy(); /*判斷是否忙*/
Display(); /*顯示*/
Home();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -