/*
*功能: 利用iic发送数据,在数码管上显示,并通过串口发生到上位机,
* 且在lcd1602上显示"Han Zhu Ying Xue"
* "1754410821@qq.com";
*作者: 徐冉
*日期: 2013-05-29-22:21 2013-5-2919:15 - 22:17
*备注: 程序已经顺利通过调试,耗时3小时。
*/
/*********51hei开发板***********/
/********AT89C52-RC MCU***********/
#include
#define write_add 0xa0
#define read_add 0xa1
typedef unsigned int uint;
typedef unsigned char uchar;
sbit wela = P2^7;
sbit dula = P2^6;
//i2c
sbit SCL = P2^1;
sbit SDA = P2^0;
//LCD1602
sbit RS = P1^0;
sbit RW = P1^1;
sbit EN = P2^5;
sbit BUSY = P0^7;
uchar num, flag;
uchar code string_1[] = "Han Zhu Ying Xue";
uchar code string_2[] = "1754410821@qq.com";
uchar code table[] = {
0x3F, //"0"
0x06, //"1"
0x5B, //"2"
0x4F, //"3"
0x66, //"4"
0x6D, //"5"
0x7D, //"6"
0x07, //"7"
0x7F, //"8"
0x6F //"9"
};
/********************************************************************/
/**********************LCD1602底层驱动程序***************************/
/********************************************************************/
//delay: 延时xms
void delay(uint xms)
{
uchar i, j;
for(i = 0; i < xms; i++)
for(j = 0; j < 110; j++);
}
//wait: 判忙等待
void wait()
{
P0 = 0xff;
do
{
RS = 0;
RW = 1;
EN = 0;
EN = 1;
}while(BUSY == 1);
EN = 0;
}
//write:cmd 写入命令
void write_cmd(uchar cmd)
{
RS = 0;
RW = 0;
EN = 0;
P0 = cmd;
EN = 1;
EN = 0;
}
//write:data 写入数据
void write_data(uchar datas)
{
RS = 1;
RW = 0;
EN = 0;
P0 = datas;
EN = 1;
EN = 0;
}
//send:string 发送一串字符
void send_string(uchar* str)
{
while(*str != '