#include "../include/config.h"
typedef unsigned char uchar ;
typedef unsigned int uint ;
//lpc2103开发板相关引脚 详见原理图
//字模信息
const unsigned char Number[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : 0123456789-:
; 宽×高(像素): 72×8
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/59字节
; 数据转换日期 : 2012-9-10 19:52:23
------------------------------------------------------------------------------*/
0x7E,0x81,0x81,0x81,0x7E,0x00,0x00,0x82,0xFF,0x80,0x00,0x00,0xC6,0xA1,0x91,0x89,
0x86,0x00,0x42,0x81,0x89,0x89,0x76,0x00,0x10,0x2C,0x22,0xFF,0xA0,0x00,0x4F,0x89,
0x89,0x89,0x71,0x00,0x7E,0x89,0x89,0x8B,0x70,0x00,0x03,0x01,0xF9,0x07,0x01,0x00,
0x76,0x89,0x89,0x89,0x76,0x00,0x0E,0xD1,0x91,0x91,0x7E,0x00,0x00,0x18,0x18,0x18,
0x18,0x00,0x00,0x00,0x24,0x00,0x00,0x00
};
const unsigned char zhou[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : 周一二三四五六日
; 宽×高(像素): 84×8
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/84字节
; 数据转换日期 : 2012-9-11 18:44:45
------------------------------------------------------------------------------*/
0xC0,0x3F,0x09,0x79,0x57,0x75,0x85,0x7F,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,
0x08,0x08,0x00,0x00,0x00,0x40,0x44,0x44,0x44,0x44,0x44,0x42,0x00,0x00,0x00,0x40,
0x42,0x52,0x52,0x52,0x4A,0x40,0x00,0x00,0x00,0xFF,0xB1,0x8F,0x81,0x9F,0xA1,0xFF,
0x00,0x00,0x00,0x41,0x49,0x7F,0x49,0x49,0x79,0x41,0x00,0x00,0x80,0x44,0x34,0x0C,
0x03,0x0C,0x34,0x44,0x00,0x00,0x00,0x00,0x7F,0x49,0x49,0x49,0x7F,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
};
const unsigned char jiadian[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : 电视
; 宽×高(像素): 16×16
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/32字节
; 数据转换日期 : 2012-9-12 14:38:00
------------------------------------------------------------------------------*/
0x00,0xE0,0x10,0x08,0xC8,0x48,0x4B,0x0C,0x0C,0x0C,0x4C,0x4A,0xC9,0x10,0xE0,0x00,
0x00,0x1F,0x20,0x20,0x27,0x28,0x20,0x20,0x20,0x20,0x28,0x28,0x2F,0x20,0x1F,0x00,
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : 冰箱
; 宽×高(像素): 16×16
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/32字节
; 数据转换日期 : 2012-9-12 14:45:06
------------------------------------------------------------------------------*/
0x00,0x00,0xFC,0x02,0x02,0x02,0x02,0x02,0x02,0x32,0x32,0x02,0x02,0xFE,0x00,0x00,
0x00,0x00,0x7F,0x41,0x41,0x41,0x41,0x41,0x41,0x4D,0x4D,0x41,0x41,0x7F,0x00,0x00,
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : 热水器
; 宽×高(像素): 16×16
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/32字节
; 数据转换日期 : 2012-9-12 14:42:48
------------------------------------------------------------------------------*/
0x00,0xE0,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0xC8,0x28,0xA8,0xC8,0x10,0xE0,0x00,
0x00,0x03,0x04,0x08,0x08,0x08,0x08,0x08,0x08,0x09,0x0B,0x0A,0x09,0x04,0x07,0x00,
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : 灯
; 宽×高(像素): 16×16
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/32字节
; 数据转换日期 : 2012-9-12 14:45:53
------------------------------------------------------------------------------*/
0x00,0x00,0xFC,0x04,0x04,0x04,0x04,0x84,0xC4,0xF4,0xFC,0xE0,0xC0,0x00,0x00,0x00,
0x00,0x00,0x3F,0x00,0x00,0x00,0x0C,0x02,0x03,0x00,0x0F,0x03,0x06,0x08,0x00,0x00,
};
const unsigned char stat[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : 开关
; 宽×高(像素): 16×8
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/16字节
; 数据转换日期 : 2012-9-12 14:57:58
------------------------------------------------------------------------------*/
0x20,0x10,0x10,0x60,0x80,0x70,0x0E,0x01,0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00,
};
const unsigned char clock[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 :
; 宽×高(像素): 14×16
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/28字节
; 数据转换日期 : 2012-9-12 18:37:46
------------------------------------------------------------------------------*/
0x00,0x00,0xF0,0x08,0x0C,0x0C,0x8C,0x4C,0x2C,0x0C,0x08,0xF0,0x00,0x00,0x00,0x00,
0x0F,0x08,0x08,0x08,0x0B,0x08,0x08,0x08,0x08,0x0F,0x00,0x00,
};
const unsigned char timer[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : Timer
; 宽×高(像素): 29×8
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/29字节
; 数据转换日期 : 2012-9-12 19:11:10
------------------------------------------------------------------------------*/
0x02,0x02,0xFE,0xFE,0x02,0x02,0xFA,0xFA,0x00,0xF8,0xF8,0x08,0xF8,0xF0,0x08,0xF8,
0xF0,0x00,0x70,0xF8,0xA8,0xB8,0xB0,0x00,0xF8,0xF8,0x10,0x08,0x00,
};
const unsigned char temp[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : ℃
; 宽×高(像素): 8×8
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/8字节
; 数据转换日期 : 2012-9-12 18:56:42
------------------------------------------------------------------------------*/
0x06,0x09,0x7E,0x84,0x82,0x82,0x42,0x04,
};
const unsigned char msg[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : Msg
; 宽×高(像素): 19×8
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/19字节
; 数据转换日期 : 2012-9-12 19:17:38
------------------------------------------------------------------------------*/
0x3F,0x03,0x0E,0x0C,0x02,0x3F,0x3F,0x00,0x2C,0x2E,0x3A,0x1A,0x00,0x1C,0xBE,0xA2,
0xFE,0x7E,0x00,
};
const unsigned char none[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : None
; 宽×高(像素): 30×8
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/30字节
; 数据转换日期 : 2012-9-12 19:21:43
------------------------------------------------------------------------------*/
0x00,0x3F,0x03,0x06,0x0C,0x18,0x3F,0x00,0x1C,0x3E,0x22,0x22,0x3E,0x1C,0x00,0x3E,
0x3E,0x02,0x02,0x3E,0x3C,0x00,0x1C,0x3E,0x2A,0x2A,0x2E,0x2C,0x00,0x00,
};
const unsigned char timerlist[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : TimerList
; 宽×高(像素): 39×8
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/39字节
; 数据转换日期 : 2012-9-13 11:47:56
------------------------------------------------------------------------------*/
0x01,0x01,0x7F,0x01,0x01,0x00,0x7D,0x00,0x7C,0x04,0x04,0x78,0x04,0x04,0x78,0x00,
0x38,0x54,0x54,0x58,0x00,0x7C,0x08,0x04,0x00,0x7F,0x40,0x40,0x40,0x00,0x7D,0x00,
0x4C,0x54,0x64,0x00,0x3F,0x44,0x00,
};
const unsigned char team02[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : Team2?:-D
; 宽×高(像素): 52×8
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/52字节
; 数据转换日期 : 2012-9-13 11:53:00
------------------------------------------------------------------------------*/
0x01,0x01,0x7F,0x01,0x01,0x00,0x38,0x54,0x54,0x58,0x00,0x20,0x54,0x54,0x78,0x00,
0x7C,0x04,0x04,0x78,0x04,0x04,0x78,0x00,0x61,0x51,0x49,0x46,0x00,0x3C,0x42,0x99,
0xA5,0xA5,0xA5,0x42,0x3C,0x00,0x00,0x6C,0x00,0x00,0x08,0x08,0x08,0x00,0x7F,0x41,
0x41,0x41,0x22,0x1C,
};
const unsigned char arrow[]=
{
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : 箭头left
; 宽×高(像素): 5×6
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/5字节
; 数据转换日期 : 2012-9-13 11:54:00
------------------------------------------------------------------------------*/
0x0C,0x1E,0x3F,0x0C,0x0C,
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : 箭头up
; 宽×高(像素): 5×6
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/5字节
; 数据转换日期 : 2012-9-13 13:47:22
------------------------------------------------------------------------------*/
0x04,0x1E,0x1F,0x1E,0x04,
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : 箭头down
; 宽×高(像素): 5×6
; 字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/5字节
; 数据转换日期 : 2012-9-13 13:47:22
------------------------------------------------------------------------------*/
0x08,0x1E,0x3E,0x1E,0x08
};
//uart引脚
//#define TxD0 1<<0
//#define RxD0 1<<1
#define UART_BPS 9600 //初始化uart波特率
#define LCD12864_RS (1<<18)
#define LCD12864_RW (1<<16)
#define LCD12864_EN (1<<17)
#define LCD12864_LEFT (1<<24)
#define LCD12864_RIGHT (1<<19)
#define LCD12864_DATABUS ( 0x060000fc )
#define LCD12864_BUSY (1<<26) //BUSY
#define SET_PAGE 0xb8
#define SET_COW 0x40
#define KC0 (1<<20)
#define KC1 (1<<21)
#define KH0 (1<<22)
#define KH1 (1<<23)
#define TIMEMAX 10
#define NORMAL 0
#define RESERVE 1
#define BLACK 2
#define WHITE 3
#define MENU_WIDTH 40
#define MENU_HEIGHT 10
#define MENU_OFFSET 8
#define MENU_X 0
#define MENU_Y 0
#define KEYUP 1
#define KEYDOWN 3
#define KEYLEFT 2
#define KEYRIGHT 4
#define LED1CON 0x00000800 //P0.11 引脚控制LED1,低电平点亮 1000 0000 0000 1<<11
#define LED2CON 0x00001000 //P0.12 引脚控制LED2,低电平点亮 1<<12
#define LED3CON 0x00002000 //P0.13 引脚控制LED3,低电平点亮
#define LED4CON 0x00004000 //P0.14 引脚控制LED4,低电平点亮
//相关结构体定义
typedef struct{
int width;
int height;
}Pic;
typedef struct{
int year;
int mon;
int dom;
int day;
int hour;
int min;
int sec;
}TIME;
typedef struct{
uchar hour;
uchar min;
uchar stat;
}ALARM;
//8位全局变量 第0 - 3 位 保存电器开关状态 4 - 7 位 待定
ALARM lst[10];
uint32 val;
uchar state = 0xff;
Pic pic = {6, 8};
Pic clean = {128, 64};
Pic menu = {30, 16};
Pic subclr = {128, 40};
Pic node = {8, 8};
// 1 状态一级菜单 2定时一级菜单 2 - n 定时二级菜单
uchar n_menu = 1;
uchar ns_menu = 0;
uchar flg_timer = 0;
uchar rcvbyte;
uchar minium = 0;
//lpc2000功能函数原型
void PLLInit( void );
void Time0Init( void );
void Int0Init(int (*func)(void),int intType );
void Int1Init(int (*func)(void),int intType );
void Int2Init( int (*func)(void), int intType );
__irq void ABC( void );
//12864点阵屏函数原型
void WriteCmd(uchar cmd);
void WriteData(uchar data);
void InitLCD(void);
void vCheckBusy(void) ;
void DelayNS(uint time);
void DisplayBitImage(const uchar *img, Pic *pic, int x, int y, int opt); // 图片宽高, 图片起始位置
void vCleanAll(int opt);
//矩阵键盘函数原型
char KeyDown(void);
char KeyNum(void);
//串口通信相关函数原型
uchar UART0_RcvByte( void );
void UART0_SendByte(uchar data);
void UART0_SendString( char* String);
void UART0Init( void );
//时钟定时相关函数
void RTCIni(void);
void set_time(TIME *time);
void set_alarm(ALARM *alm);
void TimerInit(void);
void Update()
{
UART0_SendByte(0xef);
UART0_SendByte(state);
UART0_SendByte((YEAR & 0xff00) >> 8);
UART0_SendByte((YEAR & 0x00ff));
UART0_SendByte(MONTH);
UART0_SendByte(DOM);
UART0_SendByte(HOUR);
UART0_SendByte(MIN);
UART0_SendByte(DOW);
UART0_SendByte(val >> 4);
}
__irq void UARTProc( void )
{
rcvbyte = U0RBR;
if (rcvbyte == 0xef)
{
UART0_SendByte(0xef);
UART0_SendByte(state);
UART0_SendByte((YEAR & 0xff00) >> 8);
UART0_SendByte((YEAR & 0x00ff));
UART0_SendByte(MONTH);
UART0_SendByte(DOM);
UART0_SendByte(HOUR);
UART0_SendByte(MIN);
UART0_SendByte(DOW);
UART0_SendByte(val >> 4);
VICVectAddr = 0x00;
return;
}
if(rcvbyte == 0xff)
{
rcvbyte = U0RBR;
if( rcvbyte & 0x80) YEAR = 2012 + (rcvbyte & 0x7f);
else YEAR = 2012 - rcvbyte;
MONTH = U0RBR;
DOM = U0RBR;
HOUR = U0RBR;
MIN = U0RBR;
DOW = U0RBR;
VICVectAddr = 0x00;
return;
}
if(rcvbyte == 0xee)
{
state = U0RBR;
VICVectAddr = 0x00;
return;
}
if( rcvbyte == 0xdd)
{
int i;
//腾出空位给新加入的定时信息
for(i = 9; i > ns_menu; --i)
{
lst[i].stat = lst[i - 1].stat;
lst[i].hour = lst[i - 1].hour;
lst[i].min = lst[i - 1].min;
}
lst[ns_menu].stat = U0RBR;
lst[ns_menu].hour = U0RBR;
lst[ns_menu].min = U0RBR;
}
VICVectAddr = 0x00;
}
void LED_Water()
{
uint32 nLoop;
int i = 0;
for(i;i !=5; ++i)
for (nLoop=0x00000800;nLoop<0x00008000;nLoop<<=1)
{
IOCLR = nLoop;
DelayNS(15);
IOSET = nLoop;
}
}
//EINT2外部中断
__irq void EINTProc( void )
{
//DisplayBitImage(Number + 10 * 6, &pic, 0, 15, 0);
DelayNS(10);
while((EXTINT&0x04)!=0) //等待外部中断信号恢复为高电平
{
EXTINT=0x04; //通过写入1清除标志
}
LED_Water();
VICVectAddr = 0x00;
}
//RTC定时中断
__irq void RTCProc( void )
{
int i = minium;
int j = 0;
//清除定时序列项
//minium = 0;
//寻找其他相同时间的定时信息
for(i = minium; i != 10;)
{
if( lst[i].hour == HOUR && lst[i].min == MIN)
{
if((lst[i].stat & 0x0f) >> 3)
state |= 1 << (3 - lst[i].stat & 0x07);
else
state &= ~( 1 << (3 - lst[i].stat & 0x07));
}
for(j = i; j != 9; ++j)
{
lst[j].hour = lst[j+1].hour;
lst[j].min = lst[j+1].min;
lst[j].stat = lst[j+1].stat;
}
if( lst[i].hour == HOUR && lst[i].min == MIN)
{
continue ;
}
i++;
}
minium = 0;
Update();
ILR = 0x03;
VICVectAddr = 0x00;
}
void adc (void)
{
ADCR |= 0x01000000; //Start A/D Conversion
do{
val = ADDR3; //Read A/D Data Register
} while ((val & 0x80000000) == 0); //Wait for end of A/D Conversion
ADCR &= ~0x01000000; //Stop A/D Conversion
val = (val >> 6) & 0x03FF; //Extract AIN3 Value
}
void LED_Ctl(uchar number, uchar flg)
{
if(flg == 0)
IOCLR = (1 << (10 + number));
else
IOSET = (1 << (10 + number));
}
//int n_menu = 0;
int main()
{
int i = 0;
TIME chag = { 2012, 1, 1, 1, 1, 1, 58};
ALARM lsttmp;
Pic clck = {14, 16};
Pic jd = {16, 16};
Pic xingqi = {10, 8};
Pic zmtimer = {29, 8};
Pic zmmsg = { 19, 8};
Pic zmnone = {30, 8};
Pic zmarrow = {5, 6};
Pic zmteam02 = {52, 8};
Pic zmtimerlist ={39, 8};
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
//初始化矩阵键盘引脚功能
PINSEL1 &= 0xFFFF00FF; //P0.20 ~P0.23 为GPIO
IODIR |= 0x00F00000;
IOSET |= 0x00F00000;
//LED引脚控制
IODIR |=LED1CON+LED2CON+LED3CON+LED4CON; //设置LED、BEEP控制口为输出,其它I/O为输入
IOSET = LED1CON + LED2CON + LED3CON + LED4CON;
//初始化12864相关引脚功能
PINSEL0 &= 0xFFFF000F; //P0.2~P0.7为GPIO
PINSEL1 &= 0xFFC0FF00; //P0.16~P0.19、P0.24~P0.26为GPIO
IODIR |= 0x070F00FC; //P0.2~P0.7、P0.24~P0.26、P0.16~P0.19输出
IOCLR = 0x070F00FC; //输出初始化零
//初始化uart引脚功能
PINSEL0 |= 0x00000005;
//初始化AD模块
PINSEL0 |=0x00300000; //设置IO口工作模式,P0.10设置为AIN3
ADCR = 0x00200408; //Setup A/D: 10-bit AIN3 @ 3MHz
//初始化Eint2外部中断
PINSEL0 |= 0x40000000;
EXTMODE=0x00; //EINT2电平触发
EXTPOLAR=0x00; //EINT2低电平有效
EXTINT=0x04; //清除外部中断标志
//IODIR
IRQEnable();
InitLCD();
UART0Init();
//注册UART终端
Int0Init((int(*)(void))UARTProc, 6);
//注册RTC终端
RTCIni();
//启动RTC
Int1Init((int(*)(void))RTCProc, 13);
//注册外部int2中断
Int2Init((int(*)(void))EINTProc, 16);
//初始化定时列表
for (i = 0; i != 10; ++i)
{
lst[i].hour = 0;
lst[i].min = 0;
lst[i].stat = 0x00;
}
lst[0].hour = 1;
lst[0].min = 2;
lst[0].stat = 0xf3;
lst[1].hour = 1;
lst[1].min = 2;
lst[1].stat = 0xf2;
lst[2].hour = 1;
lst[2].min = 2;
lst[2].stat = 0xf0;
lst[3].hour = 1;
lst[3].min = 2;
lst[3].stat = 0xf1;
//flg_timer = 10;
vCleanAll(WHITE);
//静态页面绘制
//vCleanAll(WHITE);
// 前两页
DisplayBitImage(Number + 10 * 6, &pic, pic.width * 4, 56, 0);
DisplayBitImage(Number + 10 * 6, &pic, pic.width * 7, 56, 0);
DisplayBitImage(Number + 11 * 6, &pic, menu.width * 2 + 5 + pic.width * 2, 56, 0);
DisplayBitImage(Number + 11 * 6, &pic, menu.width * 2 + 5 + pic.width * 5, 56, 0);
DisplayBitImage(temp, &node, menu.width * 2 + 5 + xingqi.width * 1, 4, 0);
//DisplayBitImage(team02, &zmteam02, 0, 0, 0);
//DisplayBitImage(timerlist, &zmtimerlist, 0, 4, 1);
//后两页
//vCleanAll(WHITE);
//电视状态显示
DisplayBitImage(jiadian, &jd, 5, 16, 0);
DisplayBitImage(stat + 8 * ((state & 0x08) >> 3), &node, 5 + jd.width, 20, 0);
//冰箱
DisplayBitImage(jiadian + 32 * 1, &jd, 5 + jd.width + node.width + 5 , 16, 0);
DisplayBitImage(stat + 8 * ((state & 0x04) >> 2), &node, 5 + jd.width * 2 + node.width + 5, 20, 0);
//热水器
DisplayBitImage(jiadian + 32 * 2, &jd, 5, 32, 0);
DisplayBitImage(stat + 8 * ((state & 0x02) >> 1), &node, 5 + jd.width, 36, 0);
//灯
DisplayBitImage(jiadian + 32 * 3, &jd, 5 + jd.width + node.width + 5 , 32, 0);
DisplayBitImage(stat + 8 * ((state & 0x01) >> 0), &node, 5 + jd.width * 2 + node.width + 5, 36, 0);
//timerlist
DisplayBitImage(timerlist, &zmtimerlist, 6, 4, 0);
//DisplayBitImage(team02, &zmteam02, 0, 48, 0);
set_time(&chag);
while(1)
{
uchar RetKey = KeyNum();
DisplayBitImage(zhou + DOW * 10, &xingqi, menu.width * 2 + 47 + xingqi.width * 1, 56, 0);
DisplayBitImage(Number + HOUR / 10 * 6,&pic, menu.width * 2 + 5 + pic.width * 0, 56, 0);
DisplayBitImage(Number + HOUR % 10 * 6, &pic, menu.width * 2 + 5 + pic.width * 1, 56, 0);
// DisplayBitImage(Number + 11 * 6, &pic, menu.width * 2 + 5 + pic.width * 2, 4, 0);
DisplayBitImage(Number + MIN / 10 * 6, &pic, menu.width * 2 + 5 + pic.width * 3, 56, 0);
DisplayBitImage(Number + MIN % 10 * 6, &pic, menu.width * 2 + 5 + pic.width * 4, 56, 0);
// DisplayBitImage(Number + 11 * 6, &pic, menu.width * 2 + 5 + pic.width * 5, 4, 0);
DisplayBitImage(Number + SEC / 10 * 6, &pic, menu.width * 2 + 5 + pic.width * 6, 56, 0);
DisplayBitImage(Number + SEC % 10 * 6, &pic, menu.width * 2 + 5 + pic.width * 7, 56, 0);
//DisplayBitImage(jiadian, &jd, 5, 16, 0);
//电视
DisplayBitImage(stat + 8 * ((state & 0x08) >> 3), &node, 5 + jd.width, 20, 0);
//冰箱
//DisplayBitImage(jiadian + 32 * 1, &jd, 5 + jd.width + node.width + 5 , 16, 0);
DisplayBitImage(stat + 8 * ((state & 0x04) >> 2), &node, 5 + jd.width * 2 + node.width + 5, 20, 0);
//热水器
//DisplayBitImage(jiadian + 32 * 2, &jd, 5, 32, 0);
DisplayBitImage(stat + 8 * ((state & 0x02) >> 1), &node, 5 + jd.width, 36, 0);
//灯
//DisplayBitImage(jiadian + 32 * 3, &jd, 5 + jd.width + node.width + 5 , 32, 0);
DisplayBitImage(stat + 8 * ((state & 0x01) >> 0), &node, 5 + jd.width * 2 + node.width + 5, 36, 0);
DisplayBitImage(Number + YEAR / 1000 * 6, &pic, 0, 56, 0);
DisplayBitImage(Number + YEAR % 1000 / 100 * 6, &pic, pic.width * 1, 56, 0);
DisplayBitImage(Number + YEAR % 100 / 10 * 6, &pic, pic.width * 2, 56, 0);
DisplayBitImage(Number + YEAR % 10 * 6, &pic, pic.width * 3, 56, 0);
DisplayBitImage(Number + MONTH / 10 * 6, &pic, pic.width * 5, 56, 0);
DisplayBitImage(Number + MONTH % 10 * 6, &pic, pic.width * 6, 56, 0);
DisplayBitImage(Number + DOM / 10 * 6, &pic, pic.width * 8, 56, 0);
DisplayBitImage(Number + DOM % 10 * 6, &pic, pic.width * 9, 56, 0);
//温度
DisplayBitImage(Number + (val >> 4) / 10 * 6, &pic, menu.width * 2 - 7 + xingqi.width * 1, 4, 0);
DisplayBitImage(Number + (val >> 4) % 10 * 6, &pic, menu.width * 2 - 1 + xingqi.width * 1, 4, 0);
//定时信息
DisplayBitImage(jiadian + (lst[ns_menu].stat & 0x07) * 32 , &jd, 94 + pic.width * 0, 16, 0);
DisplayBitImage(stat + ((lst[ns_menu].stat & 0x0f) >>3) * 8 , &node, 96 + jd.width + 3, 20, 0);
DisplayBitImage(Number + lst[ns_menu].hour / 10 * 6, &pic, 94 + pic.width * 0, 32, 0);
DisplayBitImage(Number + lst[ns_menu].hour % 10 * 6, &pic, 94 + pic.width * 1, 32, 0);
DisplayBitImage(Number + 11 * 6, &pic, 94 + pic.width * 2, 32, 0);
DisplayBitImage(Number + lst[ns_menu].min / 10 * 6, &pic, 94 + pic.width * 3, 32, 0);
DisplayBitImage(Number + lst[ns_menu].min % 10 * 6, &pic, 94 + pic.width * 4, 32, 0);
DisplayBitImage(Number + (ns_menu) * 6, &pic, 87, 20, 0);
//
/*定时设置
DisplayBitImage(jiadian + (lst[ns_menu].stat & 0x07) * 32 , &jd, 69 + pic.width * 0, 16, 0);
DisplayBitImage(stat + (lst[ns_menu].stat >>3) * 8 , &node, 69 + jd.width, 20, 0);
DisplayBitImage(Number + lst[ns_menu].hour / 10 * 6, &pic, 69 + pic.width * 0, 32, 0);
DisplayBitImage(Number + lst[ns_menu].hour % 10 * 6, &pic, 69 + pic.width * 1, 32, 0);
DisplayBitImage(Number + 11 * 6, &pic, 69 + pic.width * 2, 32, 0);
DisplayBitImage(Number + lst[ns_menu].min / 10 * 6, &pic, 69 + pic.width * 3, 32, 0);
DisplayBitImage(Number + lst[ns_menu].min % 10 * 6, &pic, 69 + pic.width * 4, 32, 0);
*/
// 按键逻辑 处于1级菜单状态
if(RetKey == KEYRIGHT)
{
++n_menu;
if ( n_menu == 25 )
{
n_menu = 1;
}
}
if(RetKey == KEYLEFT)
{
--n_menu; //状态菜单
if ( n_menu == 0 )
{
n_menu = 24;
}
}
//显示定时信息
// **********************************************************
if ( n_menu == 1)
{
uchar i = 0;
DisplayBitImage(arrow, &zmarrow, zmtimerlist.width + 7, 6, 0);
if (RetKey == KEYUP)
{
if( ns_menu == 0 ) ns_menu = TIMEMAX - 1;
else ns_menu--;
}
if (RetKey == KEYDOWN)
{
if( ns_menu == TIMEMAX - 1) ns_menu = 0;
else ns_menu++;
}
}
//家电开关选择
if( n_menu == 2)
{
//DisplayBitImage(stat + 8 * ((state & 0x08) >> 3), &node, 5 + jd.width, 20, 1);
if( RetKey == KEYUP) state |= 0x08;
if( RetKey == KEYDOWN) state &= ~0x08;
DisplayBitImage(arrow, &zmarrow,5 + jd.width + node.width + 1, 20 + 2, 0);
}
if( n_menu == 3)
{
//DisplayBitImage(stat + 8 * ((state & 0x04) >> 2), &node, 5 + jd.width * 2 + node.width + 5, 20, 1);
if( RetKey == KEYUP) state |= 0x04;
if( RetKey == KEYDOWN) state &= ~0x04;
DisplayBitImage(arrow, &zmarrow,5 + jd.width * 2 + node.width + 5 + node.width + 1, 20 + 2, 0);
}
if( n_menu == 4)
{
//DisplayBitImage(stat + 8 * ((state & 0x02) >> 1), &node, 5 + jd.width, 36, 1);
if( RetKey == KEYUP) state |= 0x02;
if( RetKey == KEYDOWN) state &= ~0x02;
DisplayBitImage(arrow, &zmarrow,5 + jd.width + node.width + 1, 36 + 2, 0);
}
if( n_menu == 5)
{
//DisplayBitImage(stat + 8 * ((state & 0x01) >> 0), &node, 5 + jd.width * 2 + node.width + 5, 36, 1);
if( RetKey == KEYUP) state |= 0x01;
if( RetKey == KEYDOWN) state &= ~0x01;
DisplayBitImage(arrow, &zmarrow, 5 + jd.width * 2 + node.width + 5 + node.width + 1, 36 + 2, 0);
}
//lsttmp.stat = lst[ns_menu].stat;
//lsttmp = lst[ns_menu];
//修改定时信息选择
if( n_menu == 6)
{
if (RetKey == KEYDOWN)
{
if ((lst[ns_menu].stat & 0x07) == 3) lst[ns_menu].stat &= (uchar)~0x07;
else lst[ns_menu].stat = lst[ns_menu].stat + 1;
}
if (RetKey == KEYUP)
{
if ((lst[ns_menu].stat & 0x07) == 0) lst[ns_menu].stat |= (uchar)0x03;
else lst[ns_menu].stat = lst[ns_menu].stat - 1;
}
//DisplayBitImage(jiadian + (lst[ns_menu].stat & 0x07) * 32 , &jd, 94 + pic.width * 0, 16, 0);
DisplayBitImage(arrow , &zmarrow, 94 + pic.width * 0 + jd.width, 20, 0);
}
if( n_menu == 7)
{
if( RetKey == KEYUP) lst[ns_menu].stat |= 0x08;
if( RetKey == KEYDOWN) lst[ns_menu].stat &= ~0x08;
DisplayBitImage(arrow , &zmarrow, 95 + jd.width + 12, 20, 0);
}
//修改定时信息时间选择
if( n_menu == 8 )
{
if( RetKey == KEYUP)
{
if( lst[ns_menu].hour / 10 == 2) lst[ns_menu].hour -= 20;
else lst[ns_menu].hour += 10;
}
if( RetKey == KEYDOWN)
{
if( lst[ns_menu].hour / 10 == 0 ) lst[ns_menu].hour += 20;
else lst[ns_menu].hour -= 10;
}
//lsttmp保存修改信息
DisplayBitImage(arrow + 5, &zmarrow, 94 + pic.width * 0, 41, 0);
}
if( n_menu == 9 )
{
if( RetKey == KEYUP)
{
if( lst[ns_menu].hour % 10 == 9) lst[ns_menu].hour -= 9;
else lst[ns_menu].hour += 1;
}
if( RetKey == KEYDOWN)
{
if( lst[ns_menu].hour % 10 == 0 ) lst[ns_menu].hour += 9;
else lst[ns_menu].hour -= 1;
}
DisplayBitImage(arrow + 5, &zmarrow, 94 + pic.width * 1, 41, 0);
}
if( n_menu == 10 )
{
if( RetKey == KEYUP)
{
if( lst[ns_menu].min / 10 == 5) lst[ns_menu].min -= 50;
else lst[ns_menu].min += 10;
}
if( RetKey == KEYDOWN)
{
if( lst[ns_menu].min / 10 == 0 ) lst[ns_menu].min += 50;
else lst[ns_menu].min -= 10;
}
DisplayBitImage(arrow + 5, &zmarrow, 94 + pic.width * 3, 41, 0);
}
if( n_menu == 11 )
{
if( RetKey == KEYUP)
{
if( lst[ns_menu].min % 10 == 9) lst[ns_menu].min -= 9;
else lst[ns_menu].min += 1;
}
if( RetKey == KEYDOWN)
{
if( lst[ns_menu].min % 10 == 0 ) lst[ns_menu].min += 9;
else lst[ns_menu].min -= 1;
}
DisplayBitImage(arrow + 5, &zmarrow, 94 + pic.width * 4, 41, 0);
}
//年选择
if( n_menu == 12 )
{
if (RetKey == KEYDOWN)
{
YEAR = YEAR - 1000;
}
if (RetKey == KEYUP)
{
YEAR = YEAR + 1000;
}
DisplayBitImage(arrow + 10, &zmarrow, 0, 48, 0);
}
if( n_menu == 13 )
{
if (RetKey == KEYDOWN)
{
YEAR = YEAR - 100;
}
if (RetKey == KEYUP)
{
YEAR = YEAR + 100;
}
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 1, 48, 0);
}
if( n_menu == 14 )
{
if (RetKey == KEYDOWN)
{
YEAR = YEAR - 10;
}
if (RetKey == KEYUP)
{
YEAR = YEAR + 10;
}
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 2, 48, 0);
}
if( n_menu == 15 )
{
if (RetKey == KEYDOWN)
{
YEAR = YEAR - 1;
}
if (RetKey == KEYUP)
{
YEAR = YEAR + 1;
}
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 3, 48, 0);
}
//月选择
if( n_menu == 16 )
{
if (RetKey == KEYDOWN)
{
MONTH = MONTH - 10;
}
if (RetKey == KEYUP)
{
MONTH = MONTH + 10;
}
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 5, 48, 0);
}
if( n_menu == 17 )
{
if (RetKey == KEYDOWN)
{
MONTH = MONTH - 1;
}
if (RetKey == KEYUP)
{
MONTH = MONTH + 1;
}
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 6, 48, 0);
}
//日选择
if( n_menu == 18 )
{
if (RetKey == KEYDOWN)
{
DOM = DOM - 10;
}
if (RetKey == KEYUP)
{
DOM = DOM + 10;
}
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 8, 48, 0);
}
if( n_menu == 19 )
{
if (RetKey == KEYDOWN)
{
DOM = DOM - 1;
}
if (RetKey == KEYUP)
{
DOM = DOM + 1;
}
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 9, 48, 0);
}
//小时选择
if( n_menu == 20 )
{
if (RetKey == KEYDOWN)
{
HOUR = HOUR - 10;
}
if (RetKey == KEYUP)
{
HOUR = HOUR + 10;
}
DisplayBitImage(arrow + 10,&zmarrow, menu.width * 2 + 5 + pic.width * 0, 48, 0);
}
if( n_menu == 21 )
{
if (RetKey == KEYDOWN)
{
HOUR = HOUR - 1;
}
if (RetKey == KEYUP)
{
HOUR = HOUR + 1;
}
DisplayBitImage(arrow + 10,&zmarrow, menu.width * 2 + 5 + pic.width * 1, 48, 0);
}
//分钟选择
if( n_menu == 22 )
{
if (RetKey == KEYDOWN)
{
MIN = MIN - 10;
}
if (RetKey == KEYUP)
{
MIN = MIN + 10;
}
DisplayBitImage(arrow + 10,&zmarrow, menu.width * 2 + 5 + pic.width * 3, 48, 0);
}
if( n_menu == 23 )
{
if (RetKey == KEYDOWN)
{
MIN = MIN - 1;
}
if (RetKey == KEYUP)
{
MIN = MIN + 1;
}
DisplayBitImage(arrow + 10,&zmarrow, menu.width * 2 + 5 + pic.width * 4, 48, 0);
}
//日期选择
if( n_menu == 24 )
{
if (RetKey == KEYDOWN)
{
DOW = DOW - 1;
}
if (RetKey == KEYUP)
{
DOW = DOW + 1;
}
DisplayBitImage(arrow + 10, &zmarrow, menu.width * 2 + 49 + xingqi.width * 1, 48, 0);
}
//页面动态重绘
if(RetKey !=0xff)
{
if( (RetKey == KEYUP || RetKey == KEYDOWN ) && n_menu >=6 & n_menu <= 11)
{
lst[ns_menu].stat |= 0xf0;
//更新上位机信息
}
if(RetKey != KEYUP || RetKey != KEYDOWN)
{
//DisplayBitImage(timerlist, &zmtimerlist, 0, 4, 0);
DisplayBitImage(0, &zmarrow, zmtimerlist.width + 7, 6, 3);
DisplayBitImage(0, &zmarrow,5 + jd.width + node.width + 1, 20 + 2, 3);
DisplayBitImage(0, &zmarrow,5 + jd.width * 2 + node.width + 5 + node.width + 1, 20 + 2, 3);
DisplayBitImage(0, &zmarrow,5 + jd.width + node.width + 1, 36 + 2, 3);
DisplayBitImage(0, &zmarrow, 5 + jd.width * 2 + node.width + 5 + node.width + 1, 36 + 2, 3);
//定时信息
DisplayBitImage(0 , &zmarrow, 94 + pic.width * 0 + jd.width, 20, 3);
DisplayBitImage(0 , &zmarrow, 95 + jd.width + 12, 20, 3);
DisplayBitImage(0, &zmarrow, 94 + pic.width * 0, 41, 3);
DisplayBitImage(0, &zmarrow, 94 + pic.width * 1, 41, 3);
DisplayBitImage(0, &zmarrow, 94 + pic.width * 3, 41, 3);
DisplayBitImage(0, &zmarrow, 94 + pic.width * 4, 41, 3);
//日期箭头
DisplayBitImage(arrow + 10, &zmarrow, 0, 48, 3);
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 1, 48, 3);
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 2, 48, 3);
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 3, 48, 3);
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 5, 48, 3);
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 6, 48, 3);
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 8, 48, 3);
DisplayBitImage(arrow + 10, &zmarrow, pic.width * 9, 48, 3);
//DisplayBitImage(zhou + DOW * 10, &xingqi, menu.width * 2 + 47 + xingqi.width * 1, 56, 0);
//时间箭头
DisplayBitImage(arrow + 10,&zmarrow, menu.width * 2 + 5 + pic.width * 0, 48, 3);
DisplayBitImage(arrow + 10,&zmarrow, menu.width * 2 + 5 + pic.width * 1, 48, 3);
// DisplayBitImage(Number + 11 * 6, &pic, menu.width * 2 + 5 + pic.width * 2, 4, 0);
DisplayBitImage(arrow + 10,&zmarrow, menu.width * 2 + 5 + pic.width * 3, 48, 3);
DisplayBitImage(arrow + 10, &zmarrow, menu.width * 2 + 5 + pic.width * 4, 48, 3);
// DisplayBitImage(Number + 11 * 6, &pic, menu.width * 2 + 5 + pic.width * 5, 4, 0);
DisplayBitImage(arrow + 10, &zmarrow, menu.width * 2 + 5 + pic.width * 6, 48, 3);
DisplayBitImage(arrow + 10, &zmarrow, menu.width * 2 + 5 + pic.width * 7, 48, 3);
//星期箭头
DisplayBitImage(arrow + 10, &zmarrow, menu.width * 2 + 49 + xingqi.width * 1, 48, 3);
//定时信息重绘
//电视
// DisplayBitImage(jiadian, &jd, 5, 16, 0);
DisplayBitImage(stat + 8 * ((state & 0x08) >> 3), &node, 5 + jd.width, 20, 0);
//冰箱
// DisplayBitImage(jiadian + 32 * 1, &jd, 5 + jd.width + node.width + 5 , 16, 0);
DisplayBitImage(stat + 8 * ((state & 0x04) >> 2), &node, 5 + jd.width * 2 + node.width + 5, 20, 0);
//热水器
// DisplayBitImage(jiadian + 32 * 2, &jd, 5, 32, 0);
DisplayBitImage(stat + 8 * ((state & 0x02) >> 1), &node, 5 + jd.width, 36, 0);
//灯
// DisplayBitImage(jiadian + 32 * 3, &jd, 5 + jd.width + node.width + 5 , 32, 0);
DisplayBitImage(stat + 8 * ((state & 0x01) >> 0), &node, 5 + jd.width * 2 + node.width + 5, 36, 0);
Update();
}
//if(RetKey != KEYLEFT || RetKey != KEYRIGHT)
//vCleanAll(WHITE);
//电视状态显示
}
//min = 0;
for(i = 1; i != 10; ++i)
{
if( ((lst[i].stat & 0xf0) == 0xf0) && (HOUR * 60 + MIN) < (lst[i].hour * 60 + lst[i].min) )
{
if( (lst[minium].hour * 60 + lst[minium].min) > (lst[i].hour * 60 + lst[i].min))
{
minium = i;
}
}
}
//LED指示
for(i = 0; i !=4; ++i)
{
if((state & (1 << (3 - i))) >> (3 - i) )LED_Ctl(i + 1, 1);
else LED_Ctl(i + 1, 0);
}
//设置定时
set_alarm(&lst[minium]);
adc();
}
}
void Int0Init( int (*func)(void), int intType )
{
VICIntSelect |= 0 << intType; // 对应所有中断为irq中断
VICVectCntl0 = (0x20 | intType); //设置优先级0的中断源,并使能中断
VICVectAddr0 = (int)func; //将中断服务例程的地址写入对应优先级的寄存器中
VICIntEnable = (1 << intType); //使能中断源
}
void Int1Init( int (*func)(void), int intType )
{
VICIntSelect |= 0 << intType; // 对应所有中断为irq中断
VICVectCntl1 = (0x20 | intType); //设置优先级0的中断源,并使能中断
VICVectAddr1 = (int)func; //将中断服务例程的地址写入对应优先级的寄存器中
VICIntEnable = (1 << intType); //使能中断源
}
void Int2Init( int (*func)(void), int intType )
{
VICIntSelect |= 0 << intType; // 对应所有中断为irq中断
VICVectCntl2 = (0x20 | intType); //设置优先级0的中断源,并使能中断
VICVectAddr2 = (int)func; //将中断服务例程的地址写入对应优先级的寄存器中
VICIntEnable = (1 << intType); //使能中断源
}
void InitLCD( void )
{
WriteCmd(0x3e);
WriteCmd(0x3f);
WriteCmd(0xc0);
}
// 忙闲检测 仿真环境需要更高的延迟, 实际开发板执行时间都在微妙级 需要实时检测
void vCheckBusy(void)
{
IODIR &= 0xF9FFFF03; //数据线为输入
while(1)
{
IOCLR=LCD12864_RS;
IOSET=LCD12864_RW;
//LCD12864_SET=0x00FF0000;
IOSET=LCD12864_EN;
IOCLR=LCD12864_EN;
if(!(IOPIN & LCD12864_BUSY))
break;
}
IODIR |= 0x060000FC; //数据线为输出*/
}
//uart通信函数
void UART0Init( void )
{
uchar Fdiv;
Fdiv = Fpclk / ( 16 * UART_BPS);
U0LCR = 0x83;
U0DLM = Fdiv/256;
U0DLL = Fdiv%256;
U0LCR = 0x03;
U0IER = 0x01; //允许UART1的RBR接收中断
U0FCR = 0x81;
}
void UART0_SendByte(uchar data)
{
while( (U0LSR & 0x20) == 0);
U0THR = data;
}
uchar UART0_RcvByte( void )
{
uchar rcv_data;
while( (U0LSR & 0x01) == 0 );
rcv_data = U0RBR;
return rcv_data;
}
void UART0_SendString( char* String)
{
do{
UART0_SendByte( *String++ );
}while(*String != '\n');
}
//键盘函数
char KeyDown( void )
{
IODIR &= ~(KC0 | KC1);
IOCLR |= KH0 + KH1 ; //行线置低, 读取列线状态
if( (IOPIN & KC0) == 0 || (IOPIN & KC1) == 0)
{
DelayNS(20); //消除机械抖动
if( (IOPIN & KC0) == 0 || (IOPIN & KC1) == 0)
{
return 1;
}
}
return 0;
}
char KeyNum( void )
{
if( 1 == KeyDown())
{
IOCLR |= KH0;
IOSET |= KH1;
if( (IOPIN & KC0) == 0 )
{
return 1;
}
if( (IOPIN & KC1) == 0 )
{
return 2;
}
IOCLR |= KH1;
IOSET |= KH0;
if( (IOPIN & KC0) == 0 )
{
return 3;
}
if( (IOPIN & KC1) == 0 )
{
return 4;
}
}
else
return 0xff;
}
void WriteCmd(uchar cmd)
{
vCheckBusy();
IOCLR |= LCD12864_RW;
IOCLR |= LCD12864_RS;
IOSET |= LCD12864_EN;
IOCLR |= LCD12864_DATABUS;
IOSET |= ((cmd & 0x3f) << 2 | (cmd & 0xc0) << 19); //输入命令 tdsw = 200ns 数据建立时间;
IOCLR |= LCD12864_EN;
}
void WriteData(uchar data)
{
vCheckBusy();
IOCLR |= LCD12864_RW;
IOSET |= LCD12864_RS;
IOSET |= LCD12864_EN;
IOCLR |= LCD12864_DATABUS;
IOSET |= ((data & 0x3f) << 2 | (data & 0xc0) << 19);
IOCLR |= LCD12864_EN;
}
// 功能函数
void vCleanAll(int opt)
{
uchar ucPage,ucLine,nLoop;
IOSET = LCD12864_LEFT;
IOSET = LCD12864_RIGHT;
for(ucPage=0;ucPage<8;ucPage++)
{
for(ucLine=0;ucLine<16;ucLine++)
{
if(ucLine<8)
{
IOSET = LCD12864_LEFT;
IOCLR = LCD12864_RIGHT;
}
else
{
IOCLR = LCD12864_LEFT;
IOSET = LCD12864_RIGHT;
}
WriteCmd(ucPage+0xb8);//页坐标
WriteCmd((ucLine<8?ucLine:ucLine-8)*8+0x40); //列坐标
for(nLoop=0;nLoop<8;nLoop++)
{
if( opt == 3 )
WriteData(0);
if( opt == 2 )
WriteData(0xff);
}
}
}
}
void DisplayBitImage(const uchar* img, Pic *pic, int x, int y, int opt)
{
int i =0 , j=0, row=0;
int offset; // y相对于每一页的偏移量
int startPage; // 取整的起始页数
uchar tmp = 0x00; // 处理每一个结点
startPage = y / 8; // y向下取整
offset = y % 8 ; // 偏移量
if( pic->height % 8 == 0)
{
row = pic->height / 8;
}
else
{
row = pic->height / 8 + 1;
}
//row = (pic->height % 8 == 0 ? pic->height / 8 : pic->height / 8 + 1);
if(offset) row = row + 1;
for(j = 0; j < row; j++)
{
for(i = 0; i < pic->width; i++)
{
if ( (i + x) <= 63 )
{
IOSET |= LCD12864_RIGHT;
IOCLR |= LCD12864_LEFT;
WriteCmd(SET_PAGE + startPage + j);
tmp = *(img + i + j * pic->width);
if( offset )
{
if(0 == j) tmp = tmp << offset;
else if( (row - 1) == j ) tmp = (*(img + i + (j - 1) * pic->width)) >> (8 - offset);
else tmp = (*(img + i + (j - 1) * pic->width) >> (8 - offset)) + (uchar)(tmp << offset);
}
WriteCmd(SET_COW + x + i );
if(opt == 1)
WriteData(~tmp);
if(opt == 0)
WriteData(tmp);
if(opt == 2)
WriteData(0xff);
if(opt == 3)
WriteData(0);
}
else
{
IOCLR |= LCD12864_RIGHT;
IOSET |= LCD12864_LEFT;
WriteCmd(SET_PAGE + startPage + j);
tmp = *(img + i + j * pic->width);
if( offset )
{
if(0 == j) tmp = tmp << offset;
else if( (row - 1) == j ) tmp = (*(img + i + (j - 1) * pic->width)) >> (8 - offset);
else tmp = (*(img + i + (j - 1) * pic->width) >> (8 - offset)) + (uchar)(tmp << offset);
}
WriteCmd(SET_COW + x + i - 64);
if(opt == 1)
WriteData(~tmp);
if(opt == 0)
WriteData(tmp);
if(opt == 2)
WriteData(0xff);
if(opt == 3)
WriteData(0);
}
}
}
}
void DelayNS(uint nDly)
{
uint nLoop;
for(; nDly>0; nDly--)
for(nLoop=0; nLoop<50000; nLoop++);
}
//时钟定时相关函数
void RTCIni(void)
{
PREINT = Fpclk / 32768 - 1;
PREFRAC = Fpclk - (Fpclk/32768) * 32768;
YEAR = 2012;
MONTH = 2;
DOM = 19;
DOW = 4;
HOUR = 8;
MIN = 36;
SEC = 0;
//CIIR = 0x01;
CIIR = 0x02; // 设置分值增量中断
AMR = 0xF8; // 设置报警屏蔽寄存器
CCR = 0x01;
}
void set_time(TIME *time)
{
CCR = 0x00; // 第0位为1 使能时间计数器 为0 禁止 可对其初始化
YEAR = time->year;
MONTH = time->mon;
DOM = time->dom;
DOW = time->day;
HOUR = time->hour;
MIN = time->min;
SEC = time->sec;
CCR = 0x01;
}
void set_alarm(ALARM *alm)
{
ILR = 0x03; // 清除RTC中断标志
ALHOUR = alm->hour; // 设置小时比较值
ALMIN = alm->min; // 设置分比较值
ALSEC = 0; // 设置秒比价值
// 只允许时、分、秒比较
}
void TimerInit(void)
{
T0PR=0; //设置定时器分频为100分频
T0MCR=0x03; //匹配通道0匹配中断并复位T0TC
T0MR0=Fpclk/100; //1s
T0TCR=0x03; //启动并复位T0TC
T0TCR=0x01; //Timer0 Enable
/*设置定时器0中断IRQ*/
// VICIntSelect=0x00; //所有中断通道设置为IRQ中断
// VICVectCntl0=0x24; //定时器0中断通道分配最高优先级(向量控制器0)
// VICVectAddr0=(uint32)tc0; //设置中断服务程序地址向量
// VICIntEnable=0x00000010; //使能定时器0中断
}