?? main.c
字號:
#include "reg51.h"
/*****************************************************************************
* 文件說明
******************************************************************************
創 建 人:楊宏偉
修 改 人:楊宏偉
創建日期:2003-10-19
最后更新:2004-01-01
描 述:FOR 128DI0,EM65565,8080,并行
*****************************************************************************/
#define DELAY_TIME 1000 // 定義每幅顯示畫面切換的時間常數,可根據需要更改
/*****************************************************************************
* 接口定義
******************************************************************************/
sbit CS1 = P3^5; // SELECT CHIP
sbit RES = P3^4;
sbit DC1 = P3^3;
sbit WR1 = P3^1; // 8080:/WR; 6800:R/W
sbit RD1 = P3^0; // 8080:/RD; 6800:E
sbit MI = P3^7; // SELECT 8080 OR 6800
/******************************************************************************
* 顯示數據
*******************************************************************************/
//8*8 圖案
unsigned char code test_graphic0[]={0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00}; //清屏
unsigned char code test_graphic1[]={0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF}; //全顯
unsigned char code test_graphic2[]={0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa}; //隔行
unsigned char code test_graphic3[]={0XFF,0X00,0XFF,0X00,0XFF,0X00,0XFF,0X00}; //隔列
unsigned char code test_graphic4[]={0XFF,0XFE,0XFC,0XF8,0XF0,0XE0,0XC0,0X80}; //斜角圖案
unsigned char code test_graphic5[]={0X00,0X00,0X00,0X5E,0X21,0X51,0X41,0X3E}; //"Q"
unsigned char code test_graphic6[]={0X00,0X00,0X00,0X46,0X49,0X51,0X61,0X42}; //"2"
unsigned char code test_graphic7[]={0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55}; //DOT
unsigned char code test_graphic8[]={0x11,0x22,0x44,0x88,0x11,0x22,0x44,0x88}; //"/"
unsigned char code test_graphic9[]={0x00,0x18,0x18,0x7E,0x7E,0x18,0x18,0x00}; //"+"
unsigned char code test_graphic10[]={0X0F,0X0F,0X0F,0X0F,0XF0,0XF0,0XF0,0XF0};//方格
unsigned char code test_graphic11[]={0x00,0x42,0x24,0x18,0x18,0x24,0x42,0x00};//"*"
//128*64圖片
unsigned char code test_pic1[]=
{
0x06,0x09,0x09,0x17,0x6F,0xFF,0xFF,0x79,0x1E,0x0F,0x0F,0x06,0x00,0x00,0x00,0x00,
0x00,0x01,0x01,0x0E,0x10,0xE1,0xE1,0x00,0x8F,0x70,0x70,0x17,0x0F,0x06,0x06,0x06,
0x06,0x86,0x86,0x66,0x91,0x90,0x90,0x09,0x09,0x10,0x10,0x68,0x89,0x89,0x89,0x10,
0x68,0x09,0x09,0x09,0x10,0x10,0x10,0xE1,0x11,0x10,0x10,0xE0,0xF1,0xF9,0xF9,0xF8,
0xE8,0x11,0x11,0xE1,0x10,0x10,0x10,0xE1,0x11,0x10,0x10,0x08,0x09,0x69,0x69,0x10,
0x88,0x89,0x89,0x69,0x10,0x08,0x08,0x09,0x91,0x90,0x90,0x61,0x86,0x06,0x06,0x06,
0x06,0x06,0x06,0x0F,0x17,0x70,0x70,0x8F,0x00,0xE1,0xE1,0x10,0x0E,0x01,0x01,0x00,
0x00,0x00,0x00,0x00,0x01,0x07,0x07,0x0F,0x1E,0xFF,0xFF,0x17,0x09,0x06,0x06,0x01,
0x96,0xEF,0xEF,0x9E,0x79,0xFF,0xFF,0xEF,0xF7,0x79,0x79,0x10,0x00,0x00,0x00,0x00,
0x00,0xF8,0xF8,0x07,0x70,0x9E,0x9E,0x77,0x1E,0x96,0x96,0x91,0x10,0x60,0x60,0x80,
0x80,0x80,0x80,0x80,0x08,0x0E,0x0E,0x0E,0x00,0x80,0x80,0x89,0x1E,0x19,0x19,0x99,
0x89,0x00,0x00,0x00,0x80,0x80,0x80,0x01,0x0F,0x87,0x87,0x87,0x06,0x06,0x06,0x80,
0x8F,0x1E,0x1E,0x06,0x8E,0x8E,0x8E,0x06,0x00,0x80,0x80,0x80,0x07,0x0F,0x0F,0x86,
0x8E,0x0F,0x0F,0x00,0x87,0x8F,0x8F,0x0E,0x0E,0x0F,0x0F,0x0F,0x80,0x80,0x80,0x80,
0x80,0x60,0x60,0x10,0x91,0x96,0x96,0x1E,0x77,0x9E,0x9E,0x70,0x07,0xF8,0xF8,0x00,
0x00,0x00,0x00,0x00,0x08,0x9E,0x9E,0x79,0xF7,0xFF,0xFF,0x9E,0xEF,0xF7,0xF7,0x69,
0x86,0x79,0x79,0xF7,0xEF,0xFF,0xFF,0x79,0x9E,0xEF,0xEF,0x86,0x00,0x00,0x00,0x00,
0x00,0x07,0x07,0x18,0xE7,0x0E,0x0E,0x96,0xF7,0x96,0x96,0x96,0x78,0x00,0x00,0x00,
0x00,0x10,0x10,0x1F,0x7E,0xFF,0xFF,0xEE,0x01,0xF9,0xF9,0xFF,0xE9,0x9F,0x9F,0xF7,
0xE6,0x07,0x07,0x07,0x00,0x00,0x00,0xFF,0xFF,0x77,0x77,0xE7,0x7E,0x01,0x01,0x81,
0xF9,0xE9,0xE9,0xE9,0xF9,0xE1,0xE1,0x01,0x01,0x00,0x00,0x00,0xFF,0xE0,0xE0,0xEE,
0xF8,0xF0,0xF0,0x00,0xF8,0xF8,0xF8,0xE8,0x88,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x78,0x96,0x96,0x96,0xF7,0x96,0x0E,0x0E,0xE7,0x18,0x07,0x07,0x00,
0x00,0x00,0x00,0x00,0x60,0xF0,0xF0,0xE0,0x81,0xFF,0xFF,0xE7,0x70,0x98,0x98,0x60,
0x96,0xEF,0xEF,0x9E,0x79,0xFF,0xFF,0xEF,0xF7,0x79,0x79,0x10,0x00,0x00,0x00,0x00,
0x00,0xE0,0xE0,0x1E,0x01,0xF8,0xF8,0x86,0x01,0x01,0x01,0x01,0x0E,0x10,0x10,0x0F,
0x00,0xE0,0xE0,0x80,0x00,0xF8,0xF8,0x00,0xF0,0x98,0x98,0x68,0xF8,0xF8,0xF8,0x6E,
0x78,0xF8,0xF8,0xE0,0x00,0x00,0x00,0x98,0xF0,0x60,0x60,0xE0,0xE0,0xF8,0xF8,0x10,
0xF0,0x10,0x10,0xF0,0x98,0x18,0x18,0xF8,0x80,0x00,0x00,0x00,0xFE,0xF8,0xF8,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x0E,0xFE,0xFE,0xF8,0x00,0x00,0x00,0x00,
0x0F,0x10,0x10,0x0E,0x01,0x01,0x01,0x01,0x86,0xF8,0xF8,0x01,0x1E,0xE0,0xE0,0x00,
0x00,0x00,0x00,0x00,0x10,0x79,0x79,0xF7,0xEF,0xFF,0xFF,0x79,0x9E,0x6F,0x6F,0x16,
0x83,0x74,0x74,0xEB,0x97,0xFF,0xFF,0x1C,0x8F,0xE7,0xE7,0x83,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x88,0x64,0x60,0x60,0x60,0x6C,0x80,0x80,0x00,
0x04,0x68,0x68,0x60,0x80,0x80,0x80,0x60,0x60,0x80,0x80,0x80,0x60,0x60,0x60,0x80,
0x80,0x60,0x60,0x60,0x80,0x80,0x80,0x6F,0x60,0x8F,0x8F,0x8C,0x6C,0x6C,0x6C,0x8C,
0x8C,0x6C,0x6C,0x6C,0x8F,0x80,0x80,0x6F,0x60,0x80,0x80,0x80,0x60,0x60,0x60,0x80,
0x80,0x60,0x60,0x60,0x80,0x80,0x80,0x60,0x60,0x80,0x80,0x80,0x60,0x60,0x60,0x00,
0x08,0x84,0x84,0x60,0x60,0x6C,0x6C,0x60,0x80,0x84,0x84,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x84,0xEF,0xEF,0x9C,0x78,0xFF,0xFF,0xEC,0xF7,0x7B,0x7B,0x94,
0x4B,0xF7,0xF7,0xCF,0xBC,0xFF,0xFF,0xF7,0x7B,0xBC,0xBC,0x08,0x00,0x00,0x00,0x00,
0x00,0x7C,0x7C,0x83,0x80,0x80,0x80,0x40,0x70,0x88,0x88,0xB8,0xB8,0xB8,0xB8,0x70,
0x40,0x83,0x83,0x83,0x8F,0x7C,0x7C,0x03,0x03,0x07,0x07,0x07,0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,0x7B,0xBC,0xCF,0xCF,0x84,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0x40,0x40,0x33,0x74,0x74,0x74,0x7B,0xCB,0x84,0x84,0x04,
0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x83,0x73,0x73,0x87,0x07,0x04,0x04,0x0F,
0x0B,0x3F,0x3F,0x37,0x3F,0xFF,0xFF,0xBF,0x4F,0x34,0x34,0x34,0x8B,0x4B,0x4B,0x4F,
0x4B,0x8B,0x8B,0x34,0x34,0x4F,0x4F,0xBF,0xFF,0x3F,0x3F,0x37,0x3F,0x0B,0x0B,0x0F,
0x04,0x07,0x07,0x07,0x87,0x73,0x73,0x83,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0x04,0x84,0x84,0x4B,0x3B,0x74,0x74,0x74,0x73,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x44,0xFF,0xFF,0xFC,0xFB,0xFF,0xFF,0xCF,0x77,0xBB,0xBB,0x44,
0xB0,0xCC,0xCC,0xB8,0x70,0xFC,0xFC,0xC0,0xF0,0x78,0x78,0x30,0x00,0x30,0x30,0x08,
0x04,0x00,0x00,0x00,0x3C,0x34,0x34,0x88,0x44,0x38,0x38,0x78,0x74,0x74,0x74,0xF3,
0xF3,0x83,0x83,0x83,0x73,0x3F,0x3F,0xF0,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0xF0,0x8F,0x7F,0xFF,0xFF,0xFF,0xF8,0xF7,0xF7,0xF7,
0xF7,0xF8,0xF8,0xFF,0xFF,0x7F,0x7F,0x8F,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0xF0,0x3F,0x3F,0x73,0x83,0x83,0x83,0xF3,
0x73,0x34,0x34,0x74,0x78,0x74,0x74,0xC3,0x80,0x30,0x30,0x4F,0x30,0x00,0x00,0x03,
0x04,0x08,0x08,0x00,0x30,0x7B,0x7B,0xF7,0xCF,0xFF,0xFF,0x7B,0xBC,0xCF,0xCF,0xB4,
0x00,0x03,0x03,0x04,0x04,0x0B,0x0B,0x0B,0x04,0x7C,0x7C,0x83,0x80,0x80,0x80,0x40,
0x70,0x88,0x88,0xB8,0xB8,0xB8,0xB8,0x70,0x40,0x83,0x83,0x83,0x8F,0x7C,0x7C,0x03,
0x03,0x04,0x04,0x04,0x83,0x83,0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x7F,0x40,0x40,0xCF,0xFF,0xFF,0xFF,0x7F,0x80,0xFF,0xFF,0xFF,0x7F,0xCF,0xCF,0xCF,
0xCF,0x7F,0x7F,0xFF,0xFF,0x80,0x80,0x7C,0xFF,0xFF,0xFF,0xF0,0xFF,0x7F,0x7F,0x40,
0xC0,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,
0x3F,0x40,0x40,0x40,0x40,0x30,0x30,0x38,0x44,0x4C,0x4C,0x4C,0x4C,0x38,0x38,0x30,
0x40,0x40,0x40,0x47,0xBF,0xC0,0xC0,0x80,0x03,0xF3,0xF3,0x8C,0xC4,0x73,0x73,0x83,
0x07,0x87,0x87,0x47,0x37,0x77,0x77,0x77,0x77,0xC7,0xC7,0x87,0x47,0xB7,0xB7,0x77,
0x3F,0x7F,0x7F,0xBF,0x7F,0xFF,0xFF,0x7F,0xF7,0xF7,0xF7,0xC7,0x87,0xC7,0xC7,0x37,
0x0F,0xBF,0xBF,0xBF,0x3F,0x77,0x77,0xC7,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x7F,
0x87,0x3F,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x8F,0xFF,0xFF,0xFF,0x3F,0x87,0x87,0x77,
0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x0F,0x37,0x37,0x37,0x4F,0x4F,0x37,0x37,0x37,
0x0F,0xC7,0xC7,0x37,0x4F,0x3F,0x3F,0x0F,0x3F,0x4F,0x4F,0x3F,0x7F,0x3F,0x3F,0x7F,
0xFF,0xF7,0xF7,0xC7,0x07,0x07,0x07,0xC7,0x37,0x0F,0x0F,0xBF,0xBF,0x3F,0x3F,0x77,
};
/*******************************************************************************
* 函數聲明及實現
*******************************************************************************/
void delay(unsigned int n)
{
unsigned int i,j;
for (i=0;i<n;i++)
for (j=0;j<350;j++)
{;}
}
void data_out(unsigned char i)
{
//8080 interface
CS1 = 0;
WR1 = 0;
DC1 = 1;
P1 = i;
WR1 = 1;
CS1 = 1;
}
void comm_out(unsigned char i)
{
//8080 interface
CS1 = 0;
DC1 =0;
WR1 = 0;
P1 = i;
WR1 = 1;
CS1 = 1;
}
void selectSeries(unsigned char i)
{
//SELECT SERIES
switch(i)
{
case 0:
MI = 0;//SELECT 8080
RD1 = 1;
WR1 = 1;
break;
case 1:
MI = 1; //SELECT 6800
RD1 = 0;
WR1 = 0;
break;
default:
;
}
}
void reset(void)
{
//RESET CHIP
RES = 0;
delay(100);
RES = 1;
delay(100);
}
void ini_lcd(void)
{
//INI_CODE
comm_out(0xA0);// ADC select
comm_out(0xA6);// Sets the LCD display normal/reverse
comm_out(0xA2);// Sets the LCD drive voltage bias ratio 1/9
comm_out(0x2F);// Power control set
comm_out(0x24);// V0 Voltage Regulator Internal Resistor Ratio Set
comm_out(0x81);// Electronic volume mode set
comm_out(0x29);// 3F
comm_out(0xAF);// display on
}
void setPageAddress(unsigned char i)
{
comm_out(0xb0+i);
}
void setColAddress(unsigned char i)
{
if(i<=16)
{
comm_out(0x00+i);
comm_out(0x10);
}
else
{
comm_out(0x00+i%16);
comm_out(0x10+i/16);
}
}
void dispData(unsigned char s_page,e_page,s_col,e_col,unsigned char dispdata,unsigned char dly)
{
unsigned char i,j,page_num,col_num;
page_num = e_page - s_page+1;
col_num = e_col - s_col+1;
for (i=s_page;i<(s_page+page_num);i++ )
{
setPageAddress(i);
setColAddress(s_col);
for(j=0;j<col_num;j++)
{
data_out(dispdata);
delay(dly);
}
}
}
//顯示定制圖案
void dispGraphic(unsigned char s_page, e_page,s_col,e_col,unsigned char code *graphicData,unsigned char dly)
{
unsigned char i,j,k,page_num,col_num;
page_num = e_page - s_page+1;
col_num = e_col - s_col+1;
for (i=s_page;i<s_page+page_num;i++ )
{
setPageAddress(i);
setColAddress(s_col);
for(j=0;j<(col_num/8+1);j++)
{
for(k=0;k<8;k++)
{
data_out(graphicData[k]);
delay(dly);
}
}
}
}
//顯示定制圖片
void dispPic(unsigned char s_page, e_page, s_col,e_col,unsigned char code *pictrue)
{
unsigned char i,j,page_num,col_num;
page_num = e_page - s_page+1;
col_num = e_col - s_col+1;
for (i=s_page;i<(s_page+page_num);i++ )
{
setPageAddress(i);
setColAddress(s_col);
for(j=0;j<col_num;j++)
{
data_out(*pictrue);
pictrue ++;
}
}
}
/*******************************************************************************
* 主程序
*******************************************************************************/
void main(void)
{
selectSeries(0); // 選擇8080時序
reset(); // 復位LCD
CS1 = 0; // 片選有效
ini_lcd(); // 初始化LCD
while(1)
{
//利用dispGraphic函數,顯示定制圖案
dispGraphic(0,8,0,127,test_graphic1,0); //全顯
delay(DELAY_TIME);
dispGraphic(0,7,0,127,test_graphic2,0); //隔行
delay(DELAY_TIME);
dispGraphic(0,7,0,127,test_graphic3,0); //隔列
delay(DELAY_TIME);
dispGraphic(0,7,0,127,test_graphic4,0); //斜角圖案
delay(DELAY_TIME);
dispGraphic(0,7,0,127,test_graphic5,0); //圖案Q
delay(DELAY_TIME);
dispGraphic(0,7,0,127,test_graphic0,0); //清屏
delay(DELAY_TIME);
//顯示圖片
dispPic(0,7,0,127,test_pic1);
delay(DELAY_TIME);
dispData(0,8,0,127,0x00,0); //清屏
delay(DELAY_TIME);
}
}
/******************************************************************************
** 文件結束
*******************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -