/**************ARM7(LPC2103)练习程序**************************/
/*************************************************************/
/*****File Function : lcd10265液晶显示程序 *****/
/*****Program Author : ZhengWen(ClimberWin) *****/
/*****MCU : LPC2103F 外部11.0592M晶振 *****/
/*****Compile Date : 2010/01/13 *****/
/*****Edition Info : V1.0 *****/
/*************************************************************/
//编译环境 KEIL for ARM
//修改时间2010年2月9日,能够串口输出数据,接收数据,并且LCD上显示
/*************************************************************/
//修改时间2010年2月10日
//修改内容:一直串口和LCD显示不能同时用,后来发现是设置好PLL后由于时序太快,导致液晶不能显示
// 调整好时序后液晶可以正常显示。
//LCD GUI移植成功,还需要移植按键
//#include
//#include
#include "RCU6093.h"
#include "win_delay.h"
#include "GPS_GH_80.h"
#define uchar unsigned char
#define uint unsigned int
#define baudrate 9600 //设置波特率
#define PE (U0LSR&0x40) //定义串口数据发送忙碌与否,PE=1忙碌;PE=0;不忙绿
#define Fosc (11059200) //晶振频率,10MHz~25MHz,应当与实际一至
#define Fcclk (Fosc * 6) //66.3552 系统频率,必须为Fosc的整数倍(1~32),且<=60MHZ
#define Fcco (Fcclk * 4) //CCO频率,必须为Fcclk的2、4、8、16倍,范围为156MHz~320MHz
#define Fpclk (Fcclk / 4) * 1 //016.5888,VPB时钟频率,只能为(Fcclk / 4)的1 ~ 4倍
//常量定义
uchar lcd_y_num=0;//液晶显示Y轴坐标
uchar temp_h;
uchar temp_l;
uchar stop=0;
uchar UART_MID; //定义一个缓存区数据临时存储地址
uchar numh=0;
uchar numl=0;
uchar flag=0;
uchar temp1;
uchar da
uchar da
uchar key1_flag; //定义按键标志位
uchar key2_flag;
uchar key3_flag;
uchar gps_flag;//定义是否有GPS数据
//////////////////////////////////////////////////////////////
void LCD_PORT_INI(void);
void LCD_write_LCD(unsigned char da
void LCD_RCU6093_Clear(void);
void LCD_RCU6093_tset(void);
void LCD_RCU6093_int(void);
void init_USART(void);//USART 初始化
void write_asicc(uchar assi);
void LCD_xy(uchar x,uchar y);
void write_hanzi(uchar hz);
void write_hanzi16(uchar hz,uchar x,uchar y,uchar mirror);
void PLL_Init(void);
void UART0_INT(void); //串口初始化
void UART0_SendByte(unsigned char da
void UART0_SendStr(unsigned char const *str);//串口发送字符串
void keytest(void); //按键测试程序
void Charge(void);//电池充电子程序
void Signal_strength(void);//信号强度指示程序
void banbenxinxi(void);//显示版本信息
void GPS_display(void);
/**********************************************/
void keytest(void) //按键测试程序
{
}
////////////充电状态////////////////////
void Charge(void)
{
uchar i;
LCD_xy(94,1);//LCD指针坐标
write_hanzi(19);//
for(i=0;i<6;i++)
{ LCD_xy(94,0);//LCD指针坐标
write_hanzi(13+i);//
delayms(60000);
delayms(60000);
delayms(60000);
}
}
///////////信号强度状态//////////////////
void Signal_strength(void)
{
uchar i;
LCD_xy(0,1);//LCD指针坐标
write_hanzi(20);//
for(i=0;i<4;i++)
{ LCD_xy(0,0);//LCD指针坐标
write_hanzi(21+i);//
delayms(60000);
delayms(60000);
delayms(60000);
}
}
///////////////////////////////
/////////////////////////////////
void banbenxinxi(void)
{
LCD_RCU6093_int(); //初始化液晶
LCD_xy(0,2);//LCD指针坐标
write_asicc('G');
write_asicc('P');
write_asicc('S');
write_asicc(0);
write_asicc('V');
write_asicc('1');
write_asicc('.');
write_asicc('2');
LCD_xy(0,3);//LCD指针坐标
write_asicc('C');
write_asicc('P');
write_asicc('U');
write_asicc(':');
write_asicc('A');
write_asicc('R');
write_asicc('M');
write_asicc('7');
write_asicc('T');
write_asicc('D');
write_asicc('M');
write_asicc('I');
LCD_xy(0,4);//LCD指针坐标
write_asicc('B');
write_asicc('Y');
write_asicc(0);
write_asicc('C');
write_asicc('L');
write_asicc('I');
write_asicc('M');
write_asicc('B');
write_asicc('E');
write_asicc('R');
write_asicc('W');
write_asicc('I');
write_asicc('N');
LCD_xy(0,5);//LCD指针坐标
write_asicc('2');
write_asicc('0');
write_asicc('1');
write_asicc('0');
write_hanzi(4);//年
write_asicc('0');
write_asicc('2');
write_hanzi(5);//月
write_asicc('1');
write_asicc('0');
write_hanzi(6);//日
LCD_xy(72,7);//LCD指针坐标
write_asicc('B');
write_asicc('A');
write_asicc('C');
write_asicc('K');
//////////显示手持式导航仪/////////////////
write_hanzi16(4,4,0,0);
write_hanzi16(5,1*16+4,0,0);
write_hanzi16(6,2*16+4,0,0);
write_hanzi16(7,3*16+4,0,0);
write_hanzi16(8,4*16+4,0,0);
write_hanzi16(9,5*16+4,0,0);
}
void PLL_Init(void)
{
/* 设置系统各部分时钟 */
PLLCON = 1;
#if ((Fcclk / 4) / Fpclk) == 1
VPBDIV = 0;
#endif
#if ((Fcclk / 4) / Fpclk) == 2
VPBDIV = 2;
#endif
#if ((Fcclk / 4) / Fpclk) == 4
VPBDIV = 1;
#endif
#if (Fcco / Fcclk) == 2
PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5);
#endif
#if (Fcco / Fcclk) == 4
PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5);
#endif
#if (Fcco / Fcclk) == 8
PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5);
#endif
#if (Fcco / Fcclk) == 16
PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);
#endif
PLLFEED = 0xaa;
PLLFEED = 0x55;
while((PLLSTAT & (1 << 10)) == 0);
PLLCON = 3;
PLLFEED = 0xaa;
PLLFEED = 0x55;
}
/***********串口0初始化**********************/
void UART0_INT(void)
{ unsigned int U0DL;
U0LCR = 0x83; // DLAB = 1,可设置波特率 ;无奇偶校验 1位停止位 8位数据长度。
U0DL = (Fpclk/16)/baudrate;
U0DLM= U0DL/256; //高8位
U0DLL = U0DL%256; //低8位
U0LCR = 0x03; // DLAB = 0,设置好波特率;无奇偶校验 1位停止位 8位数据长度。
}
/***********串口发送字节**********************/
void UART0_SendByte(unsigned char da
{
U0THR = da
while( PE==0 ); //等待数据发送完毕 PE=1忙碌;PE=0;不忙绿
}
/***********串口发送字符串**********************/
void UART0_SendStr(unsigned char const *str)
{ while(1)
{ if( *str == '\0' ) break;
UART0_SendByte(*str++); //发送数据
}
}
/*************串口接收字符*************************/
unsigned char UART0_GetChar(void)
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void __irq UART0_IRQ (void)
{
}
//////////////////////////////////////////////////////////////
void LCD_PORT_INI(void)
{
IO0DIR|=0x0000ff00; //配置P0.8-P1.5为输出
}
//////////////////////////////////////////////////////////////
void LCD_write_LCD(unsigned char da
{
unsigned char i=0;
LCD_CS_L();
if(cmd)LCD_A0_H();
else LCD_A0_L();
for (i=0;i<8;i++)
{
LCD_SCL_L();
if (da
da
LCD_SCL_H();
}
LCD_CS_H();
//delayms(1);
}
////////////////////////////////////////////////////////////
void LCD_RCU6093_Clear(void)
{
unsigned int i=0;
for ( i = 0 ; i < 918 ; i++ )
{
LCD_write_LCD(0x00,1);
}
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
void LCD_RCU6093_int(void)
{
LCD_PORT_INI();
LCD_RST_L();
LCD_CS_H();
LCD_A0_H();
LCD_SCL_H();
LCD_SD_H();
delayms(1);
LCD_RST_H();
LCD_write_LCD(0x21,0);//写Extend 指令 (H=1)
LCD_write_LCD(0xb0,0); //对比度调节
LCD_write_LCD(0x14,0);//LCD Duty设置
LCD_write_LCD(0x20,0);//写Basic 指令(H=0)
LCD_write_LCD(0x0c,0);//画面显示模式 0x08全白 0x09全黑 0x0c正常模式 0x0d反转显示模式
LCD_RCU6093_Clear();
}
///////////////////写asicc码//////////////////////////////////
void write_asicc(uchar assi)
{
uchar i;
for(i=0;i<8;i++)
{LCD_write_LCD( asicc[assi][i],1);}
//{LCD_write_LCD(32+i,1);}
}
///////////////////写8*8简单汉字//////////////////////////////////
void write_hanzi(uchar hz)
{
uchar i;
for(i=0;i<8;i++)
{LCD_write_LCD( hanzi1[hz][i],1);}
}
///////////////////写16*16简单汉字//////////////////////////////////
void write_hanzi16(uchar hz,uchar x,uchar y,uchar mirror)
{
uchar i;
LCD_write_LCD(0x80+x,0);//X轴地址
LCD_write_LCD(0x40+y,0);//Y轴地址
for(i=0;i<8;i++)
if(mirror==0)
{LCD_write_LCD(hanzi16[4*hz][i],1);}
else
{LCD_write_LCD(~hanzi16[4*hz][i],1);}
for(i=0;i<8;i++)
if(mirror==0)
{LCD_write_LCD(hanzi16[4*hz+1][i],1);}
else
{LCD_write_LCD(~hanzi16[4*hz+1][i],1);}
LCD_write_LCD(0x80+x,0);//X轴地址
LCD_write_LCD(0x40+y+1,0);//Y轴地址
for(i=0;i<8;i++)
if(mirror==0)
{LCD_write_LCD(hanzi16[4*hz+2][i],1);}
else
{LCD_write_LCD(~hanzi16[4*hz+2][i],1);}
for(i=0;i<8;i++)
if(mirror==0)
{LCD_write_LCD(hanzi16[4*hz+3][i],1);}
else
{LCD_write_LCD(~hanzi16[4*hz+3][i],1);}
}
//////////////LCD指针坐标//////////////////////
void LCD_xy(uchar x,uchar y)
{
LCD_write_LCD(0x80+x,0);//X轴地址
LCD_write_LCD(0x40+y,0);//Y轴地址
}
//////////////////////////////////////////////////////////////
void GPS_display(void)
{
unsigned char i,j,n,m;
unsigned char hh,hl,mh,ml,sh,sl;
unsigned char temp_time;
LCD_xy(16,0);//LCD指针坐标
write_hanzi(7); //小
write_hanzi(8);//文
write_hanzi(0); //电
write_hanzi(11);//子
write_asicc(0);//空白
write_asicc('G');
write_asicc('P');
write_asicc('S');
if(flag==2 && da
{
//cli();
da
da
LCD_xy(0,1);//LCD指针坐标
write_asicc('2');
write_asicc('0');
GPS_date_time();//获取GPS时间
if((GPS_date_year/10)==0 && (GPS_date_year%10)==4)
{
write_asicc(GPS_date_year/10+0x30);
write_asicc(GPS_date_year%10+0x30+5);
}
else
{
write_asicc(GPS_date_year/10+0x30);
write_asicc(GPS_date_year%10+0x30);
}
write_hanzi(4);//年
write_asicc(GPS_date_month/10+0x30);
write_asicc(GPS_date_month%10+0x30);
write_hanzi(5);//月
write_asicc(GPS_date_day/10+0x30);
write_asicc(GPS_date_day%10+0x30);
write_hanzi(6);//日
LCD_xy(0,2);//LCD指针坐标
write_hanzi(2);//时
write_hanzi(3);//间
write_asicc(':');
write_asicc((GPS_time_hour+8)/10+0x30);
write_asicc((GPS_time_hour+8)%10+0x30);
write_asicc(':');
write_asicc(GPS_time_minute/10+0x30);
write_asicc(GPS_time_minute%10+0x30);
write_asicc(':');
write_asicc(GPS_time_second/10+0x30);
write_asicc(GPS_time_second%10+0x30);
///////////////////////////////////////////////
//////////卫星数量///////////
LCD_xy(0,7);//LCD指针坐标
write_asicc('S');
write_asicc('A');
write_asicc('T');
write_asicc('E');
write_asicc('L');
write_asicc('L');
write_asicc('I');
write_asicc('T');
write_asicc('E');
write_asicc(':');
if(E0_temp[21]>=0 && E0_temp[21]<=12){write_asicc(E0_temp[21]/10+0x30);write_asicc(E0_temp[21]%10+0x30); }
//////////////////////////////
////////海拔//////////////
LCD_xy(0,6);//LCD指针坐标
write_asicc('H');
write_asicc('I');
write_asicc('G');
write_asicc('H');
write_asicc(':');
Altitude_change();
// write_asicc(GPS_E0_temp[12]/10+0x30); //高3位不显示
// write_asicc(GPS_E0_temp[12]%10+0x30);
// write_asicc(GPS_E0_temp[13]/10+0x30);
if(GPS_Altitude<9000)
{
write_asicc( GPS_Altitude/1000+0x30);
write_asicc((GPS_Altitude%1000)/100+0x30);
write_asicc(((GPS_Altitude%1000)%100/10)+0x30);
write_asicc('.');
write_asicc(((GPS_Altitude%1000)%100%10)/10+0x30);
write_asicc('M');
flag=0;
}
else
{;}
//////////////////速度///////////////////
LCD_xy(1,5);//LCD指针坐标
write_asicc('S');
write_asicc('P');
write_asicc('E');
write_asicc('E');
write_asicc('D');
write_asicc(':');
Speed_change();
if(GPS_speed<9000)
{
write_asicc( GPS_speed/1000+0x30);
write_asicc((GPS_speed%1000)/100+0x30);
write_asicc(((GPS_speed%1000)%100/10)+0x30);
write_asicc('.');
write_asicc(((GPS_speed%1000)%100%10)/10+0x30);
}
else
{
write_asicc('0');
}
////////////////////经纬度///////////////////////////
LCD_xy(0,3);//LCD指针坐标
Coordinates_change(1);
write_asicc('N');
//////////////2009.12.29修改/////
if(GPS_degree!=34 && GPS_minute!=44)
{
/////////////////////////////////
if(GPS_degree>100){write_asicc(GPS_degree/100+0x30);write_asicc((GPS_degree%100)/10+0x30);write_asicc((GPS_degree%100)%10+0x30); write_asicc(23);}
if(GPS_degree<100){write_asicc(GPS_degree/10+0x30);write_asicc(GPS_degree%10+0x30);write_asicc(23);}
if(GPS_minute>100){write_asicc(GPS_minute/100+0x30);write_asicc((GPS_minute%100)/10+0x30);write_asicc((GPS_minute%100)%10+0x30); write_asicc(27);}
if(GPS_minute<100){write_asicc(GPS_minute/10+0x30);write_asicc(GPS_minute%10+0x30);write_asicc(27);}
if(GPS_second>100){write_asicc(GPS_second/100+0x30);write_asicc((GPS_second%100)/10+0x30);write_asicc((GPS_second%100)%10+0x30);}
if(GPS_second<100){write_asicc(GPS_second/10+0x30);write_asicc(GPS_second%10+0x30);}
if(GPS_last>100){write_asicc(GPS_last/100+0x30);write_asicc((GPS_last%100)/10+0x30);write_asicc((GPS_last%100)%10+0x30);}
if(GPS_last<100){write_asicc(GPS_last/10+0x30);write_asicc(GPS_last%10+0x30);}
}
else
{
write_asicc('0');write_asicc('0');write_asicc(23);write_asicc('0');write_asicc('0');write_asicc(27);write_asicc('0');write_asicc('0');write_asicc('0');write_asicc('0');write_asicc('0');
}
Coordinates_change(2);
LCD_xy(0,4);//LCD指针坐标
write_asicc('E');
if(GPS_degree!=135 && GPS_minute!=21)
{
if(GPS_degree>100){write_asicc(GPS_degree/100+0x30);write_asicc((GPS_degree%100)/10+0x30);write_asicc((GPS_degree%100)%10+0x30); write_asicc(23);}
if(GPS_degree<100){write_asicc(GPS_degree/10+0x30);write_asicc(GPS_degree%10+0x30);write_asicc(23);}
if(GPS_minute>100){write_asicc(GPS_minute/100+0x30);write_asicc((GPS_minute%100)/10+0x30);write_asicc((GPS_minute%100)%10+0x30); write_asicc(27);}
if(GPS_minute<100){write_asicc(GPS_minute/10+0x30);write_asicc(GPS_minute%10+0x30);write_asicc(27);}
if(GPS_second>100){write_asicc(GPS_second/100+0x30);write_asicc((GPS_second%100)/10+0x30);write_asicc((GPS_second%100)%10+0x30);}
if(GPS_second<100){write_asicc(GPS_second/10+0x30);write_asicc(GPS_second%10+0x30);}
if(GPS_last>100){write_asicc(GPS_last/100+0x30);write_asicc((GPS_last%100)/10+0x30);write_asicc((GPS_last%100)%10+0x30);}
if(GPS_last<100){write_asicc(GPS_last/10+0x30);write_asicc(GPS_last%10+0x30);}
}
else
{
write_asicc('0');write_asicc('0');write_asicc(23);write_asicc('0');write_asicc('0');write_asicc(27);write_asicc('0');write_asicc('0');write_asicc('0');write_asicc('0');write_asicc('0');
}
flag=0;
// sei();
}
else
{;}
}
////////////主程序/////////////////////
int main(void)
{
unsigned char i,j,n,m;
uchar uart_temp;
uchar mode_flag;//模式标志位,用来切换界面
uchar tubiao1,tubiao2,tubiao3,tubiao4;//定义首界面图标
tubiao1=0x00;
tubiao2=0x00;
tubiao3=0x00;
tubiao4=0x00;
mode_flag=0x01;//模式标志位flag=0x00开机界面flag=0x01初始界面;flag=0x02日历界面;flag=0x03工具界面;
//flag=0x04导航界面;flag=0x05文件夹界面
delayms(50000);
flag=0;
gps_flag=0;//初始化
PLL_Init();//系统时钟配置,必须设置
PINSEL0 |= 0x00000005; //设置I/O连接到UART0
PINSEL1 |= 0x00000000;
UART0_INT(); //串口初始化
UART0_SendStr("LPC2103 UART0 Test OK!"); //向串口发送字符串
delayms(60000);
LCD_RCU6093_int(); //初始化液晶
LCD_xy(0,0);//LCD指针坐标
mode_flag=0x05;
while(1)
{
key1_flag=0x00;
key2_flag=0x00;
key3_flag=0x00;
LCD_RCU6093_int(); //初始化液晶
LCD_xy(0,0);//LCD指针坐标
da
da
///////////显示电池和信号强度////////////
LCD_xy(94,1);//LCD指针坐标
write_hanzi(19);//
LCD_xy(94,0);//LCD指针坐标
write_hanzi(17);//
LCD_xy(0,1);//LCD指针坐标
write_hanzi(20);//
LCD_xy(0,0);//LCD指针坐标
write_hanzi(24);//
////////////////////////////
LCD_xy(16,0);//LCD指针坐标
write_hanzi(7); //小
write_hanzi(8);// 文
write_hanzi(0); //电
write_hanzi(11);//子
write_asicc(0);//空白
write_asicc(0);//空白
write_asicc('G');
write_asicc('P');
write_asicc('S');
LCD_xy(0,7);//LCD指针坐标
write_asicc('O');
write_asicc('K');
LCD_xy(72,7);//LCD指针坐标
write_asicc('B');
write_asicc('A');
write_asicc('C');
write_asicc('K');
while(mode_flag==0x01)
{
//cli();
///////图标//////////////////////
write_hanzi16(0,2,3,tubiao1);
write_hanzi16(1,2*14+2,3,tubiao2);
write_hanzi16(2,4*14+2,3,tubiao3);
write_hanzi16(3,6*14+2,3,tubiao4);
//////////显示手持式导航仪/////////////////
write_hanzi16(4,4,5,0);
write_hanzi16(5,1*16+4,5,0);
write_hanzi16(6,2*16+4,5,0);
write_hanzi16(7,3*16+4,5,0);
write_hanzi16(8,4*16+4,5,0);
write_hanzi16(9,5*16+4,5,0);
keytest();
if( key1_flag==0){tubiao1=0;tubiao2=0;tubiao3=0;tubiao4=0;key2_flag=0;}
if( key1_flag==1){tubiao1=1;tubiao2=0;tubiao3=0;tubiao4=0;key2_flag=0;}
if( key1_flag==2){tubiao1=0;tubiao2=1;tubiao3=0;tubiao4=0;key2_flag=0;}
if( key1_flag==3){tubiao1=0;tubiao2=0;tubiao3=1;tubiao4=0;}
if( key1_flag==4){tubiao1=0;tubiao2=0;tubiao3=0;tubiao4=1;}
if( key1_flag==5){key1_flag=0;}
if( key1_flag==3 &&key2_flag==1){key2_flag=0;mode_flag=0x04;}
if( key1_flag==4 &&key2_flag==1){key2_flag=0;mode_flag=0x05;}
}
///////////////////////////////////////////////////////////////
while(mode_flag==0x04)
{
UART0_INT(); //串口初始化
//sei(); //中断使能(avr/interrupt.h 中调用)
LCD_RCU6093_Clear();
key3_flag=0;
gps_flag=0;
break;
}
while(mode_flag==0x04)
{
while(gps_flag==0)//如果GPS没收到指令就一直发送09.12.29
{
U0THR=0xc0;
delayms(10000);
U0THR=0xa3;
delayms(10000);
U0THR=0x8f;
delayms(10000);
U0THR=0xec;
delayms(10000);
U0THR=0xca;
delayms(50000);
LCD_xy(24,3);//LCD指针坐标
write_asicc('N');
write_asicc('O');
write_asicc(0);
write_asicc('G');
write_asicc('P');
write_asicc('S');
keytest();
if( key3_flag==1){key3_flag=0;mode_flag=0x01;break;}
}
while(1)
{
GPS_display();
keytest();
if( key3_flag==1){key3_flag=0;mode_flag=0x01;break;}
}
}
while(mode_flag==0x05)
{
banbenxinxi();
key3_flag=0;
break;
}
while(mode_flag==0x05)
{
keytest();
if( key3_flag==1){key3_flag=0;mode_flag=0x01;break;}
}
}
}
上一篇:ARM7学习---GPIO笔记
下一篇:ARM7学习---UART0练习
推荐阅读最新更新时间:2024-03-16 15:08