Home > Back-end >  The small white help, save the children
The small white help, save the children

Time:09-16

For graduation design a first-time microcontroller c language, asked to do a single-chip microcomputer control, matrix keyboard input, LCD display, ds18b20 temperature measurement of the temperature control system, the software for a long time, before, according to the simulation only but ds18b20 have been only a high level, press matrix keyboard only line scan is not listed the scanning process, press down to also have no reaction, now change east west change not even display shows, bosses to help me see where is wrong, should be changed places, small white in this thank you bosses
//LCD display
#include
# # ifndef __1602_H__
# define __1602_H__
# define LCD_DATA P0 mouth//LCD data
# define uint unsigned int
# define uchar unsigned char
Sbit LCD_BUSY=LCD_DATA ^ 7;//LCD busy signal a
Sbit LCD_RS=P2 ^ 0;
Sbit LCD_RW=P2 ^ 1;
Sbit LCD_EN=P2 ^ 2;

Void delay (uint ms)
{
Uint I;
While (ms -)
{
For (I=0; I<125; i++);
}
}


Void LCD_check_busy (void)//busy
{
While (1)
{
LCD_EN=0;
LCD_RS=0;//instruction register communication
LCD_RW=1;//read the data
LCD_DATA=https://bbs.csdn.net/topics/0xff;
LCD_EN=1;
if(! LCD_BUSY) break;
}
LCD_EN=0;
}

Void LCD_cls (void)//LCD screen clearing
{

LCD_check_busy ();
LCD_RS=0;
LCD_RW=0;
LCD_DATA=https://bbs.csdn.net/topics/1;
LCD_EN=1;
LCD_EN=0;

}

Void LCD_write_instruction (unsigned char LCD_instruction)//written instructions to the LCD
{
LCD_check_busy ();
LCD_RS=0;
LCD_RW=0;//write data

LCD_DATA=https://bbs.csdn.net/topics/LCD_instruction;
LCD_EN=1;
LCD_EN=0;
}

Void LCD_write_data (unsigned char LCD_data)//output a byte data into the LCD
{
LCD_check_busy ();
LCD_RS=1;
LCD_RW=0;

LCD_DATA=https://bbs.csdn.net/topics/LCD_data;
LCD_EN=1;
LCD_EN=0;
}

Void LCD_set_position (unsigned char x)//LCD the cursor to the x
{
LCD_write_instruction (0 x80 + x);
}



Void LCD_printc (unsigned char lcd_data)//output a character to the LCD
{
LCD_write_data (lcd_data);
}

Void LCD_prints (unsigned char * lcd_string)//output a string to the LCD
{
Unsigned char I=0;
While (lcd_string [I]!=0 x00)
{
LCD_write_data (lcd_string [I]);
i++;
}
}

Void LCD_c initialization (void)//LCD
{
LCD_write_instruction x3c (0);
X0c LCD_write_instruction (0);
LCD_write_instruction x06 (0);
LCD_cls ();
}

//DS18B20
# # ifndef DS18B20_H
# define DS18B20_H
Sbit DS=P1 ^ 5;//define I/o port
Uint temp.




/* * DS18B20 reset function/
Void dsreset ()//reset
{
Uint I;
DS=0;
I=103;
While (i> 0) - I;
DS=1;
I=4;
While (i> 0) - I;
}
/* * DS18B20 read function/
Uchar tmpread ()//read a byte
{
Uchar j, k, dat.
Uint I;
for(j=1; j<=8; J++)
{
DS=0; i++;//delay
DS=1; i++; i++;
K=DS;
I=8; While (i> 0) - I;
Dat=(k<7) | (dat> 1);//read the data to its lowest level in the front of keep a byte in the DAT
}
Return (dat);
}
/* * DS18B20 write function/
The void tmpwritebyte uchar (dat)//write a byte
{
Uint I;
Uchar j;
Bit testb;
for(j=1; j<=8; J++)
{
Testb=dat& 0 x01;
Dat=dat> 1;
If (testb)//write 1
{
DS=0;
i++; i++;
DS=1;
I=8; While (i> 0) - I;
}
The else
{
DS=0;//write 0
I=8; While (i> 0) - I;
DS=1;
i++; i++;
}
}
}
/* DS18B20 the data transformation function */
Void tmpchange ()//DS18B20 temperature change
{
Dsreset ();
Delay (18);
Tmpwritebyte (0 XCC);//skip reading memory ROM
X44 tmpwritebyte (0);//convert
}
/* * DS18B20 read temperature function/
Uint TMP ()//read temperature
{
Float t;
Uchar a, b;
Dsreset ();
Delay (1);
Tmpwritebyte (0 XCC);
The xbe tmpwritebyte (0);
Delay (10);
A=tmpread ();//a for the low byte 8
B=tmpread ();//b for the high 8-bit byte
Temp=b;//temp for temperature UINT 16 bit
Temp<=8;//two bytes together
Temp=temp | a;
If (b> 127)
{
Temp=~ temp + 1;
}
T=temp * 0.0625;//temp/16 is the true temperature value tt. Seven integers, 4 decimal places
Temp=t * 10 + 0.5;//expand ten times took out the first decimal
Return (temp);
}




Void lcd_DS (void)
{

LCD_set_position (0 x02);//show T=address
LCD_prints (" T=");
LCD_set_position x04 (0);//show temperature address
LCD_printc (temp/10 + 0 x30 100%);//show the temperature of high
X05 LCD_set_position (0);
LCD_printc (temp/10 + 0 x30 10%);//show the temperature of the second
LCD_set_position x06 (0);
LCD_prints (". ");//show the decimal point
X07 LCD_set_position (0);
LCD_printc (temp % 10 + 0 x30);//show the temperature of the lowest
LCD_set_position (0 x08);//show the "degree"
XDF LCD_printc (0);
X09 LCD_set_position (0);
LCD_prints (" C ");
}
# endif

//matrix keyboard
#include
Unsigned char GE, SHI XIAO;
Unsigned char wei, ji, Goal;
Uchar code TAB []=
{
Xd7 x77 0, 0 xb7, 0, 0 xe7,
XBB 0 x7b, 0, 0 XDB, 0 xeb,
XBD 0 x7d, 0, 0 XDD, 0 xed,
Xde x7e 0, 0 xbe, 0, 0 xee
};
Sbit key_a=P3 ^ 0;
Sbit key_b=P3 ^ 1;
Sbit key_c=P3 ^ 2;
Sbit key_d=P3 ^ 3;
Sbit key_1=P3 ^ 4;
Sbit key_2=P3 ^ 5;
Sbit key_3=P3 ^ 6;
Sbit key_4=P3 ^ 7;



Uchar keyscan (void)
{
Uchar c_h, c_l; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related