1602自定义字符显示摄氏度符号
void writecmd(uchar cmd)
{
wait();
RS=0;
RW=0;
__no_operation();
DATA=cmd;
__no_operation();
EN=1;
__no_operation();
__no_operation();
EN=0;
}
void writedata(uchar data)
{
wait();
RS=1;
RW=0;
__no_operation();
DATA=data;
__no_operation();
EN=1;
__no_operation();
__no_operation();
EN=0;
}
{
wait();
RS=1;
RW=0;
__no_operation();
DATA=data;
__no_operation();
EN=1;
__no_operation();
__no_operation();
EN=0;
}
void displayonechar(uchar x,uchar y,uchar dda)
{
y&=0x01;
x&=0x0f;
if(y)x|=0x40;
x|=0x80;
writecmd(x);
writedata(dda);
}
void displaychar(uchar x,uchar y,uchar *p)
{
y&=0x01;
x&=0x0f;
while(*p!= )
{
if(x<=0x0f)
{
displayonechar(x,y,*p);
p++;
x++;
}
}
}
{
y&=0x01;
x&=0x0f;
while(*p!= )
{
if(x<=0x0f)
{
displayonechar(x,y,*p);
p++;
x++;
}
}
}
void init1602()
{
delay(15);
writecmd(0x38);
delay(5);
writecmd(0x38);
delay(5);
writecmd(0x38);
writecmd(0x80);
writecmd(0x01);
writecmd(0x06);
writecmd(0x0c);
}
//--------------18B20.h------------
uchar teml,temh;
uchar sign;
uchar Flag_1820Error;
uint tempp; //温度值
/*********************************/
void delay_15us(void) //15us左右
{
uchar x=27;
while(x)
{
x--;
}
}
/********************************/
void delay_60us(void) //60us左右
{
uchar x=117;
while(x)
{
x--;
}
}
void init_1820(void)
{
uchar i;
uint j=0;
PORTC|=(1<<7); //"1"
PORTC&=~(1<<7); //"0"
for(i=0;i<8;i++)delay_60us();//480us以上
PORTC|=(1<<7); //"1"
DDRC&=~(1<<7); //"PINC7 is INPUT"
delay_15us(); //15~60us
delay_15us();
Flag_1820Error=0;
while(PINC&(1<<7))
{ delay_60us();
j++;
if(j>=18000){Flag_1820Error=1;break;}
}
DDRC|=(1<<7); //PORTC7 is OUTPUT
PORTC|=(1<<7); //"1"
for(i=0;i<4;i++)delay_60us(); //240us
}
/********************************/
void delay_5us(void) //5us左右
{
uchar x=7;
while(x)
{
x--;
}
}
/********************************/
void write_1820(uchar x)
{
uchar m;
for(m=0;m<8;m++)
{
if(x&(1< {PORTC&=~(1<<7);delay_5us(); //"0",5us
PORTC|=(1<<7); //write"1"
delay_15us(); //15~45us
delay_15us();
delay_15us();
}
else
{PORTC&=~(1<<7);delay_15us();//"0",15us
delay_15us(); //write"0"
delay_15us(); //15~45us
delay_15us();
PORTC|=(1<<7); //"1"
}
}
PORTC|=(1<<7); //"1"
}
/*******************************/
uchar read_1820(void)
{
uchar temp,k,n;
temp=0;
for(n=0;n<8;n++)
{
PORTC&=~(1<<7); //"0"
delay_5us();
PORTC|=(1<<7); //"1"
delay_5us();
DDRC&=~(1<<7); //"PINC7 is INPUT"
k=(PINC&(1<<7)); //读数据,从低位开始
if(k)
temp|=(1< else
temp&=~(1< delay_15us(); //45us
delay_15us();
delay_15us();
DDRC|=(1<<7); //PORTC7 is OUTPUT
}
return (temp);
}
/*************************************/
uint read_temper(void)
{
uchar TX; //小数位
uchar TZ; //整数位
init_1820(); //复位18b20
write_1820(0xcc); // 发出转换命令
write_1820(0x44);
;;;;;;
init_1820();
write_1820(0xcc); //发出读命令
write_1820(0xbe);
teml=read_1820(); //读数据byte1
temh=read_1820(); //byte2
TX=teml&0x0f;
temh=temh<<4;
temh|=(teml&0xf0)>>4;
TZ=temh;
tempp=TZ*10+TX;
return tempp;
}
void write_1820(uchar x)
{
uchar m;
for(m=0;m<8;m++)
{
if(x&(1<
PORTC|=(1<<7); //write"1"
delay_15us(); //15~45us
delay_15us();
delay_15us();
}
else
{PORTC&=~(1<<7);delay_15us();//"0",15us
delay_15us(); //write"0"
delay_15us(); //15~45us
delay_15us();
PORTC|=(1<<7); //"1"
}
}
PORTC|=(1<<7); //"1"
}
/*******************************/
uchar read_1820(void)
{
uchar temp,k,n;
temp=0;
for(n=0;n<8;n++)
{
PORTC&=~(1<<7); //"0"
delay_5us();
PORTC|=(1<<7); //"1"
delay_5us();
DDRC&=~(1<<7); //"PINC7 is INPUT"
k=(PINC&(1<<7)); //读数据,从低位开始
if(k)
temp|=(1<
temp&=~(1<
delay_15us();
delay_15us();
DDRC|=(1<<7); //PORTC7 is OUTPUT
}
return (temp);
}
/*************************************/
uint read_temper(void)
{
uchar TX; //小数位
uchar TZ; //整数位
init_1820(); //复位18b20
write_1820(0xcc); // 发出转换命令
write_1820(0x44);
;;;;;;
init_1820();
write_1820(0xcc); //发出读命令
write_1820(0xbe);
teml=read_1820(); //读数据byte1
temh=read_1820(); //byte2
TX=teml&0x0f;
temh=temh<<4;
temh|=(teml&0xf0)>>4;
TZ=temh;
tempp=TZ*10+TX;
return tempp;
}
评论