单片机问题求助,在线等!
#include <reg52.h>#define uchar unsigned char #define uint unsigned intconst uchar code sk[12] = "Temperature:";sbit lcdrs = P2^1;sbit lcden = P2^0;sbit oe = P2^7;sbit eoc = P2^2;sbit st = P2^3;sbit ale = P2^6;void delay(uchar j) { // ÑÓʱº¯Êý uchar i = 0; while (--j) { for (; i<110; ++i) ; }}void write_data(uchar dat) { // write_data function lcdrs = 1; lcden = 1; P0 = dat; delay(3); lcden = 0; lcdrs = 0;}void write_com(uchar com) { // write_com function lcdrs = 0; lcden = 1; P0 = com; delay(3); lcden = 0; lcdrs = 1;}void lcd_init() { write_com(0x38); delay(3); write_com(0x8); delay(3); write_com(0x1); delay(3); write_com(0x6); delay(3); write_com(0xc); delay(3);}int main(){ uchar te[5] = {'0','0','0','.','0'}; int n = 0; int getdata = 0; lcd_init(); // ³õʼ»¯ write_com(0x80+0x2); for (; n<12; ++n) { write_data(sk[n]); delay(1); } while (1) { ale = 1; st = 0; st = 1; // Æô¶¯×ª»» st = 0; while (!eoc); // µÈ´ýÐźÅת»»Íê±Ï£¬ eoc=1 ʱÍê±Ï oe = 1; // enable output getdata = P1; oe = 0; getdata = getdata*10*0.4; te[0] = '0' + getdata/1000; te[1] = '0' + getdata%1000/100; te[2] = '0' + getdata%100/10; te[4] = '0' + getdata%10; for (n=0; n<5; ++n) { write_com(0x80+0x46+n); write_data(te[n]); } } }