📄 lcd_k51.c
字号:
#include<lcd_k51.h>
/************************************************/
/* Program for YM12864 */
/************************************************/
void lcd_delay(unsigned int i)
{
while(i--)
{
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
}
}
void instruct(uchar ix)
{
/* LCD_CTR&=~RS;
LCD_CTR|=RW;
LCD_CTR|=E;
do
{
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
}
while((LCD_BUS&0x80)!=0);
*/
lcd_delay(5*lcm_clk);
LCD_CTR&=~RS;
LCD_CTR&=~RW;
LCD_CTR|=E;
LCD_BUS=ix;
LCD_CTR&=~E;
}
void write_abyte(uchar ox )
{
/* LCD_CTR&=~RS;
LCD_CTR|=RW;
LCD_CTR|=E;
do
{
_NOP();
_NOP();
_NOP();
_NOP();
_NOP();
}
while((LCD_BUS&0x80)!=0);
*/
lcd_delay(5*lcm_clk);
LCD_CTR|=RS;
LCD_CTR&=~RW;
LCD_CTR|=E;
LCD_BUS=ox;
LCD_CTR&=~E;
}
#ifndef HZ
void dis_hz_str(uchar x, uchar y, uchar *p_hz)
{
data uchar loc,*p;
//data uint xi;
code uchar xline[5]={0,1,3,2,4};
x=xline[x];
instruct(home);
loc=((x<<3)+y-9)|0x80;
instruct(loc);
p=p_hz;
// xi=((*p++)<<8)|*p++;
// xi=*p++;
while(*p)
{
// write_word(xi);
write_abyte(*p++);
// xi=((*p++)<<8)|*p++;
// xi=*p++;
// write_abyte(xi);
// xi=*p++;
}
}
#endif
void dis_str(uchar x, uchar y, uchar *str)
{
uchar loc,*p;
const uchar xline[5]={0,1,3,2,4};
p=str;
x=xline[x];
instruct(home);
loc=(16*(x-1)+y-1);
if(loc&0x01)
{
loc/=2;
instruct(loc|0x80);
write_abyte(' ');
}
else
{
loc/=2;
instruct(loc|0x80);
}
while(*p)
{
write_abyte(*p++);
}
}
#ifndef BMP
void con_disp (uchar data1,uchar data2,uchar x0,uchar y0,uchar xl,uchar yl)
{
uchar i,j;
for(j=0;j<yl;j++)
{
for(i=0;i<xl;i++)
{
instruct (0x34);
instruct (y0+j);
instruct (x0+i);
instruct (0x30);
write_abyte (data1);
write_abyte(data2);
}
}
instruct (0x36);
}
void img_disp (uchar code *img)
{
uchar i,j;
for(j=0;j<32;j++)
{
for(i=0;i<8;i++)
{
instruct(0x34);
instruct (y1+j);
instruct(x1+i);
instruct (0x30);
write_abyte(img[j*16+i*2]);
write_abyte(img[j*16+i*2+1]);
// write_abyte(0x00);
//write_abyte(0x00);
}
}
for(j=32;j<64;j++)
{
for(i=0;i<8;i++)
{
instruct(0x34);
instruct(y1+j-32);
instruct(x2+i);
instruct (0x30);
write_abyte(img[j*16+i*2]);
write_abyte(img[j*16+i*2+1]);
//write_abyte(0x00);
//write_abyte(0x00);
}
}
instruct (0x36);
}
#endif
void initial_screen(void)
{
instruct(0x30);
lcd_delay(10*lcm_clk);
// instruct(0x30);
// lcd_delay(30);
instruct(dis_on);
lcd_delay(10*lcm_clk);
instruct(clear);
lcd_delay(500*lcm_clk);
instruct(in_mode);
lcd_delay(5*lcm_clk);
instruct(home);
lcd_delay(500*lcm_clk);
instruct(0x0c);
lcd_delay(5*lcm_clk);
}
#ifndef FLT
void itoa_float(float x,unsigned char *str,uchar wei)
{
int cheng[5]={1,10,100,1000,10000};
unsigned int n,c,q;
float f;
unsigned char chn,*p,str2[20];
data unsigned char i,j;
if(x<0)
{
*str++='-';
x=-x;
}
n=(int)x;
f=x-n;
n=f*cheng[wei]*10;
n=n%10;
if(n>4)
{n=f*cheng[wei]+1;}
else
{n=f*cheng[wei];}
//n=f*1000;
q=n;
p=str2;
j=0;
while(n!=0)
{
chn=n%10;
n=n/10;
*p++=chn+'0';
j++;
}
//n=f*cheng[wei]+1;
n=q;
if(n==0)
{
for(i=0;i<wei;i++)
{
*p++='0';
j++;
}
}
else
{
while(n<cheng[wei-1])
{ *p++='0';
j++;
n=n*10;
}
}
*p++='.';
j++;
n=(int)x;
//n=n*cheng[wei];
if(n==0)
{*p++='0';
j++;}
while(n!=0)
{ chn=n%10;
n=n/10;
*p++=chn+'0';
j++;
}
c=j;
if(j!=0)
{
p--;
for(i=0;i<j;i++)
*str++=*p--;
// *str++=' ';
// *str++=' ';
}
else
{
*str++='0';
// *str++=' ';
// *str++=' ';
}
*str=0;
return;
}
#endif
void itoa(int x,unsigned char *str)
{
unsigned int n;
unsigned char chn,*p,str1[8];
unsigned char i,j;
if(x<0)
{
*str++='-';
x=-x;
}
n=x;
p=str1;
j=0;
while(n!=0)
{
chn=n%10;
n=n/10;
*p++=chn+'0';
j++;
}
if(j!=0)
{
p--;
for(i=0;i<j;i++)
*str++=*p--;
// *str++=' ';
// *str++=' ';
}
else
{
*str++='0';
// *str++=' ';
// *str++=' ';
}
*str=0;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -