是哪里出问题了嘛
#include <reg52.h>
#include <intrins.h>
typedef unsigned char u8;
typedef unsigned int u16;
sbit SCL = P2^0;
sbit SDA = P2^1;
u8 dis_tab[] =
{0x00,0xE0,0x10,0x08,0x08,
0x10,0xE0,0x00,0x00,0x0F,
0x10,0x20,0x20,0x10,0x0F,0x00};/*"0",0*/
void delay(u16 num)
{
u16 x,y;
for(x = num;x > 0;x--)
for(y = 110;y > 0;y--);
}
void delay5us()
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void iic_start()
{
SCL = 1;
_nop_();
SDA = 1;
delay5us();
SDA = 0;
delay5us();
}
void iic_stop()
{
SDA = 0;
_nop_();
SCL = 1;
delay5us();
SDA = 1;
delay5us();
}
bit iic_ack()
{
SCL = 1;
delay5us();
if(SDA) //SDA为高:非应答
{
SCL = 0;
_nop_();
iic_stop();
return 0;
}
else //SDA为低:应答
{
SCL = 0;
_nop_();
return 1;
}
}
void iic_send_1byte(u8 byte)
{
u8 i;
for(i = 0;i < 8;i++)
{
SCL = 0;
_nop_();
if(byte & 0x80)
{
SDA = 1;
_nop_();
}
else
{
SDA = 0;
_nop_();
}
SCL = 1;
_nop_();
byte <<= 1;
}
SCL = 0;
_nop_();
SDA = 1;
_nop_();
}
/************
/*lcd写命令
************/
void LCD12864_write_command(u8 cmd)
{
iic_start();
iic_send_1byte(0x78);
if(!iic_ack())
{
iic_stop();
return 0;
}
iic_send_1byte(0x00);
if(!iic_ack())
{
iic_stop();
return 0;
}
iic_send_1byte(cmd);
iic_send_1byte(0x00);
if(!iic_ack())
{
iic_stop();
return 0;
}
_nop_();
iic_stop();
}
/**********
/*lcd写数据
**********/
void LCD12864_write_data(u8 *dat)
{
iic_start();
iic_send_1byte(0x78);
if(!iic_ack())
{
iic_stop();
return 0;
}
iic_send_1byte(0x40);
if(!iic_ack())
{
iic_stop();
return 0;
}
iic_send_1byte(*dat);
if(!iic_ack())
{
iic_stop();
return 0;
}
iic_stop();
_nop_();
}
/**********
/*寻址
**********/
void LCD12864_position(u8 i,u8 j)
{
LCD12864_write_command(0xb0 + i);
LCD12864_write_command(0x00 | (j >> 4));
LCD12864_write_command(0x10 | (j & 0x0f));
}
/**********
/*初始化
**********/
void LCD12864_Initial()
{
Delay(3);
LCD12864_write_command(0x8d);
LCD12864_write_command(0x14);
LCD12864_write_command(0xaf);
LCD12864_write_command(0xae);
LCD12864_write_command(0x20);
LCD12864_write_command(0x10);
LCD12864_write_command(0xb0);
LCD12864_write_command(0xc8);
LCD12864_write_command(0x00);
LCD12864_write_command(0x10);
LCD12864_write_command(0x40);
LCD12864_write_command(0x81);
LCD12864_write_command(0xff);
LCD12864_write_command(0xa1);
LCD12864_write_command(0xa6);
LCD12864_write_command(0xa8);
LCD12864_write_command(0x3f);
LCD12864_write_command(0xa4);
LCD12864_write_command(0xd3);
LCD12864_write_command(0x00);
LCD12864_write_command(0xd5);
LCD12864_write_command(0xf0);
LCD12864_write_command(0xd9);
LCD12864_write_command(0x22);
LCD12864_write_command(0xda);
LCD12864_write_command(0x12);
LCD12864_write_command(0xdb);
LCD12864_write_command(0x20);
LCD12864_write_command(0x8d);
LCD12864_write_command(0x14);
LCD12864_write_command(0xaf);
}
/***********
/*lcd连续显示
***********/
void LCD12864_more_show(u8 *dat)
{
u8 i,j;
for(i = 0;i < 8;i++)
{
for(j = 0;j < 128;j++)
{
LCD12864_position(i.j);
LCD12864_write_data(*dat++);
}
}
}
void main()
{
LCD12864_Initial();
LCD12864_position();
while(1)
{
LCD12864_more_show(dis_tab);
}
}
|