本帖最后由 wosiyabo 于 2017-3-20 00:20 編輯
單片機:STC15W204S-DIP16@6MHz
LCD : nokia5110LCD
時鐘芯片:DS3231
論壇上做時鐘的方案一大堆,但是用來做電池帶動的卻還沒有。
我想到了一個辦法,用STC的單片機掉電模式運行時鐘,利用DS3231的1Hz來換醒讀秒。
現在能跑起來了,消耗電流在0.5mA+-1mA上下。
不知道這樣18650電池能跑多久。
但是程序上還欠調整時鐘未做,不知道怎樣做光標。
以前1602的話可以直接寫光標反色的,這個5110lcd有人會做光標嗎?求助
IMG_20170320_000519.jpg (176.61 KB, 下載次數: 81)
下載附件
2017-3-20 00:16 上傳
#include "reg51.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sfr P4 = 0xC0; //1111,1111 端口4
sfr P5 = 0xC8; //xxxx,1111 端口5
sfr P6 = 0xE8; //0000,0000 端口6
sfr P7 = 0xF8; //0000,0000 端口7
sfr P0M0 = 0x94; //0000,0000 端口0模式寄存器0
sfr P0M1 = 0x93; //0000,0000 端口0模式寄存器1
sfr P1M0 = 0x92; //0000,0000 端口1模式寄存器0
sfr P1M1 = 0x91; //0000,0000 端口1模式寄存器1
sfr P2M0 = 0x96; //0000,0000 端口2模式寄存器0
sfr P2M1 = 0x95; //0000,0000 端口2模式寄存器1
sfr P3M0 = 0xB2; //0000,0000 端口3模式寄存器0
sfr P3M1 = 0xB1; //0000,0000 端口3模式寄存器1
sfr P5M0 = 0xCA; //0000,0000 端口5模式寄存器0
sfr P5M1 = 0xC9; //0000,0000 端口5模式寄存器1
sfr IE2 = 0xaf; //中斷使能寄存器2
sfr AUXR = 0x8e; //輔助寄存器
sfr T2H = 0xD6; //定時器2高8位
sfr T2L = 0xD7; //定時器2低8位
sfr CLK_DIV = 0x97; //時鐘分頻寄存器
sbit LED = P1^2;
sbit P13 = P1^3;// SEL
sbit P14 = P1^4;// UP
sbit P15 = P1^5;// DN
sbit P30 = P3^0;
sbit P31 = P3^1;
sbit IIC_SDA = P5^5; // SDA-DS3231
sbit IIC_SCL = P5^4; // SCL-DS3231
sbit LCD5110_RES = P3^3; //LCD5110 復位,0復位
sbit LCD5110_CE = P3^6; //LCD5110 片選
sbit LCD5110_DC = P3^7; //LCD5110 1寫數據,0寫指令
sbit LCD5110_SDIN = P1^0; //LCD5110 數據
sbit LCD5110_SCLK = P1^1; //LCD5110 時鐘
bit FLAG; //1:上升沿中斷 0:下降沿中斷
uchar sec, min, hour, day, date, month, year,Dtemp1,Dtemp2;
const unsigned char code F8x8[][8] =
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//0
{0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00},//一
{0x00,0x24,0x24,0x24,0x24,0x24,0x24,0x00},//二
{0x00,0x49,0x49,0x49,0x49,0x49,0x49,0x00},//三
{0x00,0x7F,0x49,0x47,0x41,0x4F,0x49,0x7F},//四
{0x00,0x41,0x49,0x49,0x7F,0x49,0x79,0x40},//五
{0x00,0x44,0x74,0x05,0x06,0x14,0x64,0x40},//六
{0x00,0x7F,0x49,0x49,0x49,0x49,0x7F,0x00},//日
};
const unsigned char code F16x32[][64] =
{
{0x00,0x00,0x00,0x80,0xC0,0xE0,0x60,0x20,0x20,0x60,0xE0,0xC0,0x80,0x00,0x00,0x00,
0xE0,0xFC,0xFF,0xFF,0x0F,0x01,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFC,0xE0,
0x7F,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x7F,
0x00,0x03,0x0F,0x1F,0x3F,0x78,0x60,0x40,0x40,0x60,0x70,0x3F,0x1F,0x0F,0x03,0x00},//0
{0x00,0x00,0x80,0x80,0x80,0x80,0x80,0xC0,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x40,0x40,0x40,0x60,0x7F,0x7F,0x7F,0x7F,0x60,0x40,0x40,0x40,0x00,0x00},//1
{0x00,0x80,0x80,0xC0,0x60,0x20,0x20,0x20,0x20,0x60,0xE0,0xC0,0xC0,0x80,0x00,0x00,
0x3E,0x3F,0x3F,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0xC1,0xFF,0xFF,0xFF,0x3E,0x00,
0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0x70,0x3C,0x1E,0x0F,0x07,0x03,0x00,0x00,0x00,
0x70,0x78,0x7C,0x6F,0x67,0x61,0x60,0x60,0x60,0x60,0x60,0x60,0x78,0x7E,0x1E,0x00},//2
{0x00,0x80,0xC0,0xC0,0x60,0x20,0x20,0x20,0x60,0xE0,0xC0,0xC0,0x80,0x00,0x00,0x00,
0x0F,0x0F,0x0F,0x0E,0x00,0x00,0x00,0x00,0x00,0xC1,0xFF,0xFF,0x7F,0x3E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x07,0x07,0x1D,0xFC,0xF8,0xF0,0xC0,0x00,
0x0E,0x1F,0x3F,0x37,0x60,0x40,0x40,0x40,0x60,0x60,0x38,0x3F,0x1F,0x0F,0x07,0x00},//3
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0xE0,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xC0,0xE0,0x78,0x1E,0x07,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,
0x60,0xF8,0x9C,0x8F,0x83,0x80,0x80,0x80,0x80,0xFF,0xFF,0xFF,0xFF,0x80,0x80,0x80,
0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x7F,0x7F,0x7F,0x7F,0x40,0x40,0x40},//4
{0x00,0x00,0xE0,0xE0,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x00,
0x00,0xF0,0xFF,0x8F,0x80,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,
0x00,0x87,0x87,0x83,0x01,0x00,0x00,0x00,0x00,0x01,0x07,0xFF,0xFF,0xFE,0xF8,0x00,
0x0F,0x1F,0x3F,0x23,0x60,0x40,0x40,0x40,0x60,0x60,0x78,0x3F,0x1F,0x0F,0x03,0x00},//5
{0x00,0x00,0x00,0x80,0x80,0xC0,0xE0,0x60,0x20,0x20,0x20,0xE0,0xE0,0xC0,0x80,0x00,
0xC0,0xFC,0xFE,0xFF,0x0F,0x01,0x80,0x80,0x80,0x80,0x80,0x83,0x03,0x03,0x03,0x00,
0xFF,0xFF,0xFF,0xFF,0x0E,0x07,0x03,0x01,0x01,0x01,0x03,0x0F,0xFF,0xFF,0xFE,0xF8,
0x00,0x07,0x1F,0x3F,0x3E,0x70,0x60,0x40,0x40,0x40,0x60,0x78,0x3F,0x1F,0x0F,0x03},//6
{0x00,0xE0,0xE0,0xE0,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0xE0,0xE0,0x60,0x00,
0x07,0x07,0x01,0x00,0x00,0x00,0x00,0x00,0xC0,0xF0,0x3C,0x0F,0x03,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xE0,0xFC,0xFF,0x0F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x7F,0x7F,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//7
{0x00,0x00,0x80,0xC0,0xC0,0xE0,0x60,0x20,0x20,0x20,0x60,0xE0,0xC0,0xC0,0x80,0x00,
0x00,0x3E,0x7F,0xFF,0xFF,0xE0,0xC0,0x80,0x00,0x00,0x00,0xC0,0xFF,0xFF,0x7F,0x1E,
0xC0,0xF0,0xF8,0xFC,0x1F,0x07,0x03,0x07,0x07,0x0F,0x1F,0x7F,0xFD,0xF8,0xF0,0xC0,
0x07,0x0F,0x1F,0x3F,0x38,0x60,0x60,0x40,0x40,0x40,0x60,0x70,0x3F,0x1F,0x0F,0x07},//8
{0x00,0x00,0x80,0xC0,0xE0,0x60,0x20,0x20,0x20,0x20,0x60,0xC0,0xC0,0x80,0x00,0x00,
0xFC,0xFF,0xFF,0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x81,0xFF,0xFF,0xFE,0xF0,
0x01,0x07,0x0F,0x0F,0x1F,0x1C,0x18,0x18,0x18,0x1C,0x0E,0xC7,0xFF,0xFF,0xFF,0x3F,
0x00,0x1C,0x3C,0x7C,0x7C,0x40,0x40,0x40,0x60,0x70,0x3C,0x1F,0x0F,0x07,0x01,0x00},//9
};
const unsigned char code F6x8[][6] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp 0
{ 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // ! 1
{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // " 2
{ 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // # 3
{ 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $ 4
{ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // % 5
{ 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // & 6
{ 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // ' 7
{ 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // ( 8
{ 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // ) 9
{ 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // * 10
{ 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // + 11
{ 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // , 12
{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // - 13
{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // . 14
{ 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // / 15
{ 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0 16
{ 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1 17
{ 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2 18
{ 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3 19
{ 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4 20
{ 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5 21
{ 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6 22
{ 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7 23
{ 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8 24
{ 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9 25
{ 0x00, 0x3C, 0x42, 0x42, 0x24, 0x01 }, // C"
};
void Delayms(uchar ms) //@6.000MHz
{
unsigned char i, j;
while(ms--){
i = 6;
j = 211;
do
{
while (--j);
} while (--i);}
}
//-----------------------------------------------------------------------------------
void IIC_start(void)
{//IIC總線產生起始信號函數
IIC_SDA=1;//拉高數據線
IIC_SCL=1;//拉高時鐘線
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
IIC_SDA=0;//在時鐘線為高電平時,拉低數據線,產生起始信號。
IIC_SCL=0;//拉低時鐘線
}
//-------------------------------------------------------------------
void IIC_stop(void)
{//IIC總線產生停止信號函數
IIC_SDA=0;//拉低數據線
IIC_SCL=1;//拉高時鐘線。
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
IIC_SDA=1;//時鐘時線為高電平時,拉高數據線,產生停止信號。
}
//-------------------------------------------------------------------
bit IIC_Tack(void)
{//接收應答信號函數
bit ack;//定義一個位變量,來暫存應答狀態。
IIC_SDA=1;//釋放數據總線,準備接收應答信號。
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
IIC_SCL=1;//拉高時鐘線。
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
ack=IIC_SDA;//讀取應答信號的狀態。
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
IIC_SCL=0;//拉低時鐘線。
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
return ack;//返回應答信號的狀態,0表示應答,1表示非應答。
}
//-------------------------------------------------------------------
void IIC_write_byte(unsigned char Data)
{//向IIC總線寫入一個字節的數據函數
unsigned char i;
for(i=0;i<8;i++)//有8位數據
{
IIC_SDA=Data&0x80;//寫最高位的數據
IIC_SCL=1; //拉高時鐘線,將數寫入到設備中。
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
IIC_SCL=0;//拉低時鐘線,允許改變數據線的狀態
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
Data=Data<<1;//數據左移一位,把次高位放在最高位,為寫入次高位做準備
}
}
//-------------------------------------------------------------------
unsigned char IIC_read_byte()
{//從IIC總線讀取一個字節的數據函數
unsigned char i;
unsigned char Data; //定義一個緩沖寄存器。
for(i=0;i<8;i++)//有8位數據
{
IIC_SCL=1;//拉高時鐘線,為讀取下一位數據做準備。
Data=Data<<1;//將緩沖字節的數據左移一位,準備讀取數據。
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
if(IIC_SDA)//如果數據線為高平電平。
Data=Data|0x01;//則給緩沖字節的最低位寫1。
IIC_SCL=0;//拉低時鐘線,為讀取下一位數據做準備。
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
}
return Data;//返回讀取的一個字節數據。
}
//-------------------------------------------------------------------
void IIC_single_byte_write(unsigned char Waddr,unsigned char Data)
{//向任意地址寫入一個字節數據函數
IIC_start();//產生起始信號
IIC_write_byte(0xd0);//寫入設備地址(寫)
IIC_Tack();//等待設備的應答
IIC_write_byte(Waddr);//寫入要操作的單元地址。
IIC_Tack();//等待設備的應答。
IIC_write_byte(Data);//寫入數據。
IIC_Tack();//等待設備的應答。
IIC_stop();//產生停止符號。
}
//-------------------------------------------------------------------
unsigned char IIC_single_byte_read(unsigned char Waddr)
{//從任意地址讀取一個字節數據函數
unsigned char Data;//定義一個緩沖寄存器。
IIC_start();//產生起始信號
IIC_write_byte(0xd0);//寫入設備地址(寫)
IIC_Tack();//等待設備的應答
IIC_write_byte(Waddr);//寫入要操作的單元地址。
IIC_Tack();//等待設備的應答。
IIC_stop();//產生停止符號。
IIC_start();//產生起始信號
IIC_write_byte(0xd1);//寫入設備地址(寫)
IIC_Tack();//等待設備的應答
Data=IIC_read_byte();//寫入數據。
_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
IIC_stop();//產生停止符號。
//-------------------返回讀取的數據--------------------
return Data;//返回讀取的一個字節數據。
}
//------------------------------------------------------------------------
void DS3231_Init(void)
{
IIC_single_byte_write(0x0E,0x60);
IIC_single_byte_write(0x0F,0x80);
/*IIC_single_byte_write(0x01,B_BCD(28));//28
IIC_single_byte_write(0x02,B_BCD(22));//22
IIC_single_byte_write(0x03,B_BCD(7));//日
IIC_single_byte_write(0x04,B_BCD(19));//19
IIC_single_byte_write(0x05,B_BCD(3));//03
IIC_single_byte_write(0x06,B_BCD(17));//17 */
}
//--------------------------------------------------------------------------
uchar BCD2HEX(uchar val) //BCD轉換為Byte
{
return ((val>>4)*10)+(val&0x0f);
}
//--------------------------------------------------------------------------
uchar B_BCD(uchar val)//Byte碼轉換為BCD碼
{
return (((val%100)/10)<<4)|(val%10);
}
//--------------------------------------------------------------------------
void Readtime()
{
uchar temp;
temp=IIC_single_byte_read(0x00);//秒
sec=(int)BCD2HEX(temp);
temp=IIC_single_byte_read(0x01);//分
min=BCD2HEX(temp);
temp=IIC_single_byte_read(0x02); //時
hour=BCD2HEX(temp);
day=IIC_single_byte_read(0x03);//星期
temp=IIC_single_byte_read(0x04); //日
date=BCD2HEX(temp);
temp=IIC_single_byte_read(0x05); //月
month=BCD2HEX(temp);
temp=IIC_single_byte_read(0x06); //年
year=BCD2HEX(temp);
}
//void Ttemp_read()
//{
//IIC_single_byte_write(0x0E,0x20);
// Dtemp1=IIC_single_byte_read(0x11);//溫度高位
//Dtemp2=IIC_single_byte_read(0x12);//溫度低位+-0.25度變化
//Dtemp2=(Dtemp2>>6)*25;
//}
//-----------------------------------------------------------------------------------
void LCD_write_byte(unsigned char dt, unsigned char command)//LCD5110寫入數據
{
unsigned char i;
LCD5110_CE=0; // 關閉LCD
LCD5110_DC=command; // 0是寫命令,1是寫數據
for(i=0;i<8;i++)
{
if(dt&0x80)
LCD5110_SDIN=1;
else
LCD5110_SDIN=0;
dt=dt<<1; //dt為暫存數據
LCD5110_SCLK=0;
LCD5110_SCLK=1;
}
LCD5110_DC=1;
LCD5110_CE=1;
LCD5110_SDIN=1;
}
void LCD_write_byteone()//LCD5110寫入數據
{
LCD5110_CE=0; // 關閉LCD
LCD5110_DC=1; // 0是寫命令,1是寫數據
LCD5110_SDIN=1;
LCD5110_SCLK=0;
LCD5110_SCLK=1;
LCD5110_DC=1;
LCD5110_CE=1;
LCD5110_SDIN=1;
}
void LCD_clear(void) //5110LCD清屏
{
unsigned int i;
LCD_write_byte(0x0c, 0);
LCD_write_byte(0x80, 0);
for (i=0; i<504; i++)
LCD_write_byte(0, 1);
}
void LCD_set_XY(unsigned char X, unsigned char Y) //x 左右共0~83列可移,Y由上至下共0~5行可移
{
LCD_write_byte(0x40 | Y, 0); // column Y+=64
LCD_write_byte(0x80 | X, 0); // row X+=128
}
void LCD_init(void) //5110LCD初始化LCD_init
{
LCD5110_RES=0; // 產生一個讓LCD復位的低電平脈沖
Delayms(10);
LCD5110_RES=1;
LCD5110_CE = 0; // 關閉LCD
Delayms(10);
LCD5110_CE = 1;// 使能LCD
Delayms(10);
LCD_write_byte(0x21, 0); // 使用擴展命令設置LCD模式
LCD_write_byte(0xBC, 0); // 設置偏置電壓//不同的屏須要微調此參數B9~C9
LCD_write_byte(0x06, 0); // 溫度校正
LCD_write_byte(0x13, 0); // 1:48
LCD_write_byte(0x20, 0); // 使用基本命令
LCD_clear(); // 清屏
LCD_write_byte(0x0C, 0); // 設定顯示模式,正常顯示
LCD5110_CE = 0; // 關閉LCD
}
void LCD_P6x8Str(unsigned char x,unsigned char y,unsigned char ch)
{
unsigned char i;
LCD_set_XY(x,y);
for(i=0;i<6;i++){ LCD_write_byte(F6x8[ch],1); }
}
void LCD_P16x32Str(unsigned char x,unsigned char y,unsigned char ch)
{
unsigned char i;
LCD_set_XY(x,y);
for(i=0;i<16;i++){ LCD_write_byte( F16x32[ch],1); }
LCD_set_XY(x,y+1);
for(i=16;i<32;i++){ LCD_write_byte( F16x32[ch],1); }
LCD_set_XY(x,y+2);
for(i=32;i<48;i++){ LCD_write_byte( F16x32[ch],1); }
LCD_set_XY(x,y+3);
for(i=48;i<64;i++){ LCD_write_byte( F16x32[ch],1); }
}
void LCD_P8x8Str(unsigned char x,unsigned char y,unsigned char ch)
{
unsigned char i;
LCD_set_XY(x,y);
for(i=0;i<8;i++){ LCD_write_byte(F8x8[ch],1); }
}
void main()
{
bit seet=0;
uchar a1,a2,a3;
uchar key1,tt,tt2,tt3,
P1M0 =P1M1 = 0x00;
P3M0 =P3M1 = 0x00;
P5M0 =P5M1 = 0x00;
DS3231_Init();
LCD_init();
IT0 = 1; //設置INT0的中斷類型為下降沿喚醒
EX0 = 1; //使能INT0中斷
EA = 1;
Readtime();
LCD_P6x8Str(6,0,16+2); //2
LCD_P6x8Str(12,0,16+0); //0
LCD_P6x8Str(18,0,16+year/10);//1
LCD_P6x8Str(24,0,16+year%10);//7
LCD_P6x8Str(30,0,13); //-
LCD_P6x8Str(36,0,16+month/10);//0
LCD_P6x8Str(42,0,16+month%10);//3
LCD_P6x8Str(48,0,13); //-
LCD_P6x8Str(54,0,16+date/10); //1
LCD_P6x8Str(60,0,16+date%10); //9
LCD_P8x8Str(72,0,day);
LCD_P16x32Str(2,1,hour/10);//時十位
LCD_P16x32Str(20,1,hour%10);//時個位
LCD_set_XY(40,2),LCD_write_byte(0x20,1);
LCD_set_XY(41,2),LCD_write_byte(0x70,1);
LCD_set_XY(42,2),LCD_write_byte(0x70,1);
LCD_set_XY(43,2),LCD_write_byte(0x20,1);
LCD_set_XY(40,4),LCD_write_byte(0x02,1);
LCD_set_XY(41,4),LCD_write_byte(0x07,1);
LCD_set_XY(42,4),LCD_write_byte(0x07,1);
LCD_set_XY(43,4),LCD_write_byte(0x02,1);
LCD_P16x32Str(48,1,min/10);//分十位
LCD_P16x32Str(66,1,min%10);//分個位
while(1)
{
if(!P13){ while(!P13);
a1=a2=a3=0;
LED = 0;
goto MEN;
}
time: Readtime();
LCD_set_XY(sec,5);
LCD_write_byte(0x00,1);
LCD_write_byte(0x40,1);
if(sec==00)//一分鐘刷新一次分顯示
{
LCD_P16x32Str(48,1,min/10);//分十位
LCD_P16x32Str(66,1,min%10);//分個位
//Ttemp_read();
//LCD_P6x8Str(48,5,16+Dtemp1/10);
//LCD_P6x8Str(54,5,16+Dtemp1%10);
//LCD_P6x8Str(60,5,14); //.
//LCD_P6x8Str(66,5,16+Dtemp2/10);
//LCD_P6x8Str(72,5,16+Dtemp2%10);
//LCD_P6x8Str(78,5,26);
if(min==0)//一小時刷新一次時顯示
{
LCD_P16x32Str(2,1,hour/10);//時十位
LCD_P16x32Str(20,1,hour%10);//時個位
if(hour==0)//24小時刷新一次年、月、日顯示
{
LCD_P6x8Str(18,0,16+year/10);//1
LCD_P6x8Str(24,0,16+year%10);//7
LCD_P6x8Str(36,0,16+month/10);//0
LCD_P6x8Str(42,0,16+month%10);//3
LCD_P6x8Str(54,0,16+date/10); //1
LCD_P6x8Str(60,0,16+date%10); //9
LCD_P8x8Str(72,0,day);
}
}
}
PCON |= 0x02;
}
while(1)
{
MEN :
if(!P13)//SEL
{
Delayms(10);
if(!P13)
{
key1++;
a1=a2=a3=0;
if(key1==7){key1=0;}
while(!P13);
}
}
switch(key1)
{
case 1: {LCD_set_XY(48,5); //分指針
for(tt=0;tt<33;tt++){LCD_write_byteone();}
}
}
a1++;
if(a1>250)
{
a1=0;
a2++;
if(a2>250)
{
Readtime();
LCD_set_XY(sec,5);
LCD_write_byte(0x00,1);
LCD_write_byte(0x40,1);
LCD_P6x8Str(6,0,16+2); //2
LCD_P6x8Str(12,0,16+0); //0
LCD_P6x8Str(18,0,16+year/10);//1
LCD_P6x8Str(24,0,16+year%10);//7
LCD_P6x8Str(30,0,13); //-
LCD_P6x8Str(36,0,16+month/10);//0
LCD_P6x8Str(42,0,16+month%10);//3
LCD_P6x8Str(48,0,13); //-
LCD_P6x8Str(54,0,16+date/10); //1
LCD_P6x8Str(60,0,16+date%10); //9
LCD_P8x8Str(72,0,day); //星期幾
LCD_P16x32Str(2,1,hour/10);//時十位
LCD_P16x32Str(20,1,hour%10);//時個位
LCD_set_XY(40,2),LCD_write_byte(0x20,1);//
LCD_set_XY(41,2),LCD_write_byte(0x70,1);//
LCD_set_XY(42,2),LCD_write_byte(0x70,1);//
LCD_set_XY(43,2),LCD_write_byte(0x20,1);//
LCD_set_XY(40,4),LCD_write_byte(0x02,1);//
LCD_set_XY(41,4),LCD_write_byte(0x07,1);//
LCD_set_XY(42,4),LCD_write_byte(0x07,1);//
LCD_set_XY(43,4),LCD_write_byte(0x02,1);//
a2=0;
a3++;
if(a3>250)
{
a3=0;
LED =1;
goto time;
}
}
}
}
}
void exint0() interrupt 0 //INT0中斷入口
{
FLAG = INT0; //保存INT0口的狀態, INT0=0(下降沿); INT0=1(上升沿)
}
|