#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
/*#define CLK_H PORTB|=(1<<1)
#define CLK_L PORTB&=~(1<<1)
#define SID_H PORTB|=(1<<0)
#define SID_L PORTB&=~(1<<0)*/
#define CLK_H PORTC|=(1<<PC4)
#define CLK_L PORTC&=~(1<<PC4)
#define SID_H PORTC|=(1<<PC3)
#define SID_L PORTC&=~(1<<PC3)
#define uchar unsigned char
#define uint unsigned int
void send_byte(uchar byte)
{
uint i;
for (i=0;i<8;i++)
{
if(byte&0x80)
SID_H; //为1 给1
else
SID_L; //为0 给0
CLK_L;//拉低时钟
CLK_H;//拉高时钟
byte=byte<<1;
}
}
void write_com(uchar com)
{
send_byte(0xf8);//step 1
send_byte(0xf0&com);//step 2
send_byte(0xf0&(com<<4));//step 3
_delay_ms(50);
}
void write_data(uchar data)
{
send_byte(0xfa);
send_byte(0xf0&data);
send_byte(0xf0&(data<<4));
_delay_ms(50);
}
void lcd12864_init()
{
_delay_ms(50);
write_com(0x30);
_delay_ms(50);
write_com(0x0f);//整体和游标显示
_delay_ms(50);
write_com(0x01);
_delay_ms(50);
}
void display()
{
write_com(0x80);
_delay_ms(50);
write_data(200);
_delay_ms(50);
write_com(0x80+0x10);
_delay_ms(50);
write_data(0x31);
}
void main()
{
DDRB|=(1<<PB0)|(1<<PB1);
DDRC|=(1<<PC3)|(1<<PC4);
lcd12864_init();
_delay_ms(100);
while (1)
{
display();
}
}
上面是我的代码,是串口写的,记得刚写好的时候还可以看到游标闪烁,但写了一个数据进去后就出问题了,再没显示,只是屏幕亮着,请问你们遇到过这种情况吗
|