|
执行完lcd_init()后,就显示了全部字符.清屏也清除不了.
初始化只设置 1/2bias,4comm 和 启动内部振荡器, 不打开显示的话, 上电的一瞬间会有几个笔段亮了,很快又暗了. 内部振荡器不启动的话则不会.
用的是AVR mega 16,11.0592M晶振,-0s优化(用-00的话居然需要占103%的空间.....)
tCLK最大要125us,我延时都设置成200us了啦
#include <avr/io.h>
#include <util/delay.h>
//#include "lcd_code.h"
#define CS_LOW PORTC &= 0xFE
#define CS_HIGH PORTC |= 0x01
#define RD_LOW PORTC &= 0xFD
#define RD_HIGH PORTC |= 0x02
#define WR_LOW PORTC &= 0xFB
#define WR_HIGH PORTC |= 0x04
#define DATA_LOW PORTC &= 0xF7
#define DATA_HIGH PORTC |= 0x08
//下面是驱动程序定义的一个显示缓冲区,共16个字节,128位
volatile unsigned int lcd_buffer[8]={0,0,0,0,0,0,0,0};
//这个函数可以向HT1621B写入一个命令;用户可能需要在语句间增加必要的延时
void send_lcd_command(unsigned char command)
{
CS_LOW;
_delay_us(5);
WR_LOW; //PRESENT 100 COMMAND CODE
DATA_HIGH;
_delay_us(200);
WR_HIGH;
_delay_us(5);
WR_LOW;
DATA_LOW;
_delay_us(200);
WR_HIGH;
_delay_us(5);
WR_LOW;
DATA_LOW;
_delay_us(200);
WR_HIGH;
_delay_us(5);
for (unsigned short int i =0;i<=7;i++)
{
WR_LOW;
if ((command & 0x80) !=0) DATA_HIGH; else DATA_LOW;
_delay_us(200);
WR_HIGH;
_delay_us(5);
command = command << 1;
}
WR_LOW;
_delay_us(200);
WR_HIGH;
_delay_us(5);
CS_HIGH;
}
//这个函数可以将显示缓冲区刷新到HT1621B;用户可能需要在语句间增加必要的延时
void flood_lcd_data(void)
{
unsigned int temp_data;
CS_LOW;
_delay_us(5);
WR_LOW; //PRESENT 101 DATA CODE
DATA_HIGH;
_delay_us(200);
WR_HIGH;
_delay_us(5);
WR_LOW;
DATA_LOW;
_delay_us(200);
WR_HIGH;
_delay_us(5);
WR_LOW;
DATA_HIGH;
_delay_us(200);
WR_HIGH;
_delay_us(5);
for (unsigned short int i =0;i<=5;i++)
{
WR_LOW;
DATA_LOW;
_delay_us(200);
WR_HIGH;
_delay_us(5);
}
for (unsigned short int i =0;i<=7;i++)
{
temp_data = lcd_buffer;
for (unsigned short int j=0;j<=15;j++)
{
WR_LOW;
if ((temp_data & 0x01) !=0) DATA_HIGH; else DATA_LOW;
_delay_us(200);
WR_HIGH;
_delay_us(5);
temp_data = temp_data >> 1;
}
}
_delay_us(5);
CS_HIGH;
}
//初始化HT1621B
void lcd_init(void)
{
send_lcd_command(0x28); //1/2bias,4comm
send_lcd_command(0x03); //启动内部振荡器
send_lcd_command(0x01); //打开显示
}
//清除全部液晶的显示,同时清空显示缓冲区
void lcd_clr()
{
for (int i=0; i<=7;i++) lcd_buffer=0;
flood_lcd_data();
}
int main()
{
DDRA = 0xff;
PORTA = 0x00;
DDRC = 0xFF;
PORTC = 0xFF;
lcd_init();
flood_lcd_data();
/*
lcd_clr();
for(int i=0;i<=127;i++) lcd_char(i,1);
*/
PORTA = 0xff;
while (1);
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|