📄 lcd._c
字号:
#include <iom64v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
#include "./lcd.h"
#include "./welcom.h"
#include "./ascii.h"
#include "./power.h"
#include "../Ds1302/ds1302.h"
extern struct time_now timebuf;
/******************************************************************************/
uchar lcd_read_cmd(uchar cs)
{
uchar temp;
LCD_RD;
LCD_CMD;
switch(cs){
case CS1:temp = *(volatile unsigned char *)LCD_STATUS_CS1;break;
case CS2:temp = *(volatile unsigned char *)LCD_STATUS_CS2;break;
case CS3:temp = *(volatile unsigned char *)LCD_STATUS_CS3;break;
}
return temp;
}
void lcd_busy(uchar cs)
{
while((lcd_read_cmd(cs) & STATUS_BUSY)!= 0);
}
void lcd_write_cmd(uchar cs, uchar cmd)
{
lcd_busy(cs);
LCD_WR;
LCD_CMD;
switch(cs){
case CS1:*(volatile unsigned char *)LCD_CMD_CS1 = cmd;break;
case CS2:*(volatile unsigned char *)LCD_CMD_CS2 = cmd;break;
case CS3:*(volatile unsigned char *)LCD_CMD_CS3 = cmd;break;
}
}
void lcd_write_data(uchar cs,uchar data)
{
lcd_busy(cs);
LCD_WR;
LCD_DATA;
switch(cs){
case CS1:*(volatile unsigned char *)LCD_DATA_CS1 = data;break;
case CS2:*(volatile unsigned char *)LCD_DATA_CS2 = data;break;
case CS3:*(volatile unsigned char *)LCD_DATA_CS3 = data;break;
}
}
uchar lcd_read_data(uchar cs)
{
lcd_busy(cs);
LCD_RD;
LCD_DATA;
return(*(volatile unsigned char *)0xef00);
}
void delay_1s(void)
{
unsigned int i;
for(i=0; i<5;i++) delay_ms(200);
}
void lcd_init(void)
{
uchar temp,i;
DDRD |= LCD_RS | LCD_RST;
PORTD |= LCD_RS;
PORTD &= ~LCD_RST;
DDRF |= LCD_245;
PORTF |= LCD_245;
delay_ms(200);
delay_ms(200);
PORTD |= LCD_RST;
delay_ms(200);
delay_ms(200);
while(1){
temp = lcd_read_cmd(CS1);
if((temp & STATUS_RET) == 0) break; //等待复位
}
lcd_write_cmd(CS1, LCD_SHOW_ON);
lcd_write_cmd(CS1, 0xC0);
lcd_write_cmd(CS2, LCD_SHOW_ON);
lcd_write_cmd(CS2, 0xC0);
lcd_write_cmd(CS3, LCD_SHOW_ON);
lcd_write_cmd(CS3, 0xC0);
LCD_DISBLE;
}
//nBitmapDot
void show_welcom(void)
{
uchar const *ps;
uchar ii;
uchar jj;
ps = &nBitmapDot[0];
for(ii=0; ii<8; ii++){
lcd_write_cmd(CS1, 0xb8+ii);
lcd_write_cmd(CS1, 0x40);
for(jj=0; jj<64 ;jj++)
{ lcd_write_data(CS1,*ps++);}
lcd_write_cmd(CS2, 0xb8+ii);
lcd_write_cmd(CS2, 0x40);
for(jj=0; jj<64 ;jj++)
{ lcd_write_data(CS2,*ps++);}
lcd_write_cmd(CS3, 0xb8+ii);
lcd_write_cmd(CS3, 0x40);
for(jj=0; jj<64 ;jj++)
{ lcd_write_data(CS3,*ps++);}
}
LCD_DISBLE;
delay_1s();
}
void show_clear(void)
{
uchar const *ps;
uchar ii;
uchar jj;
ps = &nBitmapDot[0];
for(ii=0; ii<8; ii++){
lcd_write_cmd(CS1, 0xb8+ii);
lcd_write_cmd(CS1, 0x40);
for(jj=0; jj<64 ;jj++)
{ lcd_write_data(CS1,0x00);}
lcd_write_cmd(CS2, 0xb8+ii);
lcd_write_cmd(CS2, 0x40);
for(jj=0; jj<64 ;jj++)
{ lcd_write_data(CS2,0x00);}
lcd_write_cmd(CS3, 0xb8+ii);
lcd_write_cmd(CS3, 0x40);
for(jj=0; jj<64 ;jj++)
{ lcd_write_data(CS3,0x00);}
}
LCD_DISBLE;
}
/////////////////////////////////////////////////////////////////////////
// 在LCD上打印 //
// 启示页号,列号,回转长度,写的页数数据指针 //
/////////////////////////////////////////////////////////////////////////
void show_lcd(uchar page, uchar lie, uchar lcd_chang, uchar size, uchar const *ps ,uchar type)
{
uchar are;
uchar ii,jj;
uchar loop;
uchar lie_save;
loop = 0;
lie_save = lie;
while(size--){
if(lie_save < 64) are = CS1;
else{ if(lie_save < 129) {are = CS2;
if(loop == 0){lie -= 64;loop = 1;}
}
else {are = CS3;
if(loop == 0){lie -= 129;loop = 1;}
}
}
ii = 64 - lie; //本叶可以写多少列
jj = ii;
if(jj > lcd_chang) jj = lcd_chang;
lcd_write_cmd(are, LCD_PAGE+page);
lcd_write_cmd(are, LCD_LIE+lie);
while(jj--){
if(type != 0) lcd_write_data(are,~*ps++);
else lcd_write_data(are,*ps++);
}
if(lcd_chang < 64){page++; continue;}
ii = lcd_chang - ii;
if(ii <= 64){are += 1;
lcd_write_cmd(are, LCD_PAGE+page);
lcd_write_cmd(are, LCD_LIE);
while(ii--){
if(type != 0) lcd_write_data(are,~*ps++);
else lcd_write_data(are,*ps++);
}
}
else{
jj = 64;
are += 1;
lcd_write_cmd(are, LCD_PAGE+page);
lcd_write_cmd(are, LCD_LIE);
while(jj--){
if(type != 0) lcd_write_data(are,~*ps++);
else lcd_write_data(are,*ps++);
}
ii -= 64;
are += 1;
lcd_write_cmd(are, LCD_PAGE+page);
lcd_write_cmd(are, LCD_LIE);
while(ii--){
if(type != 0) lcd_write_data(are,~*ps++);
else lcd_write_data(are,*ps++);
}
}//end else
page++;
}//while(size-)
LCD_DISBLE;
}
/*
*显示主菜单
*/
void show_menu(uchar type)
{
show_lcd(0, 0, 192, 2, &main_lab[0],0); //直选播放
show_lcd(2, 0, 80, 2, &edit[0],0); //编辑播放
show_lcd(2, 80+25, 80, 2,&system[0],0); //系统设置
show_lcd(4, 0, 80, 2,&xuanzhe[0],0); //直选播放
show_lcd(4, 80+25, 80, 2,&luyin[0],0); //录音
show_lcd(6, 0, 80, 2,&suiji[0],0); //随机播放
show_lcd(6, 80+25, 80, 2,&yinyuan[0],0); //音源切换
switch(type)
{
case 0: show_lcd(2, 0, 80, 2, &edit[0],1); //编辑播放
break;
case 1: show_lcd(2, 80+25, 80, 2,&system[0],1); //系统设置
break;
case 2: show_lcd(4, 0, 80, 2,&xuanzhe[0],1); //直选播放
break;
case 3: show_lcd(4, 80+25, 80, 2,&luyin[0],1); //录音
break;
case 4: show_lcd(6, 0, 80, 2,&suiji[0],1); //随机播放
break;
case 5: show_lcd(6, 80+25, 80, 2,&yinyuan[0],1);//音源切换
break;
}
}
void show_set_system(uchar type)
{
show_lcd(0, 0, 192, 2, &sys_lab[0],0);
show_lcd(2, 56, 80, 2, &time[0],0);
show_lcd(3, 56, 80, 2, &data[0],0);
show_lcd(6, 56, 80, 2, &week[0],0);
switch(type)
{
case 0: show_lcd(0, 56, 80, 2, &time[0],1);
break;
case 1: show_lcd(2, 56, 80, 2, &data[0],1);
break;
case 2: show_lcd(4, 56, 80, 2, &week[0],1);
break;
}
}
void show_play(uchar *s,uchar page,uchar type)
{
uchar *ps;
uchar ii;
uint temp;
ii=0;
ps = s;
while(*ps != 0){ps++;ii++;}
ii = ii/2;
ii *= 8;
ii = 96-ii; //起点
ps = s;
while(*ps != 0){if(ii == 128) ii=129;
temp = *ps++;
temp -= 32;
temp *= 16;
show_lcd(page, ii, 8, 2, &nAsciiDot[temp],type); //直选播放
ii += 8;
}
}
void show_init(uchar *s,uchar page,uchar type)
{
uchar *ps;
uchar ii;
uint temp;
ii=0;
ps = s;
while(*ps != 0){if(ii == 128) ii=129;
temp = *ps++;
temp -= 32;
temp *= 16;
show_lcd(page, ii, 8, 2, &nAsciiDot[temp],type); //直选播放
ii += 8;
}
}
/*
*显示播放器空闲
*/
void show_status(void)
{
show_clear();
show_lcd(0, 0, 192, 2, &playstatus[0],0); //直选播放nAsciiDot
}
void show_tiem(void)
{
//ascii
uchar ii;
uint temp;
ii = 16;
temp = timebuf.hour;
temp >>= 4;
temp &= 0x000f;
temp += '0';
temp -= 32;
temp *= 16;
show_lcd(3, ii, 8, 2, &nAsciiDot[temp],0);
ii += 8;
temp = timebuf.hour;
temp &= 0x000f;
temp += '0';
temp -= 32;
temp *= 16;
show_lcd(3, ii, 8, 2, &nAsciiDot[temp],0);
ii += 8;
temp = ':';
temp -= 32;
temp *= 16;
show_lcd(3, ii, 8, 2, &nAsciiDot[temp],0);
ii += 8;
temp = timebuf.min;
temp >>= 4;
temp &= 0x000f;
temp += '0';
temp -= 32;
temp *= 16;
show_lcd(3, ii, 8, 2, &nAsciiDot[temp],0);
ii += 8;
temp = timebuf.min;
temp &= 0x000f;
temp += '0';
temp -= 32;
temp *= 16;
show_lcd(3, ii, 8, 2, &nAsciiDot[temp],0);
ii += 8;
temp = ':';
temp -= 32;
temp *= 16;
show_lcd(3, ii, 8, 2, &nAsciiDot[temp],0);
ii += 8;
temp = timebuf.sec;
temp >>= 4;
temp &= 0x000f;
temp += '0';
temp -= 32;
temp *= 16;
show_lcd(3, ii, 8, 2, &nAsciiDot[temp],0);
ii += 8;
temp = timebuf.sec;
temp &= 0x000f;
temp += '0';
temp -= 32;
temp *= 16;
show_lcd(3, ii, 8, 2, &nAsciiDot[temp],0);
ii = 112;
show_lcd(3, ii, 16, 2, &DotTbl16[9*32],0);//星期
ii += 16;
show_lcd(3, 129, 16, 2, &DotTbl16[10*32],0);//星期
ii += 24;
if(timebuf.week == 0x07) show_lcd(3, ii, 16, 2, &DotTbl16[2*32],0);//星期
else{
temp = timebuf.week;
temp += 10;
show_lcd(3, ii, 16, 2, &DotTbl16[temp*32],0);//星期
}
//下面开始显示年
ii = 40;
temp = '2';
temp -= 32;
temp *= 16;
show_lcd(6, ii, 8, 2, &nAsciiDot[temp],0);
ii += 8;
temp = '0';
temp -= 32;
temp *= 16;
show_lcd(6, ii, 8, 2, &nAsciiDot[temp],0);
ii += 8;
temp = timebuf.year;
temp >>= 4;
temp &= 0x000f;
temp += '0';
temp -= 32;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -