?? nokia5110.c
字號:
/**************************************************************************************
* 子程序:底層程序 *
* 功能:顯示器處理,系統(tǒng)初始化; *
* *
* *
***************************************************************************************/
# include <intrins.h>
# include "stc12c5a60s2.h"
# include "macroandconst.h"
# include "zimo.h"
# include "nokia5110.h"
# include "ds1302.h"
# include "ADC.h"
# include "delay.h"
void system_inint()
{
uchar num;
EX0 = 1;//*外部中斷0中斷允許位;*//
IT0 = 0;//*外部中斷0觸發(fā)方式控制位,置0為低電平觸發(fā)方式,置1為跳變觸發(fā)方式;*//
TMOD = 0x11; //設(shè)置定時器模式
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
TF0 = 0; //清除TF0標志
TR0 = 1;
EA = 1;//*總中斷控制;*//
LCD_RST=0;
Delay100ms();
LCD_RST=1;
LCD_init(); //初始化LCD模塊
LCD_clear(); //清屏幕
LCD_POWER=1;
Delay100ms();
LCD_BLA=1;
BEEP=0;
//smartclock//
for(num=0;num<10;num++)
{
LCD_write_shu(num,2,num+77);
}
BEEP=1;
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
LCD_clear(); //清屏幕
/*您好,歡迎您使用!*/
LCD_write_hanzi(0,0,20);
LCD_write_hanzi(1,0,21);
LCD_write_shu(4,0,88);
LCD_write_hanzi(0,2,22);
LCD_write_hanzi(1,2,23);
LCD_write_hanzi(2,2,20);
LCD_write_hanzi(3,2,24);
LCD_write_hanzi(4,2,25);
LCD_write_6x8shu(13,3,100);
LCD_write_6x8shu(13,2,99);
/*leading...*/
LCD_write_shu(2,4,'L'-29);
LCD_write_shu(3,4,'e'-87);
LCD_write_shu(4,4,'a'-87);
LCD_write_shu(5,4,'d'-87);
LCD_write_shu(6,4,'i'-87);
LCD_write_shu(7,4,'n'-87);
LCD_write_shu(8,4,'g'-87);
LCD_write_shu(9,4,89);
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
LCD_draw_bmp_pixel(0,0,tupian, 84,48);
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
Delay100ms();
LCD_clear(); //清屏幕
InitADC();
}
/*--------------------------------------------
LCD_write_byte: 使用SPI接口寫數(shù)據(jù)到LCD
輸入?yún)?shù):DAT:寫入的數(shù)據(jù);
command :寫數(shù)據(jù)/命令選擇;
----------------------------------------------*/
void LCD_write_byte(uchar DAT, uchar command)
{
uchar i;
LCD_CE=0;
LCD_DC=command; //command=1為寫數(shù)據(jù),command=0為寫指令
for(i=0;i<8;i++)
{
if(DAT&0x80)
LCD_SDA=1;
else
LCD_SDA=0;
DAT=DAT<<1;
LCD_SCLK=0; //LCD_SCLK上升沿接收一位數(shù)據(jù)
LCD_SCLK=1;
}
LCD_DC=1;
LCD_CE=1;
LCD_SDA=1;
}
/*---------------------------------------
LCD_init: 5110LCD初始化
----------------------------------------- */
void LCD_init(void)
{
LCD_RST=0; //復(fù)位
delayms(1);
LCD_RST=1;
LCD_write_byte(0x21,0);//初始化Lcd,功能設(shè)定使用擴充指令
LCD_write_byte(0xc5,0);//設(shè)定液晶偏置電壓//背景陰影調(diào)整;
LCD_write_byte(0x20,0);//使用基本指令
LCD_write_byte(0x0C,0);//設(shè)定顯示模式,正常顯示
LCD_write_byte(0x06,0); // 溫度校正
}
/*-------------------------------------------
LCD_set_XY: 設(shè)置LCD坐標函數(shù)
輸入?yún)?shù):X:0-83 Y:0-5
---------------------------------------------*/
void LCD_set_XY(uchar X, uchar Y)
{
LCD_write_byte(0x40 | Y, 0);// column 列
LCD_write_byte(0x80 | X, 0);// row 行
}
/*------------------------------------------
LCD_clear: LCD清屏函數(shù)
--------------------------------------------*/
void LCD_clear(void)
{
uchar t;
uchar k;
LCD_set_XY(0,0);
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
LCD_write_byte(0x00,1);
}
}
}
/*---------------------------------------------
LCD_write_shu: 顯示6(寬)*8(高)點陣列數(shù)字字母符號等半角類
輸入?yún)?shù):c:顯示的字符;
-----------------------------------------------*/
void LCD_write_6x8shu(uchar row, uchar page,uchar c) //row:列 page:行 dd:字符
{
uchar i;
LCD_set_XY(row*6, page);// 列,頁 row表示第row個8行,page表示第page個8列,坐標位(row,page)
for(i=0; i<3;i++)
{
LCD_write_byte(shuzi6x8[c*6+i],1); //數(shù)字的點陣為8*6,寫上shuz90的上半部分
}
LCD_set_XY(row*6+3, page);// 列,行
for(i=3; i<6;i++)
{
LCD_write_byte(shuzi6x8[c*6+i],1); //寫數(shù)字的下半部分
}
}
/*---------------------------------------------
LCD_write_shu: 顯示8(寬)*16(高)點陣列數(shù)字字母符號等半角類
輸入?yún)?shù):c:顯示的字符;
-----------------------------------------------*/
void LCD_write_shu(uchar row, uchar page,uchar c) //row:列 page:頁 dd:字符
{
uchar i;
LCD_set_XY(row*8, page);// 列,頁 row表示第row個8行,page表示第page個8列,坐標位(row,page)
for(i=0; i<8;i++)
{
LCD_write_byte(shuzi[c*16+i],1); //數(shù)字的點陣為16*8,寫上shuz9o的上半部分
}
LCD_set_XY(row*8, page+1);// 列,頁
for(i=8; i<16;i++)
{
LCD_write_byte(shuzi[c*16+i],1); //寫數(shù)字的下半部分
}
}
/*---------------------------------------------
LCD_write_hanzi: 顯示16(寬)*16(高)點陣列漢字等半角類
輸入?yún)?shù):c:顯示的字符;
-----------------------------------------------*/
void LCD_write_hanzi(uchar row, uchar page,uchar c) //row:列 page:頁 dd:字符
{
uchar i;
LCD_set_XY(row*16, page);// 列,頁
for(i=0; i<16;i++)
{
LCD_write_byte(hanzi[c*32+i],1); //寫漢子的上半部分
}
LCD_set_XY(row*16, page+1);// 列,頁
for(i=16; i<32;i++)
{
LCD_write_byte(hanzi[c*32+i],1); //寫漢子的下半部分
}
}
/***********************************************************
函數(shù)名稱:LCD_draw_bmp_pixel
函數(shù)功能:位圖繪制函數(shù)
入口參數(shù):X、Y :位圖繪制的起始X、Y坐標;
*map :位圖點陣數(shù)據(jù);
Pix_x :位圖像素(長)
Pix_y :位圖像素(寬)
出口參數(shù):無
備 注:
***********************************************************/
void LCD_draw_bmp_pixel(uchar X,uchar Y,uchar *tupian, uchar Pix_x,uchar Pix_y)
{
uint i,n;
uchar row;
//計算位圖所占行數(shù)
if (Pix_y%8==0) //如果為位圖所占行數(shù)為整數(shù)
row=Pix_y/8;
else
row=Pix_y/8+1; //如果為位圖所占行數(shù)不是整數(shù)
LCD_set_XY(X,Y);
for (n=0;n<row;n++) //換行
{
for(i=0;i<Pix_x;i++)
{
LCD_set_XY(X+i,Y+n);
LCD_write_byte(tupian[i+n*Pix_x], 1);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -