📄 mainline.c
字号:
{
UINT8 flag = 1;
while((flag & 0x3) != 3)
{
delay(10);
flag = LcdCom;
}
}
void ReadySTA3() //读状态并判断STA3状态准备好
{
UINT8 flag = 1;
while((flag & (1 << 3)) == 0)
{
delay(10);
flag = LcdCom;
}
}
void LcdClr()
{
UINT16 R6;
ReadySTA01();
LcdData = 0x00;
ReadySTA01();
LcdData = 0x00;
ReadySTA01();
LcdCom = 0x24;
ReadySTA01();
LcdCom = 0xb0;
for(R6=0;R6<0xFFFF;R6++)
{
ReadySTA3();
LcdData = 0x00;
}
ReadySTA3();
LcdCom = 0xb2;
}
/*Draw graphic function
Set LCD address pointer
Set graphic home address 0x0000,Set graphic area 32, just is 256/8
row:row number,0...127; col:column number,0...29.
*/
void SetLcdAddr(UINT8 row, UINT8 col)
{
UINT8 LcdRow, LcdCol, i;
i = row % 8;
if(i) //odd number row
{
LcdRow = row / 8;
LcdCol = col + 32 * i; //LCD实际行数的转换
}
else //even number row
{
LcdRow = row / 8;
LcdCol = col;
}
ReadySTA01();
LcdData = LcdCol;
ReadySTA01();
LcdData = LcdRow;
ReadySTA01();
LcdCom = 0x24;
}
//Draw Dot; Row < 128, Col < 240. that is Row=0...127;Col=0...239
void DrawDot(UINT8 Row, UINT8 Col)
{
UINT8 LcdCol, tmp, bitnum;
LcdCol = Col / 8; //确定列数, 范围0...29
tmp = Col % 8; //确定列中的位
if(tmp == 0) //列(字节)中的高位与低位交换
bitnum = 7;
else if(tmp == 1)
bitnum = 6;
else if(tmp == 2)
bitnum = 5;
else if(tmp == 3)
bitnum = 4;
else if(tmp == 4)
bitnum = 3;
else if(tmp == 5)
bitnum = 2;
else if(tmp == 6)
bitnum = 1;
else if(tmp == 7)
bitnum = 0;
//Set address pointer
SetLcdAddr(Row, LcdCol);
ReadySTA01();
LcdCom = 0xF8 + bitnum;
}
//Draw column Line; starow=0...127, stacol=0...239, endrow >= starow
void DrawColLine(UINT8 starow, UINT8 stacol, UINT8 endrow)
{
for(; starow <= endrow; starow++)
{
DrawDot(starow, stacol);
}
}
//Draw row Line; starow=0...127, stacol=0...239, endcol >= stacol
void DrawRowLine(UINT8 starow, UINT8 stacol, UINT8 endcol)
{
for(; stacol <= endcol; stacol++)
{
DrawDot(starow, stacol);
}
}
/*Draw text
row:row number,0...127
col:column number,0...29,每个表示一个字节,与画点的不同.
unicode: 内码值,通过这个值来查寻汉字的编码.
当返回值是0是,表示没有与内码相对应的汉字,返回1表示正确.
*/
int DrawText(UINT8 row, UINT8 col, UINT16 codeval)
{
UINT8 i,j;
for(i=0; i< CHAR_SIZE; i++) //查找与内码相对应的编码
{
if(TextCode[i].value == codeval)
break;
if(i == CHAR_SIZE - 1)
return 0;
}
for(j=0;j<32;j=j+2)
{
SetLcdAddr(row, col);
ReadySTA01();
LcdCom = 0xB0;
ReadySTA3();
LcdData = TextCode[i].data[j];
ReadySTA3();
LcdData = TextCode[i].data[j+1];
ReadySTA3();
LcdCom = 0xB2;
row++;
}
return 1;
}
//test draw text 宋体9号
int TestDrawText(UINT8 row, UINT8 col, UINT16 codeval)
{
UINT8 i,j;
for(i=0; i< TEST_SIZE; i++) //查找与内码相对应的编码
{
if(TestCode[i].value == codeval)
break;
if(i == TEST_SIZE - 1)
return 0;
}
for(j=0;j<24;j=j+2)
{
SetLcdAddr(row, col);
ReadySTA01();
LcdCom = 0xB0;
ReadySTA3();
LcdData = TestCode[i].data[j];
ReadySTA3();
LcdData = TestCode[i].data[j+1];
ReadySTA3();
LcdCom = 0xB2;
row++;
}
return 1;
}
//test draw char 宋体12号
int TestDrawChar(UINT8 row, UINT8 col, UINT16 codeval)
{
UINT8 i,j;
for(i=0; i< CHAR_SIZE; i++) //查找与内码相对应的编码
{
if(TestChar[i].value == codeval)
break;
if(i == CHAR_SIZE - 1)
return 0;
}
for(j=0;j<16;j++)
{
SetLcdAddr(row, col);
ReadySTA01();
LcdData = TestChar[i].data[j];
ReadySTA01();
LcdCom = 0xC0;
row++;
}
return 1;
}
//Draw curve, 共200点.
void DrawCurve(UINT16 *buf)
{
UINT8 row, col, i;
for(i=0;i<190;i++)
{
row = 71 - (buf[i] - 0x8000) / 655;
col = 20 + i + 1;
DrawDot(row, col);
}
}
void FigDisp(UINT8 row, UINT8 col, UINT16 figure)
{
//covert figure to -9.999...9.999V
UINT16 flag, fig1, fig2, fig3, fig4;
UINT16 ffig;
flag =0; //flag=0时, 表示是正数
if(figure < 0x8000)
flag = 1;
else
figure = figure - 0x8000;
ffig = (UINT16)((figure * 10 * 1000) / 0x8000);
fig1 = (UINT16)(ffig / 1000);
fig2 = (UINT16)((ffig - fig1 * 1000) / 100);
fig3 = (UINT16)((ffig - fig1 * 1000 - fig2 * 100) / 10);
fig4 = ffig - fig1 * 1000 - fig2 * 100 - fig3 * 10;
/*
printk("fig1, fig2, fig3, fig4 is %x, %x, %x, %x\n", fig1, fig2, fig3, fig4);
fig1 = (UINT16)ffig; //取第1位
fig2 = (UINT16)((ffig - fig1) * 10); //取第2位
fig3 = (UINT16)((((ffig - fig1) *10) - fig2) * 10);
fig4 = (UINT16)((((((ffig - fig1) *10) - fig2) * 10) - fig3) * 10);
*/
DrawText(row,col,0x0003); //电
DrawText(row,col + 2,0x0004); //压
TestDrawChar(row,col + 4,0x000B); //:
if(flag)
{
TestDrawChar(row,col + 6,0x000D);
}
else
{
TestDrawChar(row, col + 11 + 1, 0x000F);
}
TestDrawChar(row,col + 6 + flag,fig1);
TestDrawChar(row,col + 7 + flag,0x000A);
TestDrawChar(row,col + 8 + flag,fig2);
TestDrawChar(row,col + 9 + flag,fig3);
TestDrawChar(row,col + 10 + flag,fig4);
TestDrawChar(row,col + 11 + flag,0x000E);
}
int main()
{
AT91_SYS->EBI_SMC2_CSR[4] = (AT91C_SM_RWHOLD | AT91C_SM_RWSETUP | AT91C_SM_ACESS |
AT91C_SM_DRP | AT91C_SM_DBW | AT91C_SM_BAT |
AT91C_SM_TDF | AT91C_SM_WSEN | AT91C_SM_NWS);
//GRAPHIC HOME ADDRESS SET
ReadySTA01();
LcdData = 0x00;
ReadySTA01();
LcdData = 0x00;
ReadySTA01();
LcdCom = 0x42;
//GRAPHIC AREA SET
ReadySTA01();
LcdData = 32;
ReadySTA01();
LcdData = 0x00;
ReadySTA01();
LcdCom = 0x43;
//"OR" mode
ReadySTA01();
LcdCom = 0x80; //or
//Cursor pattern set 3 lines
ReadySTA01();
LcdCom = 0xa3;
ReadySTA01();
LcdCom = 0x98;
while(1)
{
LcdClr(); //clear display start to test
//test draw char titles16*16
DrawText(2,4,0x0003);
DrawText(2,7,0x0004);
DrawText(2,10,0x0005);
DrawText(2,13,0x0006);
DrawText(2,16,0x0007);
DrawText(2,19,0x0008);
DrawText(2,22,0x0009);
DrawText(2,25,0x000A);
FigDisp(60,1,0x0000);
FigDisp(60,1,0x8e80);
FigDisp(60,1,0x9be0);
FigDisp(60,1,0xc0ff);
FigDisp(80,2,0x2000);
FigDisp(80,2,0xB322);
FigDisp(80,2,0xffff);
FigDisp(80,2,0x1000);
//test dot
//DrawDot(5,0);
//test Column Line
//DrawColLine(6,125,78);
//test row Line
//DrawRowLine(0,0,239);
//test text
//DrawText(0,0,0x0001); //16*16
//test text:电压采样实时显示曲线
TestDrawText(0,6,0x0001);
TestDrawText(0,8,0x0002);
TestDrawText(0,10,0x0011);
TestDrawText(0,12,0x0012);
TestDrawText(0,14,0x0013);
TestDrawText(0,16,0x0003);
TestDrawText(0,18,0x0014);
TestDrawText(0,20,0x0015);
TestDrawText(0,22,0x0016);
TestDrawText(0,24,0x0017);
//test text: 电压
TestDrawText(8,1,0x0001);
TestDrawText(23,1,0x0002);
//test text: 时间
TestDrawText(74,26,0x0003);
TestDrawText(74,28,0x0004);
//test coordinate
//draw col line
DrawColLine(16,20,123);
//draw row line
DrawRowLine(71,20,224);
//draw top_left arrowhead,top(16,20), draw 3 dots
DrawDot(17,19);
DrawDot(18,18);
DrawDot(19,17);
//draw top_right arrowhead
DrawDot(17,21);
DrawDot(18,22);
DrawDot(19,23);
//draw right_top arrowhead, right(71,224), draw 3 dots
DrawDot(70,223);
DrawDot(69,222);
DrawDot(68,221);
//draw rignt_bottom arrowhead
DrawDot(72,223);
DrawDot(73,222);
DrawDot(74,221);
//draw top column labels, 5 dots
DrawDot(61,19);
DrawDot(51,19);
DrawDot(41,19);
DrawDot(31,19);
DrawDot(21,19);
//draw bottom column labels, 5 dots
DrawDot(81,19);
DrawDot(91,19);
DrawDot(101,19);
DrawDot(111,19);
DrawDot(121,19);
//draw right labels, 2 dot
DrawDot(70,120);
DrawDot(72,120);
//DrawCurve
DrawCurve(sample);
//display black
ReadySTA01();
LcdData = 0x00;
ReadySTA01();
LcdData = 0x01;
ReadySTA01();
LcdCom = 0x24;
ReadySTA01();
LcdCom = 0xb0;
valR6 = 128;
while(valR6) {
valR5 = 0x1E;
while(valR5) {
ReadySTA3();
LcdData = 0xFF;
valR5--;
}
valR6--;
}
ReadySTA3();
LcdCom = 0xb2;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -