簡(jiǎn)易時(shí)鐘:
1、采用DS1302時(shí)鐘芯片,12864顯示當(dāng)前時(shí)間
2、測(cè)量環(huán)境溫度并顯示
3、按鍵設(shè)置日期和時(shí)間
#include <AMPIRE128X64.h>
uchar *ppp,*qqq;
uchar code num0[16] ={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00};/*"0",0*/
uchar code num1[16] ={0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};/*"1",1*/
uchar code num2[16] ={0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00};/*"2",2*/
uchar code num3[16] ={0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00};/*"3",3*/
uchar code num4[16] ={0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00};/*"4",4*/
uchar code num5[16] ={0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00};/*"5",5*/
uchar code num6[16] ={0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00};/*"6",6*/
uchar code num7[16] ={0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00};/*"7",7*/
uchar code num8[16] ={0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00};/*"8",8*/
uchar code num9[16] ={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00};/*"9",9*/
uchar code fuhao[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01};/*"-",0*/
uchar code kong[16] ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*" ",0*/
uchar code dian[16] ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00};/*".",0*/
/************** 判忙函數(shù) **************/
void lcd_r_busy()
{
P0 = 0x00;
RS = 0;
RW = 1;
EN = 1;
while (P0 & 0x80); // 最高位DB7==1,則busy
EN = 0;
}
/************* LCD寫命令函數(shù) *************/
void lcd_w_cmd(uchar value)
{
lcd_r_busy(); // 每次讀寫操作前都要忙判斷
RS = 0;
RW = 0;
P0 = value;
EN = 1; // 下降沿鎖存寫入的數(shù)據(jù)/命令
_nop_();
_nop_();
EN = 0;
}
/************* LCD寫數(shù)據(jù) **************/
void lcd_w_data(uchar value)
{
lcd_r_busy();
RS = 1;
RW = 0;
P0 = value;
EN = 1; // 下降沿鎖存寫入的數(shù)據(jù)/命令
_nop_();
_nop_();
EN = 0;
}
/***************頁設(shè)置:顯示在哪一頁******************/
/*************共8頁,一頁是8行像素點(diǎn)*****************/
void lcd_set_page(uchar page)
{
page = 0xb8 | page; // 頁的首地址為0xb8:page或上0xb8=選擇page頁
lcd_w_cmd(page);
}
/************行設(shè)置:起始在哪一行********************/
/**********每頁共8行,一般從0行開始******************/
void lcd_set_line(uchar sline)
{
sline = 0xc0 | sline; // 起始行地址為0xc0:sline或上0xc0=選擇行
lcd_w_cmd(sline);
}
/*************起始列設(shè)置+像素點(diǎn)選擇********************/
/***********每半片共64列,列值不得大于63***************/
void lcd_set_column(uchar column)
{
column = 0x3f & column; // 與上列的最大值63:0x3f 可得所選列值<63
column = 0x40 | column; // 得列的首地址
lcd_w_cmd(column);
}
/*************設(shè)置顯示的開關(guān)********************/
/**********0為關(guān)閉顯示;1為 開啟顯示************/
void lcd_on_off(uchar set)
{
set = 0x3e | set; // =0011 111x----0x3e為關(guān)閉顯示;0x3f為開啟顯示
lcd_w_cmd(set);
}
/*************選擇左右半屏顯示********************/
/********0-全屏顯示;1-左;2-右********************/
/************cs片選端低電平有效********************/
void lcd_cs(uchar sel)
{
switch (sel)
{
case 0:CS1 = 0; CS2 = 0; break; // 全屏顯示
case 1:CS1 = 0; CS2 = 1; break; // 左顯示
case 2:CS1 = 1; CS2 = 0; break; // 右顯示
default:break;
}
}
/*************清屏:選擇半屏********************/
/********0-清全屏;1-清左;2-清右***************/
void lcd_clear(uchar sel)
{
uchar i, j;
lcd_cs(sel);
for (i = 0; i < 8; i++)
{
lcd_set_page(i);
lcd_set_column(0);
for (j = 0; j < 64; j++)
{
lcd_w_data(0x00); // 每列全部寫0,列地址指針自動(dòng)+1
}
}
}
/****************LCD的初始化********************/
void lcd_init()
{
lcd_r_busy();
lcd_cs(0);
lcd_on_off(0); // 關(guān)顯示
lcd_cs(0);
lcd_on_off(1); // 開顯示
lcd_cs(0);
lcd_clear(0); // 清全屏
lcd_set_line(0); // 起始行設(shè)為0
}
/****************16*16像素的漢字顯示程序********************/
//CS左右半屏1,2
//page 頁 lie0-7 hang0-3
void display(uchar hang, uchar lie, uchar* p)
{
uchar i;
lcd_cs((lie>3)+1);
lcd_set_page(hang*2); // 要在本頁寫上半個(gè)漢字8*16
lcd_set_column(lie*16); // 選擇起始列
for (i = 0; i < 16; i++)
{
lcd_w_data(p[i]); // 按列輸入上半個(gè)漢字的編碼8*16
}
lcd_set_page(hang*2 + 1); // 要在下一頁寫下半個(gè)漢字8*16
lcd_set_column(lie*16); // 選擇起始列
for (i = 0; i < 16; i++)
{
lcd_w_data(p[i + 16]); // 按列輸入下半個(gè)漢字的編碼8*16
}
}
/****************16*16像素的漢字顯示程序********************/
//CS左右半屏1,2
//page 頁 lie0-7 hang0-3
void display_fan(uchar hang, uchar lie, uchar* p)
{
uchar i;
lcd_cs((lie>3)+1);
lcd_set_page(hang*2); // 要在本頁寫上半個(gè)漢字8*16
lcd_set_column(lie*16); // 選擇起始列
for (i = 0; i < 16; i++)
{
lcd_w_data(~p[i]); // 按列輸入上半個(gè)漢字的編碼8*16
}
lcd_set_page(hang*2 + 1); // 要在下一頁寫下半個(gè)漢字8*16
lcd_set_column(lie*16); // 選擇起始列
for (i = 0; i < 16; i++)
{
lcd_w_data(~p[i + 16]); // 按列輸入下半個(gè)漢字的編碼8*16
}
}
/****************2數(shù)字顯示程序********************/
//CS左右半屏1,2
//page 頁
void display_num(uchar hang, uchar lie, uchar* p,uchar* q)
{
uchar i;
lcd_cs((lie>3)+1);
lcd_set_page(hang*2); // 要在本頁寫上半個(gè)漢字8*16
lcd_set_column(lie*16); // 選擇起始列
for (i = 0; i < 8; i++)
{
lcd_w_data(p[i]); // 按列輸入上半個(gè)漢字的編碼8*16
}
for (i = 0; i < 8; i++)
{
lcd_w_data(q[i]); // 按列輸入上半個(gè)漢字的編碼8*16
}
lcd_set_page(hang*2 + 1); // 要在下一頁寫下半個(gè)漢字8*16
lcd_set_column(lie*16); // 選擇起始列
for (i = 8; i < 16; i++)
{
lcd_w_data(p[i]); // 按列輸入下半個(gè)漢字的編碼8*16
}
for (i = 8; i < 16; i++)
{
lcd_w_data(q[i]); // 按列輸入下半個(gè)漢字的編碼8*16
}
}
/****************2數(shù)字顯示程序********************/
//CS左右半屏1,2
//page 頁
void display_num_fan(uchar hang, uchar lie, uchar* p,uchar* q)
{
uchar i;
lcd_cs((lie>3)+1);
lcd_set_page(hang*2); // 要在本頁寫上半個(gè)漢字8*16
lcd_set_column(lie*16); // 選擇起始列
for (i = 0; i < 8; i++)
{
lcd_w_data(~p[i]); // 按列輸入上半個(gè)漢字的編碼8*16
}
for (i = 0; i < 8; i++)
{
lcd_w_data(~q[i]); // 按列輸入上半個(gè)漢字的編碼8*16
}
lcd_set_page(hang*2 + 1); // 要在下一頁寫下半個(gè)漢字8*16
lcd_set_column(lie*16); // 選擇起始列
for (i = 8; i < 16; i++)
{
lcd_w_data(~p[i]); // 按列輸入下半個(gè)漢字的編碼8*16
}
for (i = 8; i < 16; i++)
{
lcd_w_data(~q[i]); // 按列輸入下半個(gè)漢字的編碼8*16
}
}
void find(uchar i)//查找指針
{
switch(i)
{
case 0:ppp=num0;break;
case 1:ppp=num1;break;
case 2:ppp=num2;break;
case 3:ppp=num3;break;
case 4:ppp=num4;break;
case 5:ppp=num5;break;
case 6:ppp=num6;break;
case 7:ppp=num7;break;
case 8:ppp=num8;break;
case 9:ppp=num9;
}
}
資料借鑒于此?紛傳
閱讀全文