📄 lc7981hg.c
字号:
/* Wrote by WZH 2003/5/21 */
//#include<dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <i86.h>
#include <string.h>
#define baseaddr 0x118//0x230
#define outportb(x,y) outp(x,y)
#define inportb(x) inp(x)
/******************* Function Define ************************/
void LCD_Init() /* LCD initial */
{
outportb(baseaddr+6,5);
outportb(baseaddr+5,3);
}
int Read_Status() /* Reading the BUSY flag */
{
int t;
outportb(baseaddr+4,1);
outportb(baseaddr+4,2);
outportb(baseaddr+4,6);
outportb(baseaddr+4,4);
t=inportb(baseaddr+3) & 0x80;
outportb(baseaddr+5,4);
if(t == 0x80) return 1;
else return 0;
}
void Write_Command(unsigned char data) /* Write instruction register */
{
while(Read_Status()); /* Reading the BUSY flag */
outportb(baseaddr+5,1);
outportb(baseaddr+4,2);
outportb(baseaddr+4,4);
outportb(baseaddr+5,6);
outportb(baseaddr+3,data);
outportb(baseaddr+5,4);
}
void Write_Data(unsigned char data) /* Write data register */
{
while(Read_Status()); /* Reading the BUSY flag */
outportb(baseaddr+5,1);
outportb(baseaddr+5,2);
outportb(baseaddr+4,4);
outportb(baseaddr+5,6);
outportb(baseaddr+3,data);
outportb(baseaddr+5,4);
}
void Dis_LED(char d) /* LED control */
{
if(d == 0)
outportb(baseaddr+5,7);
else if(d == 1)
outportb(baseaddr+4,7);
}
/*************** End of Function Define *******************/
void Mode_Control(unsigned char data)
{
Write_Command(0);
Write_Data(data);
}
void Set_CharPit(unsigned char data)
{
Write_Command(1);
Write_Data(data);
}
void Set_CharNum(unsigned char data)
{
Write_Command(2);
Write_Data(data);
}
void Set_DisDuty(unsigned char data)
{
Write_Command(3);
Write_Data(data);
}
void Set_CurPos(unsigned char data)
{
Write_Command(4);
Write_Data(data);
}
void Set_DisAddr(unsigned char low,unsigned char upper)
{
Write_Command(8);
Write_Data(low);
Write_Command(9);
Write_Data(upper);
}
void Set_CurAddr(unsigned char low,unsigned char upper)
{
Write_Command(0xa);
Write_Data(low);
Write_Command(0xb);
Write_Data(upper);
}
void Dis_Data(unsigned char data)
{
Write_Command(12);
Write_Data(data);
}
void main(int argc, const char *argv[])
{
// int t;
// unsigned char data=0x21;
int i=0,j=0,k=0;
unsigned char charl=0x00, charr=0x00;
unsigned char mat[16][2],chinease[3]="我",zimu[16], word[]="I am CSM-300F!";
unsigned char chinese[]="北京四方继保自动化有限公司";
int zone, code;
FILE *HZK, *ASC;
LCD_Init(); /* LCD initial */
Dis_LED(1); /* LED light */
Mode_Control(0x32); /* Mode control */
Set_CharPit(0x07); /* Setting the character pitch */
Set_CharNum(0x12); /* Setting the number of characters */
Set_DisDuty(0x50); /* Setting the time division number(display duty) */
Set_CurPos(0);
Set_DisAddr(0,0);
Set_CurAddr(0,0);
if((HZK=fopen(argv[1],"rb"))==NULL)exit(0);
if((ASC=fopen(argv[2],"rb"))==NULL)exit(0);
i=chinease[0]-0xa0;
j=chinease[1]-0xa0;// 获得区码与位码
fseek(HZK,(94*(i-1)+(j-1))*32l,SEEK_SET);
fread(mat,32,1,HZK);
for(i=0;i<5;i++)
{
for(j=0;j<16;j++)
{
charl = 0x00;
/*for(k=0;k<8;k++)
{
if((mat[j][0]&(0x01<<k))!=0x00)
{
charl |= (0x80>>k);
}
}*/
charr = 0x00;
/*for(k=0;k<8;k++)
{
if((mat[j][1]&(0x01<<k))!=0x00)
{
charr |= (0x80>>k);
}
}
*/
for(k=0;k<10;k++)
{
Dis_Data(charl);
Dis_Data(charr);
}
}
}
for(j=0;j<16;j++)
{
charl = 0x00;
for(k=0;k<8;k++)
{
if((mat[j][0]&(0x01<<k))!=0x00)
{
charl |= (0x80>>k);
}
}
charr = 0x00;
for(k=0;k<8;k++)
{
if((mat[j][1]&(0x01<<k))!=0x00)
{
charr |= (0x80>>k);
}
}
//for(k=0;k<10;k++)
{
Set_CurAddr((j*20)%256, (j*20)/256);
Dis_Data(charl);
Dis_Data(charr);
}
}
for(i=0;i<14;i++)
{
fseek(ASC,word[i]*16l,SEEK_SET);
fread(zimu,16,1,ASC);
for(j=0;j<16;j++)
{
charl = 0x00;
for(k=0;k<8;k++)
{
if((zimu[j]&(0x01<<k))!=0x00)
{
charl |= (0x80>>k);
}
}
//for(k=0;k<10;k++)
{
Set_CurAddr((j*20+3+i)%256, (j*20+3+i)/256);
Dis_Data(charl);
}
}
}
for(i=0;i<13;i++)
{
zone = chinese[i*2] - 0xa0;
code = chinese[i*2+1] - 0xa0;
fseek(HZK, (94*(zone-1)+(code-1))*32l, SEEK_SET);
fread(mat, 32, 1, HZK);
for(j=0;j<16;j++)
{
charl = 0x00;
for(k=0;k<8;k++)
{
if((mat[j][0]&(0x01<<k))!=0x00)
{
charl |= (0x80>>k);
}
}
charr = 0x00;
for(k=0;k<8;k++)
{
if((mat[j][1]&(0x01<<k))!=0x00)
{
charr |= (0x80>>k);
}
}
//for(k=0;k<10;k++)
{
Set_CurAddr(((j+16*(1+(i/10)))*20+i*2)%256, ((j+16*(1+(i/10)))*20+i*2)/256);
Dis_Data(charl);
Dis_Data(charr);
}
}
//getch();
}
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -