📄 lcd.c
字号:
#include <mega16.h>
#include <delay.h>
#include <head_lcd.h>
#include <tab_char.h>
unsigned char change_char(unsigned char char_x)
{
unsigned char tab_temp[8];
unsigned char temp;
tab_temp[0]=(char_x&0x80)>>7;
tab_temp[1]=(char_x&0x20)>>4;
tab_temp[2]=(char_x&0x08)>>1;
tab_temp[3]=(char_x&0x02)<<2;
tab_temp[4]=(char_x&0x01)<<4;
tab_temp[5]=(char_x&0x04)<<3;
tab_temp[6]=(char_x&0x10)<<2;
tab_temp[7]=(char_x&0x40)<<1;
temp=(tab_temp[0]|tab_temp[1]|tab_temp[2]|tab_temp[3]|tab_temp[4]|tab_temp[5]|tab_temp[6]|tab_temp[7]);
return(temp);
}
//8*8 char font
//112*48,line:6(0-5),row:14(0-13)
void written_char(unsigned char line,unsigned char row,unsigned char char_data)
{
unsigned int Address_master,Address_slave;
unsigned int Address_slave_x;
unsigned char Address_tab[3];
unsigned char i,j;
if(row<8)
{
for(i=0;i<8;i++)
{
Address_master =((unsigned int)(8*line+i)*32+7-row);
Address_slave =((unsigned int)(8*line+i)*32+6+row);
Address_tab[0]=(unsigned char)((Address_master>>4)&0xf0)|(unsigned char)(Address_slave>>8);
Address_tab[1]=(unsigned char)((Address_master&0xf0))|(unsigned char)((Address_slave>>4)&0x0f);
Address_tab[2]=(unsigned char)((Address_master<<4)&0xf0)|(unsigned char)(Address_slave&0x0f);
RAM_ADRESS=0;
for(j=0;j<3;j++)
{
RAM_WRITTEN=0;
PORTC=Address_tab[j];
RAM_WRITTEN=1;
}
RAM_ADRESS=1;
RAM_WRITTEN=0;
PORTC=change_char(tab_char[char_data][i]);
RAM_WRITTEN=1;
}
}
else
{
for(i=0;i<8;i++) //从机上行显示
{
Address_slave =((unsigned int)(8*line+i)*32+6+row);
Address_tab[0]=(unsigned char)((Address_slave>>8));
Address_tab[1]=(unsigned char)((Address_slave>>4));
Address_tab[2]=(unsigned char)((Address_slave&0x0f));
RAM_ADRESS=0;
for(j=0;j<3;j++)
{
RAM_WRITTEN=0;
PORTC=Address_tab[j];
RAM_WRITTEN=1;
}
RAM_ADRESS=1;
RAM_WRITTEN=0;
PORTC=(change_char(tab_char[char_data][i]));
RAM_WRITTEN=1;
}
for(i=0;i<8;i++) //从机下行显示
{
Address_slave_x =((unsigned int)(8*line+i)*32+13-row);
Address_tab[0]=(unsigned char)(Address_slave_x>>8);
Address_tab[1]=(unsigned char)(Address_slave_x>>4);
Address_tab[2]=(unsigned char)(Address_slave_x&0x0f);
RAM_ADRESS=0;
for(j=0;j<3;j++)
{
RAM_WRITTEN=0;
PORTC=Address_tab[j];
RAM_WRITTEN=1;
}
RAM_ADRESS=1;
RAM_WRITTEN=0;
PORTC=((change_char(tab_char[char_data][i]))>>4);
RAM_WRITTEN=1;
}
}
}
void lcd_init(void) //初始化LCD
{
unsigned char init_tab[3] ={0xaa,0x0,0x0};
unsigned char init_data[6] ={0x22,0xee,0x77,0xcc,0x66,0x0};
//unsigned char init_data[6] ={0x0,0xcc,0x66,0xcc,0x44,0x0}; //other init data
unsigned char i;
RAM_EN=0;
RAM_ADRESS=0;
for(i=0;i<3;i++)
{
RAM_WRITTEN=0;
PORTC=init_tab[i];
RAM_WRITTEN=1;
}
RAM_ADRESS=1;
for(i=0;i<6;i++)
{
RAM_WRITTEN=0;
PORTC=init_data[i];
RAM_WRITTEN=1;
}
}
void clear_display(void)
{
unsigned char i,j,k;
for(i=0;i<6;i++)
{
for(j=0;j<14;j++)
{
for(k=0;k<8;k++)
{
written_char(i,j,Char_nop);
}
}
}
}
void main(void) //主函数
{
unsigned int i;
PORTC=0x00; //PORT ininteally
DDRC=0xff;
PORTB=0x00;
DDRB=0x3F;
POWER_EN=1; //stand moudle,all output pin to gnd level
POWER_EN=0; //OPEN POWER FOR IC
light=1; //LCD's light open
lcd_init(); //初始化LCD
clear_display(); //清除LCD上的所有数据
while(1)
{
for(i=0;i<62;i++)
{
written_char(3,3,i);
delay_ms(1000);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -