#include<reg51.h>
#include<string.h>
#include<stdio.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int口定义
sbit CLK=P3^4;//ADC0832时钟端
sbit DIO=P3^3;//ADC832数据输入输出
sbit AD_CS=P3^5;//ADC0832片选端
#define jiaquan_CH 1
#define tianranqi_CH 0
sbit beep=P1^5;
#define LCD12864_DataPort P0
sbit LCD12864_EN=P2^1;
sbit LCD12864_RW=P2^2;
sbit LCD12864_RS=P2^3;
sbit LCD12864_PSB=P2^5;
void delay(unint time)//Time ms
{
uint j,k;
for(k=time;k>0;k--)
for(j=150;j>0;j--);
}
//AD转换函数
//ch--通道选择,
ch=0,0通
ch=1,1通道
uint sum;
uchar RH,RH_H=60,RH_L=20,state,ms,time_num,cs;
bit beep1,zt,s1;
void DelayUs2x(unsigned char t)
{
while(--t);
}
void DelayMs(unsigned char t)
{
while(t--)
{
DelayUs2x(245);
DelayUs2x(245);
}
}
unsigned int A_D()
{
unsigned char i;
unsigned char dat;
ADC0832_CS=1;
ADC0832_CLK=0;
ADC0832_CS=0;
ADC0832_DIO=1;
ADC0832_CLK=1;
ADC0832_CLK=0;
ADC0832_DIO=1;
ADC0832_CLK=1;
ADC0832_CLK=0;
ADC0832_DIO=0;
ADC0832_CLK=1;
ADC0832_CLK=0;
ADC0832_DIO=1;
ADC0832_CLK=1;
for(i=0;i<8;i++)
{
ADC0832_CLK=1;
ADC0832_CLK=0;
dat<<=1;
dat|=(unsigned char)ADC0832_DIO;
}
ADC0832_CS=1;
return dat;
}
void delay(uint T)
{
while(T--);
}
bit LCD_Check_Busy(void)
{
DataPort= 0xFF;
RS_CLR;
RW_SET;
EN_CLR;
_nop_();
EN_SET;
return (bit)(DataPort & 0x80);
}
void LCD_Write_Com(unsigned char com)
{
// while(LCD_Check_Busy());
DelayMs(5);
RS_CLR;
RW_CLR;
EN_SET;
DataPort= com;
_nop_();
EN_CLR;
}
void LCD_Write_Data(unsigned char Data)
{
//while(LCD_Check_Busy());
DelayMs(5);
RS_SET;
RW_CLR;
EN_SET;
DataPort= Data;
_nop_();
EN_CLR;
}
void LCD_Clear(void)
{
LCD_Write_Com(0x01);
DelayMs(5);
}
void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s)
{
if (y == 0)
{
LCD_Write_Com(0x80 + x); //表示第一行
}
else
{
LCD_Write_Com(0xC0 + x); //表示第二行
}
while (*s)
{
LCD_Write_Data( *s);
s ++;
}
}
void LCD_Write_Char(unsigned char x,unsigned char y,unsigned char Data)
{
if (y == 0)
{
LCD_Write_Com(0x80 + x);
}
else
{
LCD_Write_Com(0xC0 + x);
}
LCD_Write_Data( Data);
}
LCD12864功能函数
void LCD12864_delayms(unsigned int a)
{
unsigned int x,y;
for(x=a;x0;x--)
for(y=110;y0;y--)
{
;
}
}
void LCD12864_write_cmd(unsigned char cmd)写命令
{
LCD12864_RS=0;
LCD12864_RW=0;
LCD12864_EN=1;
LCD12864_DataPort=cmd;
LCD12864_delayms(1);
LCD12864_EN=0;
LCD12864_delayms(1);
}
------------------------------------------------
清屏
------------------------------------------------
void ClrScreen()
{
LCD12864_write_cmd(0x01);
LCD12864_delayms(15);
}
void LCD12864_write_data(unsigned char dat) 写数据
{
LCD12864_RS=1;
LCD12864_RW=0;
LCD12864_EN=1;
LCD12864_DataPort=dat;
LCD12864_delayms(1);
LCD12864_EN=0;
LCD12864_delayms(1);
}
void LCD12864_write_String(unsigned char dat)写字符串,可写汉字
{
for(;dat!='0';dat++)
{
LCD12864_write_data(dat);
}
}
在固定的位置显示固定的数据
unsigned char x 第几行显示,从0开始
unsigned char y 第几个位置 从0开始
unsigned char dat 要显示的内容,可为汉字
void LCD12864_write_String_pos(unsigned char x,unsigned char y,unsigned char dat)
{
if(x==0)第一行
{
LCD12864_write_cmd(0x80+y);
LCD12864_write_String(dat);
}
if(x==1)第二行
{
LCD12864_write_cmd(0x90+y);
LCD12864_write_String(dat);
}
if(x==2) 第三行
{
LCD12864_write_cmd(0x88+y);
LCD12864_write_String(dat);
}
if(x==3)第四行
{
LCD12864_write_cmd(0x98+y);
LCD12864_write_String(dat);
}
}
void LCD12864_init(void)初始化
{
LCD12864_PSB=1;并行显示
LCD12864_write_cmd(0x30);基本指令集
LCD12864_write_cmd(0x0c);开显示,不显示光标
LCD12864_Draw_Full(empty);写入一个空白的图形,防止数据干扰
}
=======================
主函数
void main(void)
{
flag=0;
LCD12864_init();//12864初始化
start_display();
while(1)
{
keyscan();按键扫描函数
jiaquan_ADCdat=ADC0832(jiaquan_CH);
jiaquan_Disdat[0]=jiaquan_ADCdat100; 百位
jiaquan_Disdat[1]=(jiaquan_ADCdat10)%10; 十位
jiaquan_Disdat[2]=jiaquan_ADCdat%10; 个位
delay(500);
tianranqi_ADCdat=ADC0832(tianranqi_CH);
tianranqi_Disdat[0]=tianranqi_ADCdat100; 百位
tianranqi_Disdat[1]=(tianranqi_ADCdat10)%10; 十位
tianranqi_Disdat[2]=tianranqi_ADCdat%10; 个位
if(flag==1)
{
ADCresult_display();
jing_bao();
}
}
}
|