[mw_shl_code=c,true]#include <reg52.h>
#include <intrins.h>
#include <string.h>
#define uchar unsigned char
#define uint unsigned long int
uint connect_flag;
uint gao,di;
char wendu[5];
char state[2];
sbit so=P1^0;
sbit cs=P1^1;
sbit sck=P1^2;
sbit lcd_en=P1^5;
sbit lcd_rw=P1^6;
sbit lcd_rs=P1^7;
sbit lcd_psb=P3^3;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}
void delay_ms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=1;y>0;y--);
}
uint read_data()
{
uint i;
uint temp=0;
cs=0;
_nop_(); //D15
sck=0;
_nop_();
sck=1;
_nop_();
sck=0;
for(i=4;i>0;i--) //"高四位"
{
sck=1;
gao=gao<<1;
if(so==1)
{
gao=gao | 0x01;
}
else
gao=gao | 0x00;
_nop_();
sck=0;
}
for(i=8;i>0;i--)//"低八位"
{
sck=1;
di=di<<1;
if(so==1)
{
di=di | 0x01;
}
else
di=di | 0x00;
_nop_();
sck=0;
}
sck=0;
_nop_();
sck=1;
_nop_();
sck=0;
connect_flag=so;
cs=1;
gao=gao<<8;
gao=gao | di;
return gao;
}
bit lcd_busy()
{
bit result;
lcd_rs = 0;
lcd_rw = 1;
lcd_en = 1;
_nop_();
_nop_();
result = (bit)(P2 & 0x80);
_nop_();
lcd_en = 0;
return(result);
}
void lcd_wcmd(uchar cmd)
{
while(lcd_busy());
lcd_rs = 0;
lcd_rw = 0;
lcd_en = 0;
_nop_();
_nop_();
P2 = cmd;
delay_ms(1);
lcd_en = 1;
delay_ms(1);
lcd_en = 0;
}
void lcd_wdat(uchar dat)
{
while(lcd_busy());
lcd_rs = 1;
lcd_rw = 0;
lcd_en = 0;
P2 = dat;
_nop_();
_nop_();
lcd_en = 1;
delay_ms(1);
lcd_en = 0;
}
void lcd_init()
{
P2=0Xff;
delay(2);
lcd_psb=1;
delay(1);
lcd_wcmd(0x30);
delay(1);
lcd_wcmd(0x0c);
delay(1);
lcd_wcmd(0x01);
delay(5);
}
void display(uchar addr,uchar *str)
{
uint i;
lcd_wcmd(addr);
for(i=0;i<strlen(str);i++)
{
lcd_wdat(str);
delay_ms(10);
}
}
void main()
{
uint temp=0;
uint temp1=0;
int i;
lcd_init();
while(1)
{
temp=read_data();
temp1=temp/4;
for(i=200;i>0;i--)
{
state[0]=connect_flag+'0';//D2"控制工作状态"
wendu[0]=temp1/100+'0';
wendu[1]=temp1/10%10+'0';
wendu[2]=temp1%10+'0';
display(0x80,"西北农林科技大学");
display(0x90,"温度:");
display(0x93,wendu);
display(0x88,"热电偶状态:");
display(0x8e,state);
display(0x95,"C");
display(0x98,"欢迎指导");
}
}
}[/mw_shl_code]
|