}
RELAY=0; P3=out; delay(100); RELAY=1;
void key(void ) {
if(KS0==0) delay_ms(1); if(KS0==0) SET_TEMP++; while(!KS0); if(KS1==0) delay_ms(1); if(KS1==0) SET_TEMP--; while(!KS1);
display_onechar(0,9,SET_TEMP/100+'0'); display_onechar(0,10,(SET_TEMP0)/10+'0'); display_onechar(0,11,SET_TEMP+'0'); } main() {
lcd_init();
display_string(0,0,LcdBuf1); display_string(1,0,LcdBuf2); Write_CGRAM(LcdBuf);
//向CGRAM写入自定义的摄氏度符号
display_onechar(0,12,0); //显示自定义的摄氏度符号
21
display_onechar(0,13,1); //显示自定义的摄氏度符号 display_onechar(1,12,0); display_onechar(1,13,1); while(1) {
key(); ADC();
constant_temperature(); display_string(1,9,a); pid();
dac0832(sumout); delay_ms(100);
}
}
附录2 LCD程序
#ifndef LCD_1602_ #define LCD_1602_ #include
unsigned char code LcdBuf[]= {
//自定义汉字 22
5X7;最大能存储64个字节
0x0c,0x12,0x12,0x0c,0x00,0x00,0x00,0x00, 0x0f,0x10,0x10,0x10,0x10,0x10,0x0f,0x00, };
void delay(unsigned int ms) { }
bit lcd_busy()
{ // 测试LCD忙碌状态 bit result; LCD_RS = 0; LCD_RW = 1; LCD_E = 1; _nop_(); _nop_(); _nop_(); _nop_();
result =(LCD_DATA & 0x80); LCD_E = 0; return result; }
unsigned char y; for(;ms>0;ms--)
for(y=120;y>0;y--);
void WriteCommand(unsigned char wdata) {
while(lcd_busy()); LCD_DATA=wdata; LCD_RS=0;
23
LCD_RW=0; LCD_E=1; LCD_E=0; delay(5); LCD_E=1; }
void WriteData(unsigned char wdata) {
while(lcd_busy()); LCD_DATA=wdata; LCD_RS=1; LCD_RW=0; LCD_E=1; LCD_E=0; delay(5); LCD_E=1; }
void lcd_init(void) {
WriteCommand(0x38); WriteCommand(0x38);
WriteCommand(0x38);
delay(5);
WriteCommand(0x08); WriteCommand(0x01); WriteCommand(0x06); WriteCommand(0x0c); }
void set_xy(unsigned char x,unsigned
char y)
24
{
switch (x) {
case 0: y+=0x80; break;
case 1: y+=0xc0; break;
}
WriteCommand(y); }
void display_onechar(unsigned char x,unsigned char y,unsigned char wdate) {
set_xy(x,y); WriteData(wdate); }
void display_string(unsigned char x,unsigned char y,unsigned char *s) {
set_xy(x,y); while(*s) {
WriteData(*s); s++; } }
/******************************************************************/ void Write_CGRAM(unsigned char *p) {
unsigned char i,j,kk;
unsigned char tmp=0x40; //操作CGRAM的命令码 kk=0;
for(j=0;j<2;j++) //64 字节存储空间,可以生成 8 个自定义字符点阵 64X8
25