1602的数据写入及CGRAM的使用
#include <iom16.h>
#include <intrinsics.h> #define u8 uchar unsigned char
#define u16 uchar unsigned int
#define uchar unsigned char
#define uint unsigned int uchar zi[]={0x16,0x09,0x08,0x08,0x08,0x09,0x06,0x00}; //自定义字符摄氏度
#include"1602.h"
#include"18b20.h"
void port_init()
{
PORTA=0xff;
A=0xff;
PORTB=0xff;
DDRB=0xff;
PORTC=0xff;
DDRC=0xff;
PORTD=0xff;
DDRD=0x00;
} void setzi() //把设定字存入CGRAM
{
uchar i;
writecmd(0x40); //设置第一个字的起始地址
for(i=0;i<8;i++)
{
writedata(zi[i]);
}
}
void show_temp(uint k)
{
displayonechar(1,1,(k/100)+48);
displayonechar(2,1,(k%100/10)+48);
displayonechar(3,1,'.');
displayonechar(4,1,(k%10)+48);
} void main()
{
uint
; //显示的温度值
port_init();
delay(1000);
init1602();
displaychar(0,0,"Set zi Test");
setzi();
displayonechar(5,1,0x00); //0x00表示 0x40地址的值
while(1)
{
TT=read_temper();
show_temp(TT);
} } //---------------1602.h---------------- #define RS PORTB_Bit0
#define RW PORTB_Bit1
#define EN PORTB_Bit2
#define DATA PORTA
#define busy 0x80 void delay(uint k)
{
uint i,j;
for(i=0;i<k;i++)
for(j=0;j<1140;j++);
}
void wait()
{
uchar val;
DATA=0xff;
RS=0;
RW=1;
__no_operation();
__no_operation();
EN=1;
__no_operation();
__no_operation();
DDRA=0x00;
val=PINA;
while(val&busy)
{
val=PINA;
}
EN=0;
DDRA=0xff;
}
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;
}
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