?? cgm12864b.c
字號(hào):
//-------------------------------------------------------------------------
//函數(shù)名稱(chēng): void LCD_WriteData1(char ch)
//函數(shù)功能: 向LCD控制芯片KS0108發(fā)送數(shù)據(jù)
//入口參數(shù): char ch 數(shù)據(jù)參數(shù)
//出口參數(shù): 無(wú)
//全局變量引用: 無(wú)
//調(diào)用模塊: LCD_WaitReady1()
//----------------------------------------------------------------------
void LCD_WriteData1(char ch)
{
LCD_WaitReady1(); ////判斷LCD是否處于忙狀態(tài)
LCD_CS2=SELECTCS;
LCD_RW=0;
LCD_RS=1;
LCD_DATA=ch;
LCD_E=1;
LCD_E=0;
LCD_CS2=!SELECTCS;
}
//-------------------------------------------------------------------------
//函數(shù)名稱(chēng): void LCD_WriteData2(char ch)
//函數(shù)功能: 向LCD控制芯片KS0108發(fā)送數(shù)據(jù)
//入口參數(shù): char ch 數(shù)據(jù)參數(shù)
//出口參數(shù): 無(wú)
//全局變量引用: 無(wú)
//調(diào)用模塊: LCD_WaitReady2()
//----------------------------------------------------------------------
void LCD_WriteData2(char ch)
{
LCD_WaitReady2(); //判斷LCD是否處于忙狀態(tài)
LCD_CS1=SELECTCS;
LCD_RW=0;
LCD_RS=1;
LCD_DATA=ch;
LCD_E=1;
LCD_E=0;
LCD_CS1=!SELECTCS;
}
//-------------------------------------------------------------------------
//函數(shù)名稱(chēng): void LCD_WriteHZ(char x,char y,char *Dot)
//函數(shù)功能: 在液晶的指定位置顯示16*16點(diǎn)陣漢字
//入口參數(shù): char x:橫向坐標(biāo) char y:縱向坐標(biāo) char *Dot:漢字點(diǎn)陣的首地址
//出口參數(shù): 無(wú)
//全局變量引用: 無(wú)
//調(diào)用模塊: LCD_WriteCommand1(); LCD_WriteCommand2();
// LCD_WriteData1(); LCD_WriteData1();
//----------------------------------------------------------------------
void LCD_WriteHZ(char x,char y,char *Dot)
{
char i;
for (i=0;i<32;i++)
{
if ((x+i%16)<64) //橫向坐標(biāo)小于64時(shí)在左屏顯示漢字
{
LCD_WriteCommand1(0xB8+y+i/16);
LCD_WriteCommand1(0x40+x+i%16);
LCD_WriteData1(Dot[i]);
}
else //橫向坐標(biāo)大于64時(shí)在右屏顯示漢字
{
LCD_WriteCommand2(0xB8+y+i/16);
LCD_WriteCommand2(0x40+x-64+i%16);
LCD_WriteData2(Dot[i]);
}
}
}
//-------------------------------------------------------------------------
//函數(shù)名稱(chēng): void InitLCD(void)
//函數(shù)功能: 初始化液晶并清屏
//入口參數(shù): 無(wú)
//出口參數(shù): 無(wú)
//全局變量引用: 無(wú)
//調(diào)用模塊: Delay1ms(1);LCD_WriteCommand1(); LCD_WriteCommand2();
// LCD_WriteData1(); LCD_WriteData1();
//----------------------------------------------------------------------
void InitLCD(void)
{
char i,j;
LCD_RST=0;
Delay1ms(1);
LCD_RST=1;
LCD_WriteCommand1(0xc0);
LCD_WriteCommand2(0xc0);
LCD_WriteCommand1(0x3f); //開(kāi)顯示
LCD_WriteCommand2(0x3f);
for (j=0;j<8;j++) //清屏
{
LCD_WriteCommand1(0xB8+j); //清左半屏
LCD_WriteCommand1(0x40);
for (i=0;i<64;i++)
LCD_WriteData1(0x00);
LCD_WriteCommand2(0xB8+j); //清右半屏
LCD_WriteCommand2(0x40);
for (i=0;i<64;i++)
LCD_WriteData2(0x00);
}
}
//-------------------------------------------------------------------------
//函數(shù)名稱(chēng): void DispBmp(char *buf)
//函數(shù)功能: 顯示位圖
//入口參數(shù): char *buf 位圖數(shù)據(jù)首地址
//出口參數(shù): 無(wú)
//全局變量引用: 無(wú)
//調(diào)用模塊: LCD_WriteCommand1(); LCD_WriteCommand2();
// LCD_WriteData1(); LCD_WriteData1();
//----------------------------------------------------------------------
void DispBmp(char *buf) //顯示一幅位圖
{
int i,j;
for (j=0;j<8;j++) //顯示位圖
{
LCD_WriteCommand1(0xB8+j);
LCD_WriteCommand1(0x40);
for (i=0;i<64;i++)
LCD_WriteData1(buf[(j*2)*64+i]);
LCD_WriteCommand2(0xB8+j);
LCD_WriteCommand2(0x40);
for (i=0;i<64;i++)
LCD_WriteData2(buf[(j*2+1)*64+i]);
}
}
//-------------------------------------------------------------------------
//函數(shù)名稱(chēng): void SYSCLK_Init (void)
//函數(shù)功能: 系統(tǒng)時(shí)鐘初始化;使能外部時(shí)鐘:11.0592MHz
//入口參數(shù): 無(wú)
//出口參數(shù): 無(wú)
//全局變量引用: 無(wú)
//調(diào)用模塊: 無(wú)
//----------------------------------------------------------------------
void SYSCLK_Init (void)
{
int i; // delay counter
OSCXCN = 0x67; // start external oscillator with
// 18.432MHz crystal
for (i=0; i < 256; i++) ; // Wait for osc. to start up
while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
OSCICN = 0x88; // select external oscillator as SYSCLK
// source and enable missing clock
// detector
}
//-------------------------------------------------------------------------
//函數(shù)名稱(chēng): PORT_Init ()
//函數(shù)功能: 端口初始化;使能交叉開(kāi)關(guān)
//入口參數(shù): 無(wú)
//出口參數(shù): 無(wú)
//全局變量引用: 無(wú)
//調(diào)用模塊: 無(wú)
//----------------------------------------------------------------------
void PORT_Init (void)
{
XBR2 = 0x40; // Enable crossbar and weak pull-ups
}
//-------------------------------------------------------------------------
//函數(shù)名稱(chēng): Timer0_Init ()
//函數(shù)功能: 定時(shí)器0初始化;定時(shí)時(shí)間1ms
//入口參數(shù): 無(wú)
//出口參數(shù): 無(wú)
//全局變量引用: 無(wú)
//調(diào)用模塊: 無(wú)
//----------------------------------------------------------------------
void Timer0_Init (void)
{
CKCON|=0x8;
TMOD|=0x1; //16Bit
Count1ms=10;
TR0 = 0; // STOP Timer0
TH0 = (-SYSCLK/1000) >> 8; // set Timer0 to overflow in 1ms
TL0 = -SYSCLK/1000;
TR0 = 1; // START Timer0
IE|= 0x2;
}
//-------------------------------------------------------------------------
//函數(shù)名稱(chēng): Timer0_ISR ()
//函數(shù)功能: 定時(shí)器0中斷服務(wù)程序
//入口參數(shù): 無(wú)
//出口參數(shù): 無(wú)
//全局變量引用: Count1ms
//調(diào)用模塊: 無(wú)
//----------------------------------------------------------------------
void Timer0_ISR (void) interrupt 1 //1ms
{
TH0 = (-SYSCLK/1000) >> 8;
TL0 = -SYSCLK/1000;
if (Count1ms) Count1ms--;
}
//-------------------------------------------------------------------------
//函數(shù)名稱(chēng): Delay1ms(unsigned char T)
//函數(shù)功能: 延時(shí)1ms程序
//入口參數(shù): unsigned char T :定時(shí)時(shí)間常數(shù)
//出口參數(shù): 無(wú)
//全局變量引用: Count1ms
//調(diào)用模塊: 無(wú)
//----------------------------------------------------------------------
void Delay1ms(unsigned char T)
{
Count1ms=T;
while (Count1ms);
}
//-------------------------------------------------------------------------
//函數(shù)名稱(chēng): void Delay1s(unsigned char T)
//函數(shù)功能: 延時(shí)1s程序
//入口參數(shù): unsigned char T :定時(shí)時(shí)間常數(shù)
//出口參數(shù): 無(wú)
//全局變量引用: Count1ms
//調(diào)用模塊: Delay1ms()
//----------------------------------------------------------------------
void Delay1s(unsigned char T)
{
while (T)
{
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
Delay1ms(200);
T--;
}
}
//---------------------------------------------------------------------------
// 主程序
//----------------------------------------------------------------------------
void main (void)
{
WDTCN = 0xde;
WDTCN = 0xad; //關(guān)看門(mén)狗
SYSCLK_Init (); //初始化時(shí)鐘
Timer0_Init(); //初始化定時(shí)器
PORT_Init (); //初始化IO口
EA=1; //開(kāi)中斷
InitLCD(); //清屏
Delay1s(1); //延時(shí)1S
for (;;)
{
DispBmp(screen1); //顯示位圖"新華龍電子-單片機(jī)推廣應(yīng)用急先鋒!"
Delay1s(3);
DispBmp(screen2); //顯示位圖"換代創(chuàng)新后的51-高速SOC美國(guó)silicon labs 8051F"
Delay1s(3);
InitLCD(); //清屏
LCD_WriteHZ(2,1,Han); //顯示16*16點(diǎn)陣漢字'漢'
Delay1ms(100);
LCD_WriteHZ(60,3,Zi); //顯示16*16點(diǎn)陣漢字'字'
Delay1s(3);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -