?? demo.c
字號:
#include <AT89X55.H>
#include <intrins.h>
#include "demo.h"
#include "demo_funs.h"
UCHAR synchronization=SYN_INTERNAL,demo_choice=0;
void (*DemoFunction[DEMO_SUM])() ={
DemoLogo,DemoAll,DemoFontSize,DemoCount,DemoMoveText,DemoPicture,DemoPic
};
/*********************************************************************************************************
** 函數名稱: Delay_ms
** 功能描述: 延時ms毫秒 (不精確)
** 日 期: 2004年12月29日
********************************************************************************************************/
void Delay_ms (UINT ms)
{
UINT i,j,k;
for(k=0; k<ms; k++)
for(i=48; i>0; i--)
for(j=10; j>0; j--);
}
/*********************************************************************************************************
** 函數名稱: MB90092_WriteByte
** 功能描述: 向MB90092 寫一個字節數據
** 日 期: 2004年12月29日
********************************************************************************************************/
void MB90092_WriteByte (UCHAR _data)
{
UCHAR i;
ACC=_data;
CS=0x00;
for (i=8;i>0;i--){
CLK=0;
SIN = ACC_0;
CLK=1;
ACC>>=1;
}
CS=0x01;
}
/*********************************************************************************************************
** 函數名稱: MB90092_ClearXY
** 功能描述: 清掉屏幕上面坐標(x,y)處的字符,y=0x00~0x0B and x=0x00~0x17 for main screen
** 日 期: 2004年12月29日
********************************************************************************************************/
void MB90092_ClearXY (UCHAR x,UCHAR y)
{
UCHAR byte1,byte2;
if (x>0x17||y>0x0B) return; //invalid col number or row number
byte1=((y>>2)&0x3)+0x80;
byte2=((y<<5)&0x60)+x;
MB90092_WriteByte(byte1); //command 0,設置寫入地址,行和列
MB90092_WriteByte(byte2);
MB90092_WriteByte(0x88); //command1-1,定義字符顏色,背景顏色
MB90092_WriteByte(0x00);
MB90092_WriteByte(0x90+62/128); //command2-1,寫入一個空格字符,地址62為空格符點陣
MB90092_WriteByte(62%128);
}
/*********************************************************************************************************
** 函數名稱: MB90092_ClearRow
** 功能描述: 清掉屏幕上面的第y行字符,y=0x00~0x0B for main screen
** 日 期: 2004年12月29日
********************************************************************************************************/
void MB90092_ClearRow (UCHAR y)
{
UCHAR x;
if (y>0x0B) return; //invlid row number
for (x=0;x<0x18;x++)
MB90092_ClearXY (x,y);
}
/*********************************************************************************************************
** 函數名稱: MB90092_ClearScreen
** 功能描述: 清屏
** 日 期: 2004年12月29日
********************************************************************************************************/
void MB90092_ClearScreen ()
{
UCHAR i;
for (i=0;i<0x0C;i++)
MB90092_ClearRow (i);
}
/*********************************************************************************************************
** 函數名稱: MB90092_DisColor
** 功能描述: MB90092顏色初始化
** 日 期: 2004年12月29日
********************************************************************************************************/
void MB90092_DisColor (UCHAR y)
{
UCHAR temp1,temp2;
temp1=((y>>2)&0x3)+0x84;
temp2=((y<<5)&0x60)+1;
MB90092_WriteByte(temp1); //command 0,設置寫入地址,行和列
MB90092_WriteByte(temp2);
MB90092_WriteByte(0x88); //ff控制是否特顯
MB90092_WriteByte(0x00); //command1-1,設置字符顏色,背景顏色
MB90092_WriteByte(0x90); //command2-1,設置字符點陣在外rom的地址
MB90092_WriteByte(0x00);
}
/*********************************************************************************************************
** 函數名稱: MB90092_DisChar
** 功能描述: 在屏幕坐標(x,y)處顯示一個字符,該字符的點陣存儲地址為addr,為一24x32的矩形區域
** 參 數: x,y為屏幕坐標,addr為字符點陣在外rom的存儲地址,mul為字符尺寸,bc為字符背景顏色,
cc為字符顏色,ff控制是否特顯.
** 日 期: 2004年12月29日
********************************************************************************************************/
void MB90092_DisChar (UCHAR x,UCHAR y,int addr,UCHAR mul,UCHAR bc,UCHAR cc,UCHAR ff)
{
UCHAR temp1,temp2,color;
if (x>0x17||y>0x0B) return; //invalid col number or row number
temp1=((y>>2)&0x3)+0x80;
temp2=((y<<5)&0x60)+x;
MB90092_WriteByte(temp1); //command 0,設置寫入地址,行和列
MB90092_WriteByte(temp2);
MB90092_WriteByte(0xB0|mul); //command 6,mul->字符尺寸控制(datasheel82),設置一整行
MB90092_WriteByte(0x20|y);
if (synchronization==SYN_EXTERNAL){
cc=7;
bc=0;
}
color=((cc<<4)&0x70)|bc;
MB90092_WriteByte(0x88|ff); //ff控制是否特顯
MB90092_WriteByte(color); //command1-1,設置字符顏色,背景顏色
MB90092_WriteByte(0x90+addr/128); //command2-1,設置字符點陣在外rom的地址
MB90092_WriteByte(addr%128);
}
/*********************************************************************************************************
** 函數名稱: MainScreen_Init
** 功能描述: MB90092主屏初始化
** 日 期: 2004年12月29日
********************************************************************************************************/
void MainScreen_Init (UCHAR bc)
{
UCHAR i;
CS=0;
Delay_ms(10); //程序開始時,要輸入CS四次去清除上電復位,然后所作的設置才是有效的。
CS=1;
Delay_ms(10);
CS=0;
Delay_ms(10);
CS=1;
Delay_ms(10);
CS=0;
Delay_ms(10);
CS=1;
Delay_ms(10);
CS=0;
Delay_ms(10);
CS=1;
Delay_ms(10);
MB90092_WriteByte(0xA0); //command 4,首先選擇內同步
MB90092_WriteByte(0x00);
MB90092_WriteByte(0xAD); //command 5
MB90092_WriteByte(0x10); //KID=0;APC與顏色有關;GYZ=0;W3--W0為行間距;10101 KID APC GYZ0 BH2 BH1 BH0 W3 W2 W1 W0
MB90092_WriteByte(0xBC); //command 7
MB90092_WriteByte(0x2A); //垂直開始位置設定
MB90092_WriteByte(0xC0); //command 8
MB90092_WriteByte(0x18); //水平開始位置設定
MB90092_WriteByte(0xC8); //command 9,GRM位設置普通模式或者擴展圖形模式
MB90092_WriteByte(0x20);
MB90092_WriteByte(0xD1); //command 10,設置普通模式/擴展圖形模式,閃爍,字符背景,字符單色/彩色,背景單色/彩色
MB90092_WriteByte(0x38|bc);
MB90092_WriteByte(0xA2|synchronization);//command 4,內/外同步選擇
MB90092_WriteByte(0x2B);
for (i=0;i<0x0B;i++)
MB90092_DisColor (i);
MB90092_ClearScreen ();
}
/*********************************************************************************************************
** 函數名稱: ScanKey
** 功能描述: 接收按鍵
** 日 期: 2004年12月29日
********************************************************************************************************/
UCHAR ScanKey ()
{
UCHAR i;
if(EXT==0){
synchronization=SYN_EXTERNAL;
while (EXT==0);
MB90092_WriteByte(0xA2|synchronization);//command 4,內/外同步選擇
MB90092_WriteByte(0x2B);
return 1;
}
if(INT==0){
synchronization=SYN_INTERNAL;
while (INT==0);
MB90092_WriteByte(0xA2|synchronization);//command 4,內/外同步選擇
MB90092_WriteByte(0x2B);
return 1;
}
if(MODE==0){
demo_choice=(++demo_choice)%DEMO_SUM;
while (MODE==0);
for (i=0;i<0x0B;i++)
MB90092_DisColor (i);
MB90092_ClearScreen ();
switch (demo_choice){
case 1:
MB90092_WriteByte(0xAA); //command 5,設置行間距為0
MB90092_WriteByte(0x15);
MB90092_WriteByte (0xD1); //command 10,字符顯示背景(solid-fill)
MB90092_WriteByte (0x38|B_COLOR_BLACK);
break;
case 0:
case 2:
case 3:
case 4:
case 5:
case 6:
MB90092_WriteByte(0xAD); //command 5,設置行間距為0
MB90092_WriteByte(0x10);
MB90092_WriteByte (0xD1); //command 10,字符顯示背景(solid-fill)
MB90092_WriteByte (0x38|B_COLOR_WHITE);
break;
}
return 1;
}
return 0;
}
main ()
{
CLK=1; //先將CLK腳置高
MainScreen_Init (7);
MB90092_ClearScreen ();
while (1){
DemoFunction[demo_choice] ();
ScanKey ();
Delay_ms (10);
}
while (1);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -