Đề bài của bọn em yêu cầu : Sử dụng chip AT89C51, ADC0804,cảm biến nhiệt LM35 để hiển thị ra màn LCD. Em đã vẽ xong mạch trên protues nhưng khi viết CODE để chạy thì liên tục báo 3 warnings mà em ko biết lỗi ở đâu. Đoạn CODE đây ạ, ai biết sai chỗ nào chỉ giúp em với ạ. Thanks for reading!
#include <AT89X51.H>
#include <stdio.h>
#include<string.h>
#define RS P3_5
#define RW P3_6//RW=0 => ghi du lieu
#define EN P3_7//RW=1 => doc du lieu
//RS=0 => code
//RS=1 => data
#define LCD_PORT P1
#define INTR P3_0
#define RD P3_1
#define WR P3_2
//===========================
void delay_ms(int n)
{
int k,j;
for(k=0;k<n;k++)
{
for(j=0;j<500;j++);
}
}
//==========================
void delay_5ms(){
int i,j;
for(i=0;i<250;i++)
for(j=0;j<4;j++){}
}
//===========================
void delay_15ms(){
int i,j;
for(i=0;i<250;i++)
for(j=0;j<100;j++){}
}
//============================
void LCDWriteCmd(unsigned char c) //CT con ghi du lieu len LCD
{
RS=0;
RW=0;
LCD_PORT=c;
EN=1;
EN=0;
delay_5ms();
}
//==============================
void LCDWriteData(unsigned char c) //CT con doc du lieu tu LCD
{
RS=1;
RW=0;
LCD_PORT=c;
EN=1;
EN=0;
delay_5ms();
}
//=============================
void LCDcursorxy(int x, int y)
{
if((x<1||x>2)&&(y<1||y>16))
{
x=1;
y=1;
}
if(x == 1)
LCDWriteCmd(0x7F+y);
else
LCDWriteCmd(0xBF+y);
}
//===============================
void LCD_init() // Khoi tao LCD
{
delay_15ms();
LCDWriteCmd(0x38);
LCDWriteCmd(0x0C);
LCDWriteCmd(0x06);
LCDWriteCmd(0x01); // Xoa man hinh LCD
}
//================================
void LCD_clear()
{
LCDWriteCmd(0x01);
}
//===============================
void LCD_home()
{
LCDWriteCmd(0x80);
}
//=============================
void LCD_putstr(unsigned char *s)
{
while (*s)
{
LCDWriteData(*s);
s++;
}
}
//============================
void HienThi_ADC(unsigned char t)
{
unsigned char v;
if(t<10)
{ LCDWriteData(t+48);
}else if(t<100){
LCDWriteData(t/10+48);
LCDWriteData(t%10+48);
}else{
v=t/10;
LCDWriteData(v/10+48);
LCDWriteData(v%10+48);
LCDWriteData(t%10+48);
}
}
//==========================================
void main (void)
{
unsigned char gt=0; //gt la bie^n' cho gia tri 8bit ADC
LCD_init();
LCDWriteCmd(0x83);
LCD_putstr("Nhom03KTVT");
while(1)
{
WR=0; // Bat dau chuyen doi gia tri tu ADC
delay_ms(5); // Tao tre de cap nhat du lieu tu ADC
WR=1; //
while(!INTR);
RD=0; // Nhan du lieu da duoc chuyen doi
gt=P2;
LCDWriteCmd(0x01);
LCDWriteCmd(0x83);
LCD_putstr("Nhom03KTVT");
LCDWriteCmd(0xC0);
LCD_putstr("Nhiet do bay gio la:");
HienThi_ADC(gt);
delay_ms(150);
}
}
#include <AT89X51.H>
#include <stdio.h>
#include<string.h>
#define RS P3_5
#define RW P3_6//RW=0 => ghi du lieu
#define EN P3_7//RW=1 => doc du lieu
//RS=0 => code
//RS=1 => data
#define LCD_PORT P1
#define INTR P3_0
#define RD P3_1
#define WR P3_2
//===========================
void delay_ms(int n)
{
int k,j;
for(k=0;k<n;k++)
{
for(j=0;j<500;j++);
}
}
//==========================
void delay_5ms(){
int i,j;
for(i=0;i<250;i++)
for(j=0;j<4;j++){}
}
//===========================
void delay_15ms(){
int i,j;
for(i=0;i<250;i++)
for(j=0;j<100;j++){}
}
//============================
void LCDWriteCmd(unsigned char c) //CT con ghi du lieu len LCD
{
RS=0;
RW=0;
LCD_PORT=c;
EN=1;
EN=0;
delay_5ms();
}
//==============================
void LCDWriteData(unsigned char c) //CT con doc du lieu tu LCD
{
RS=1;
RW=0;
LCD_PORT=c;
EN=1;
EN=0;
delay_5ms();
}
//=============================
void LCDcursorxy(int x, int y)
{
if((x<1||x>2)&&(y<1||y>16))
{
x=1;
y=1;
}
if(x == 1)
LCDWriteCmd(0x7F+y);
else
LCDWriteCmd(0xBF+y);
}
//===============================
void LCD_init() // Khoi tao LCD
{
delay_15ms();
LCDWriteCmd(0x38);
LCDWriteCmd(0x0C);
LCDWriteCmd(0x06);
LCDWriteCmd(0x01); // Xoa man hinh LCD
}
//================================
void LCD_clear()
{
LCDWriteCmd(0x01);
}
//===============================
void LCD_home()
{
LCDWriteCmd(0x80);
}
//=============================
void LCD_putstr(unsigned char *s)
{
while (*s)
{
LCDWriteData(*s);
s++;
}
}
//============================
void HienThi_ADC(unsigned char t)
{
unsigned char v;
if(t<10)
{ LCDWriteData(t+48);
}else if(t<100){
LCDWriteData(t/10+48);
LCDWriteData(t%10+48);
}else{
v=t/10;
LCDWriteData(v/10+48);
LCDWriteData(v%10+48);
LCDWriteData(t%10+48);
}
}
//==========================================
void main (void)
{
unsigned char gt=0; //gt la bie^n' cho gia tri 8bit ADC
LCD_init();
LCDWriteCmd(0x83);
LCD_putstr("Nhom03KTVT");
while(1)
{
WR=0; // Bat dau chuyen doi gia tri tu ADC
delay_ms(5); // Tao tre de cap nhat du lieu tu ADC
WR=1; //
while(!INTR);
RD=0; // Nhan du lieu da duoc chuyen doi
gt=P2;
LCDWriteCmd(0x01);
LCDWriteCmd(0x83);
LCD_putstr("Nhom03KTVT");
LCDWriteCmd(0xC0);
LCD_putstr("Nhiet do bay gio la:");
HienThi_ADC(gt);
delay_ms(150);
}
}