附件為:LCD12864顯示漢字和數字的程序與電路
/*
自定義延時子函數
*/
void delayms(uchar z)
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
/*
判斷LCD忙信號狀態
*/
void buys()
{
int dat;
RW=1;
RS=0;
do
{
P0=0x00;
E=1;
dat=P0;
E=0;
dat=0x80 & dat;
} while(!(dat==0x00));
}
/*
LCD寫指令函數
*/
void w_com(uchar com)
{
//buys();
RW=0;
RS=0;
E=1;
P0=com;
E=0;
}
/*
LCD寫數據函數
*/
void w_date(uchar date)
{
//buys();
RW=0;
RS=1;
E=1;
P0=date;
E=0;
}
/*
LCD選屏函數
*/
void select_screen(uchar screen)
{
switch(screen)
{
Case 0: //選擇全屏
CS1=0;
CS2=0;
break;
Case 1: //選擇左屏
CS1=0;
CS2=1;
break;
Case 2: //選擇右屏
CS1=1;
CS2=0;
break;
/* Case 3: //選擇右屏
CS1=1;
CS2=1;
break;
*/
}
}
/*
LCDx向上滾屏顯示
*/
void lcd_rol()
{
int x;
for(x=0;x<64;x++)
{
select_screen(0);
w_com(0xc0+x);
delayms(500);
}
}
/*
LCD清屏函數:清屏從第一頁的第一列開始,總共8頁,64列
*/
void clear_screen(screen)
{
int x,y;
select_screen(screen); //screen:0-選擇全屏,1-選擇左半屏,2-選擇右半屏
for(x=0xb8;x<0xc0;x++) //從0xb8-0xbf,共8頁
{
w_com(x);
w_com(0x40); //列的初始地址是0x40
for(y=0;y<64;y++)
{
w_date(0x00);
}
}
}
/*
LCD顯示漢字字庫函數
*/
void lcd_display_hanzi(uchar screen,uchar page,uchar col,uint mun)
{ //screen:選擇屏幕參數,page:選擇頁參數0-3,col:選擇列參數0-3,mun:顯示第幾個漢字的參數
int a;
mun=mun*32;
select_screen(screen);
w_com(0xb8+(page*2));
w_com(0x40+(col*16));
for ( a=0;a<16;a++)
{
w_date(hanzi[mun++]);
}
w_com(0xb8+(page*2)+1);
w_com(0x40+(col*16));
for ( a=0;a<16;a++)
{
w_date(hanzi[mun++]);
}
}
/*
LCD顯示字符字庫函數
*/
void lcd_display_zifuk(uchar screen,uchar page,uchar col,uchar mun)
{ //screen:選擇屏幕參數,page:選擇頁參數0-3,col:選擇列參數0-7,mun:顯示第幾個漢字的參數
int a;
mun=mun*16;
select_screen(screen);
w_com(0xb8+(page*2));
w_com(0x40+(col*8));
for ( a=0;a<8;a++)
{
w_date(zifu[mun++]);
}
w_com(0xb8+(page*2)+1);
w_com(0x40+(col*8));
for ( a=0;a<8;a++)
{
w_date(zifu[mun++]);
}
}
/*
LCD顯示數字字庫函數
*/
void lcd_display_shuzi(uchar screen,uchar page,uchar col,uchar mun)
{ //screen:選擇屏幕參數,page:選擇頁參數0-3,col:選擇列參數0-7,mun:顯示第幾個漢字的參數
int a;
mun=mun*16;
select_screen(screen);
w_com(0xb8+(page*2));
w_com(0x40+(col*8));
for ( a=0;a<8;a++)
{
w_date(shuzi[mun++]);
}
w_com(0xb8+(page*2)+1);
w_com(0x40+(col*8));
for ( a=0;a<8;a++)
{
w_date(shuzi[mun++]);
}
}
/*
LCD初始化函數
*/
void lcd_init()
{
w_com(0x3f); //LCD開顯示
w_com(0xc0); //LCD行初始地址,共64行
w_com(0xb8); //LCD頁初始地址,共8頁
w_com(0x40); //LCD列初始地址,共64列
}
/*
LCD顯示主函數
*/
void main()
{
//第一行
int x;
lcd_init(); //LCD初始化
clear_screen(0); //LCD清屏幕
lcd_display_shuzi(1,0,4,5); //LCD顯示數字
lcd_display_shuzi(1,0,5,1); //LCD顯示數字
lcd_display_hanzi(1,0,3,0); //LCD顯示漢字
lcd_display_hanzi(2,0,0,1); //LCD顯示漢字 //LCD字符漢字
lcd_display_hanzi(2,0,1,2); //LCD顯示漢字
//第二行
lcd_display_zifuk(1,1,2,0); //LCD顯示字符
lcd_display_zifuk(1,1,3,0); //LCD顯示字符
lcd_display_zifuk(1,1,4,0); //LCD顯示字符
lcd_display_zifuk(1,1,5,4); //LCD顯示字符
lcd_display_shuzi(1,1,6,8); //LCD顯示字符
lcd_display_shuzi(1,1,7,9); //LCD顯示字符
lcd_display_shuzi(2,1,0,5); //LCD顯示字符
lcd_display_shuzi(2,1,1,1); //LCD顯示字符
lcd_display_zifuk(2,1,2,4);
lcd_display_zifuk(2,1,3,1);
lcd_display_zifuk(2,1,4,2);
lcd_display_zifuk(2,1,5,3);
//第三行
for(x=0;x<4;x++)
{
lcd_display_hanzi(1,2,x,3+x); //LCD顯示漢字
}
for(x=0;x<4;x++)
{
lcd_display_hanzi(2,2,x,7+x); //LCD顯示漢字
}
//第四行
for(x=0;x<4;x++)
{
lcd_display_zifuk(1,3,x,5+x); //LCD顯示漢字
}
lcd_display_shuzi(1,3,4,7);
lcd_display_shuzi(1,3,5,5);
lcd_display_shuzi(1,3,6,5);
lcd_display_zifuk(1,3,7,9);
lcd_display_shuzi(2,3,0,8);
lcd_display_shuzi(2,3,1,9);
lcd_display_shuzi(2,3,2,9);
lcd_display_shuzi(2,3,3,5);
lcd_display_shuzi(2,3,4,6);
lcd_display_shuzi(2,3,5,8);
lcd_display_shuzi(2,3,6,9);
lcd_display_shuzi(2,3,7,2);
while(1);
/* while(1)
{ // LCD向上滾屏顯示
lcd_rol();
}
*/
}
標簽:
12864
LCD
漢字
數字
上傳時間:
2013-11-08
上傳用戶:aeiouetla
All inputs of the C16x family have Schmitt-Trigger input characteristics. These Schmitt-Triggers are intended to always provide proper internal low and high levels, even if anundefined voltage level (between TTL-VIL and TTL-VIH) is externally applied to the pin.The hysteresis of these inputs, however, is very small, and can not be properly used in anapplication to suppress signal noise, and to shape slow rising/falling input transitions.Thus, it must be taken care that rising/falling input signals pass the undefined area of theTTL-specification between VIL and VIH with a sufficient rise/fall time, as generally usualand specified for TTL components (e.g. 74LS series: gates 1V/us, clock inputs 20V/us).The effect of the implemented Schmitt-Trigger is that even if the input signal remains inthe undefined area, well defined low/high levels are generated internally. Note that allinput signals are evaluated at specific sample points (depending on the input and theperipheral function connected to it), at that signal transitions are detected if twoconsecutive samples show different levels. Thus, only the current level of an input signalat these sample points is relevant, that means, the necessary rise/fall times of the inputsignal is only dependant on the sample rate, that is the distance in time between twoconsecutive evaluation time points. If an input signal, for instance, is sampled throughsoftware every 10us, it is irrelevant, which input level would be seen between thesamples. Thus, it would be allowable for the signal to take 10us to pass through theundefined area. Due to the sample rate of 10us, it is assured that only one sample canoccur while the signal is within the undefined area, and no incorrect transition will bedetected. For inputs which are connected to a peripheral function, e.g. capture inputs, thesample rate is determined by the clock cycle of the peripheral unit. In the Case of theCAPCOM unit this means a sample rate of 400ns @ 20MHz CPU clock. This requiresinput signals to pass through the undefined area within these 400ns in order to avoidmultiple capture events.For input signals, which do not provide the required rise/fall times, external circuitry mustbe used to shape the signal transitions.In the attached diagram, the effect of the sample rate is shown. The numbers 1 to 5 in thediagram represent possible sample points. Waveform a) shows the result if the inputsignal transition time through the undefined TTL-level area is less than the time distancebetween the sample points (sampling at 1, 2, 3, and 4). Waveform b) can be the result ifthe sampling is performed more than once within the undefined area (sampling at 1, 2, 5,3, and 4).Sample points:1. Evaluation of the signal clearly results in a low level2. Either a low or a high level can be sampled here. If low is sampled, no transition willbe detected. If the sample results in a high level, a transition is detected, and anappropriate action (e.g. capture) might take place.3. Evaluation here clearly results in a high level. If the previous sample 2) had alreadydetected a high, there is no change. If the previous sample 2) showed a low, atransition from low to high is detected now.
標簽:
Signal
Input
Fall
Rise
上傳時間:
2013-10-23
上傳用戶:copu