?? 1.txt
字號:
#include<reg52.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tab0[]="AD0809數字電壓表";
uchar code tab1[]="Vx =";
sbit sid=P0^1;//12864數據輸入
sbit sck=P0^0;//12864時鐘輸入
#define com 0 //指令標志
#define dat 1 //數據標志
uint temp,a1,a2,a3,a;
//********12864相關函數*****************//
void w_12864byte(uchar byte)//寫字節
{
uchar i;
for(i=0;i<8;i++)
{
sck=0;
byte<<=1;
sid=CY;
sck=1;
sck=0;
}
}
void w_12864(bit dat_com,uchar byt) //寫入函數
{
uchar temp;
if(dat_com==0) //為零,寫入指令
temp=0xf8; //11111,RS(0),RW(0),0
else //否則,寫入數據
temp=0xfa; //11111,RS(1),RW(0),0
w_12864byte(temp);
w_12864byte(byt&0xf0); //寫入高四位
w_12864byte(byt<<4); //寫入低四位
}
void init_12864(void)//初始化12864
{
w_12864(com,0x30); //基本指令功能.
w_12864(com,0x0c); //顯示打開,關光標,反白關.
w_12864(com,0x01); //清屏指令.
w_12864(com,0x06); //AC自動加一
}
void lcd_display()
{
uchar i;
w_12864(com,0x80);
for(i=0;i<16;i++)
{
w_12864(dat,tab0[i]);
}
w_12864(com,0x90);
for(i=0;i<6;i++)
{
w_12864(dat,tab1[i]);
}
}
void adc0809_data(void)
{
uchar i;
w_12864(com,0x80);
for(i=0;i<16;i++)
{
w_12864(dat,tab0[i]);
}
temp = a*196;
a1=temp/10000;
a2=temp%10000/1000;
a3=temp%10000%1000/100;
w_12864(com,0x90+2);
w_12864(dat,0x30+a1); //寫入溫度
w_12864(dat,0x2e);
w_12864(dat,0x30+a2);
w_12864(dat,0x30+a3);
a++;
if(a==256)
a=0;
}
void delay(uint z)
{
uint x,y;
for(x=0;x<z;x++)
for(y=0;y<120;y++);
}
void main()
{
init_12864();
lcd_display();
while(1)
{
adc0809_data();
delay(100);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -