1、系统配置。
2、源代码。
|
文件: |
毕业设计源代码.rar |
大小: |
9KB |
下载: |
下载 | |
includes.h文件
#ifndef INCLUDES_H_
#define INCLUDES_H_
#define SYS_TICK 50000000
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "altera_avalon_uart_regs.h"
#include "altera_avalon_timer_regs.h"
#include "sys/alt_irq.h"
#include "alt_types.h"
#include "stdio.h"
#include "unistd.h"
#include
#include
#include
#include
#include "lcd.h"
#include "uart.h"
#include "led.h"
#include "key.h"
#include "timer.h"
#include "sys/alt_flash.h"
//#define uart_2
#define uart_3
//#include "hello_world.h"
//#include "gprs.h"
#endif /*INCLUDES_H_*/
lcd.h文件
#ifndef LCD_H_
#define LCD_H_
extern void lcd_write_cmd(alt_u16,alt_u8);
extern void lcd_read_cmd(alt_u16);
extern void lcd_write_data(alt_u16,alt_u8);
extern void lcd_read_data(alt_u16);
extern void lcd_init();
extern void lcd_show_text(char * text);
extern void lcd_line1();
extern void lcd_line2();
extern void lcd_test();
#define lcd_write_cmd(base,data) IOWR(base,0,data)
#define lcd_read_cmd(base) IORD(base,1)
#define lcd_write_data(base,data) IOWR(base,2,data)
#define lcd_read_data(base) IORD(base,3)
void test_display();
void lcd_dis(alt_u8 line,alt_u8 *p);
#endif /*LCD_H_*/
lcd.c文件
#include "includes.h"
void lcd_init()
{
/*采用8位数据总线的方式,两行显示*/
lcd_write_cmd(LCD_16207_0_BASE,0X38);
usleep(2000);
/*关显示,关光标闪烁方式*/
lcd_write_cmd(LCD_16207_0_BASE,0X0C);
usleep(2000);
/*清显示*/
lcd_write_cmd(LCD_16207_0_BASE,0X01);
usleep(2000);
/*光标前移方式,不允许整屏移动*/
lcd_write_cmd(LCD_16207_0_BASE,0X06);
usleep(2000);
/*显示指针指向处事位置*/
lcd_write_cmd(LCD_16207_0_BASE,0X80);
usleep(2000);
}
/*显示一行字符*/
void lcd_show_text(char * text)
{
int i;
for(i=0;i {
lcd_write_data(LCD_16207_0_BASE,text[i]);
usleep(2000);
}
}
void lcd_line1()
{
lcd_write_cmd(LCD_16207_0_BASE,0X80);
usleep(2000);
}
/*换行,即切换到第二行*/
void lcd_line2()
{
lcd_write_cmd(LCD_16207_0_BASE,0XC0);
usleep(2000);
}
void lcd_dis(alt_u8 line,alt_u8 *p)
{
if(line==1)
{
lcd_line1();
lcd_show_text(p);
}
else if(line==2)
{
lcd_line2();
lcd_show_text(p);
}
}
void test_display()
{
char text1[16]="TIAN SANG DI XIA";
char text2[16]="WEI WO DU ZUN!";
/*切换到第一行*/
lcd_line1();
/*显示第一行字符*/
lcd_show_text(text1);
/*切换到第二行*/
lcd_line2();
/*显示第二行字符*/
lcd_show_text(text2);
usleep(500000);
lcd_write_cmd(LCD_16207_0_BASE,0X01);//清屏
usleep(2000);
/*切换到第一行*/
lcd_line1();
lcd_show_text("YANGTZE");
lcd_line2();
/*显示第二行字符*/
lcd_show_text("UNIVERSITY GOOD!");
//Uart_3_send_n("NIOS II,I am coming!");
usleep(500000);
}
key.h文件
#ifndef KEY_H_
#define KEY_H_
#define key4 0x7
#define key3 0xb
#define key2 0xd
#define key1 0xe
#define key IORD(BUTTON_PIO_BASE,0)
#endif /*KEY_H_*/
key.c文件
#include "includes.h"
led.h文件
#ifndef LED_H_
#define LED_H_
void seg_init();
void red_dis(alt_u8 x);
void green_dis(alt_u8 x);
void seg_dis(alt_u32 z);
#endif /*LED_H_*/
led.c文件
/*发光二极管和数码管驱动*/
#include "includes.h"
alt_u8 seg_table[11]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x7f};
void seg_init()
{
IOWR(SEG7_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG6_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG5_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG4_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG3_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG2_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG1_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG0_DISPLAY_BASE,0,seg_table[10]);
}
//数码管显示子函数//
void seg_dis(alt_u32 z)
{
if(z<10)
{
IOWR(SEG0_DISPLAY_BASE,0,seg_table[z%10]);
IOWR(SEG1_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG2_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG3_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG4_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG5_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG6_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG7_DISPLAY_BASE,0,seg_table[10]);
}
else if(z<100)
{
IOWR(SEG0_DISPLAY_BASE,0,seg_table[z%10]);
IOWR(SEG1_DISPLAY_BASE,0,seg_table[z%100/10]);
IOWR(SEG2_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG3_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG4_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG5_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG6_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG7_DISPLAY_BASE,0,seg_table[10]);
}
else if(z<1000)
{
IOWR(SEG0_DISPLAY_BASE,0,seg_table[z%10]);
IOWR(SEG1_DISPLAY_BASE,0,seg_table[z%100/10]);
IOWR(SEG2_DISPLAY_BASE,0,seg_table[z%1000/100]);
IOWR(SEG3_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG4_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG5_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG6_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG7_DISPLAY_BASE,0,seg_table[10]);
}
else if(z<10000)
{
IOWR(SEG0_DISPLAY_BASE,0,seg_table[z%10]);
IOWR(SEG1_DISPLAY_BASE,0,seg_table[z%100/10]);
IOWR(SEG2_DISPLAY_BASE,0,seg_table[z%1000/100]);
IOWR(SEG3_DISPLAY_BASE,0,seg_table[z%10000/1000]);
IOWR(SEG4_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG5_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG6_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG7_DISPLAY_BASE,0,seg_table[10]);
}
else if(z<100000)
{
IOWR(SEG0_DISPLAY_BASE,0,seg_table[z%10]);
IOWR(SEG1_DISPLAY_BASE,0,seg_table[z%100/10]);
IOWR(SEG2_DISPLAY_BASE,0,seg_table[z%1000/100]);
IOWR(SEG3_DISPLAY_BASE,0,seg_table[z%10000/1000]);
IOWR(SEG4_DISPLAY_BASE,0,seg_table[z%100000/10000]);
IOWR(SEG5_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG6_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG7_DISPLAY_BASE,0,seg_table[10]);
}
else if(z<1000000)
{
IOWR(SEG0_DISPLAY_BASE,0,seg_table[z%10]);
IOWR(SEG1_DISPLAY_BASE,0,seg_table[z%100/10]);
IOWR(SEG2_DISPLAY_BASE,0,seg_table[z%1000/100]);
IOWR(SEG3_DISPLAY_BASE,0,seg_table[z%10000/1000]);
IOWR(SEG4_DISPLAY_BASE,0,seg_table[z%100000/10000]);
IOWR(SEG5_DISPLAY_BASE,0,seg_table[z%1000000/100000]);
IOWR(SEG6_DISPLAY_BASE,0,seg_table[10]);
IOWR(SEG7_DISPLAY_BASE,0,seg_table[10]);
}
else if(z<10000000)
{
IOWR(SEG0_DISPLAY_BASE,0,seg_table[z%10]);
IOWR(SEG1_DISPLAY_BASE,0,seg_table[z%100/10]);
IOWR(SEG2_DISPLAY_BASE,0,seg_table[z%1000/100]);
IOWR(SEG3_DISPLAY_BASE,0,seg_table[z%10000/1000]);
IOWR(SEG4_DISPLAY_BASE,0,seg_table[z%100000/10000]);
IOWR(SEG5_DISPLAY_BASE,0,seg_table[z%1000000/100000]);
IOWR(SEG6_DISPLAY_BASE,0,seg_table[z%10000000/1000000]);
IOWR(SEG7_DISPLAY_BASE,0,seg_table[10]);
}
else if(z<100000000)
{
IOWR(SEG0_DISPLAY_BASE,0,seg_table[z%10]);
IOWR(SEG1_DISPLAY_BASE,0,seg_table[z%100/10]);
IOWR(SEG2_DISPLAY_BASE,0,seg_table[z%1000/100]);
IOWR(SEG3_DISPLAY_BASE,0,seg_table[z%10000/1000]);
IOWR(SEG4_DISPLAY_BASE,0,seg_table[z%100000/10000]);
IOWR(SEG5_DISPLAY_BASE,0,seg_table[z%1000000/100000]);
IOWR(SEG6_DISPLAY_BASE,0,seg_table[z%10000000/1000000]);
IOWR(SEG7_DISPLAY_BASE,0,seg_table[z%100000000/10000000]);
}
}
void led_init()
{
IOWR(LED_RED_BASE,0,0);//熄灭红色发光二极管
IOWR(LED_GREEN_BASE,0,0);//熄灭绿色发光二极管
}
void red_dis(alt_u8 x)
{
IOWR(LED_RED_BASE,0,x);
}
void green_dis(alt_u8 x)
{
IOWR(LED_GREEN_BASE,0,x);
}
uart.h文件
extern void Uart_3_send(unsigned char data);
extern void Uart_3_send_n(unsigned char *ptr);
extern int Uart_3_receive(void);
extern void Uart_3_ISR(void * context,alt_u32 id);
extern void Uart_3_init(alt_u32);
extern void Uart_2_send(unsigned char data);
extern void Uart_2_send_n(unsigned char *ptr);
extern int Uart_2_receive(void);
extern void Uart_2_ISR(void * context,alt_u32 id);
extern void Uart_2_init(alt_u32);
void Uart_init();
uart.c文件
#include "includes.h"
#define TIME_DELAY 1000000//1M,即一秒
//UART发送一个字节子程序
/*-------------------------------------UART2-------------------------------*/
#ifdef uart_2
void Uart_2_send(unsigned char data)
{
alt_u16 status;
status=IORD_ALTERA_AVALON_UART_STATUS(UART_2_BASE);
while(!(status&0x0040))//等待发送完成
status=IORD_ALTERA_AVALON_UART_STATUS(UART_2_BASE);
IOWR_ALTERA_AVALON_UART_TXDATA(UART_2_BASE,data);
}
//UART发送多个字节子程序
void Uart_2_send_n(unsigned char *ptr)
{
while(*ptr)
{
Uart_2_send(*ptr);
ptr++;
}
Uart_2_send(0x0a);//显示完一个字符串就回车换行
}
//UART接收子程序
int Uart_2_receive(void)
{
alt_u16 status;
int temp;
status=IORD_ALTERA_AVALON_UART_STATUS(UART_2_BASE);
while(!(status&0x0080))//等待发送完成
status=IORD_ALTERA_AVALON_UART_STATUS(UART_2_BASE);
temp=IORD_ALTERA_AVALON_UART_RXDATA(UART_2_BASE);
return temp;
}
//串口中断初始化
void Uart_2_init(alt_u32 baudrate)
{
int divisor;
IOWR_ALTERA_AVALON_UART_CONTROL(UART_2_BASE, 0x80);//接收中断使能
IOWR_ALTERA_AVALON_UART_STATUS(UART_2_BASE, 0x0);//清状态标志
//IOWR_ALTERA_AVALON_UART_RXDATA(UART_2_BASE, 0x0);//清接收寄存器
divisor = (int)(SYS_TICK/baudrate+0.5);//设置波特率
IOWR_ALTERA_AVALON_UART_DIVISOR(UART_2_BASE, divisor);
alt_irq_register(UART_2_IRQ,0,Uart_2_ISR);
////////////////////// alt_irq_register(UART_2_IRQ,0,Uart_2_ISR);
}
#endif
#ifdef uart_3
/*-------------------------------------UART3-------------------------------*/
void Uart_3_send(unsigned char data)
{
alt_u16 status;
status=IORD_ALTERA_AVALON_UART_STATUS(UART_3_BASE);
while(!(status&0x0040))//等待发送完成
status=IORD_ALTERA_AVALON_UART_STATUS(UART_3_BASE);
IOWR_ALTERA_AVALON_UART_TXDATA(UART_3_BASE,data);
}
//UART发送多个字节子程序
void Uart_3_send_n(unsigned char *ptr)
{
while(*ptr)
{
Uart_3_send(*ptr);
ptr++;
}
Uart_3_send(0x0a);//显示完一个字符串就回车换行
}
//UART接收子程序
int Uart_3_receive(void)
{
alt_u16 status;
int temp;
status=IORD_ALTERA_AVALON_UART_STATUS(UART_3_BASE);
while(!(status&0x0080))//等待发送完成
status=IORD_ALTERA_AVALON_UART_STATUS(UART_3_BASE);
temp=IORD_ALTERA_AVALON_UART_RXDATA(UART_3_BASE);
return temp;
}
//串口中断初始化
void Uart_3_init(alt_u32 baudrate)
{
int divisor;
IOWR_ALTERA_AVALON_UART_CONTROL(UART_3_BASE, 0x80);//接收中断使能
IOWR_ALTERA_AVALON_UART_STATUS(UART_3_BASE, 0x0);//清状态标志
//IOWR_ALTERA_AVALON_UART_RXDATA(UART_3_BASE, 0x0);//清接收寄存器
divisor = (int)(SYS_TICK/baudrate+0.5);//设置波特率
IOWR_ALTERA_AVALON_UART_DIVISOR(UART_3_BASE, divisor);
alt_irq_register(UART_3_IRQ,0,Uart_3_ISR);
}
#endif
void Uart_init()
{
#ifdef uart_2
Uart_2_init(4800);
#endif
#ifdef uart_3
Uart_3_init(4800);
#endif
}
/*
int main()
{
Uart_init();
while(1)
{
Uart_send_n("Liu Ya Li,I love u!");
//Uart_send_n(64);
usleep(TIME_DELAY);//延时一微秒
}
}
*/
timer.h文件
#ifndef TIMER_H_
#define TIMER_H_
//定时器1周期1s
#define timer_1_period ((SYS_TICK))
#define timer_1_start IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_1_BASE,0x07)
#define timer_1_stop IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_1_BASE,0x00)
void timer_1_init();
void isr_timer_1();
#endif /*TIMER_H_*/
timer.c文件
#include "includes.h"
void timer_1_init()
{
//手动清除定时器1的中断溢出标志//
IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_1_BASE,0X00);
/*设定定时器1周期的低16位*/
IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_1_BASE,timer_1_period);
/*设定定时器1周期的高16位*/
IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_1_BASE,timer_1_period>>16);
/*对定时器1中断进行注册*/
alt_irq_register(TIMER_1_IRQ, (void *)TIMER_1_BASE, isr_timer_1);
//timer_1_start;
}
hello_world.h文件
#ifndef HELLO_WORLD_H_
#define HELLO_WORLD_H_
//串口中断需要的变量
alt_u8 comma_count; //逗号计数器
alt_u8 dot_count; //小数点计数器
alt_u8 rx_count; //位数计数器
alt_u8 cmd_type; //命令类型
alt_u8 mode; //0:结束模式,1:命令模式,2:数据模式
alt_u8 buf_full=0; //1:整句接收完成,相应数据有效。0:缓存数据无效。
alt_u8 cmd[5]; //命令类型存储数组
alt_u8 dd[10]; //数据数组
#define TYPE_GPGGA 1
#define TYPE_GPGSV 2
#define TYPE_GPRMC 3
#define TYPE_NONE 4
//结束模式
#define mode_end 0
//命令模式
#define mode_cmd 1
//数据模式
#define mode_data 2
//其他模式
#define mode_else 3
#define TIME_BASE 8
//GPS数据存储数组
alt_u8 state_dingwei;//定位状态
alt_u8 stat_count[2]="XX";//定位状态
alt_u8 JD[10]="1234567890"; //经度
alt_u8 JD_A='X'; //经度方向
alt_u8 WD[9]="123456789"; //纬度
alt_u8 WD_A='X'; //纬度方向
alt_u8 time[6] ="123456"; //时间
alt_u8 date[6] ="123456";
alt_u8 speed[5]="12345"; //速度
alt_u8 high[6] ="123456"; //高度
alt_u8 angle[6]="123456"; //方位角
alt_u8 use_sat[2]="12"; //使用的卫星数
alt_u8 total_stat[2]="12"; //天空中总卫星数
alt_u8 lock; //定位状态
alt_u8 gps_data[]="$GPRMC,072255.000,A,3019.9711,N,11212.1782,E,0.35,182.02,040111,,*06\
$GPGGA,072256.000,3019.9712,N,11212.1782,E,1,03,9.2,22.0,M,,,,0000*38\
$GPGSA,A,2,10,05,29,,,,,,,,,,9.2,9.2,1.0*3D\
$GPGSV,3,1,12,26,74,147,,05,53,023,33,29,46,291,32,02,43,106,*7F\
$GPGSV,3,2,12,15,41,206,,10,16,059,28,08,14,074,19,04,12,116,*79\
$GPGSV,3,3,12,21,08,307,,27,04,170,,07,04,045,16,25,01,246,*71";
//FLASH的相关定义
#define BUF_SIZE 100
#define FLASH_OFFSET 0X01500000
#endif /*HELLO_WORLD_H_*/
hello_world.c文件
//int main (void) __attribute__ ((weak, alias ("alt_main")));
/*硬件环境:DE2开发板
* 软件环境:quaters II 7.2,NIOS II 7.2
*/
#include "includes.h"
#include "hello_world.h"
alt_u8 dis_buff[16]=" ";
alt_u8 dis_buff2[16]=" ";
extern alt_u8 f_1hz=0x00;
void isr_timer_1()
{
//手动清除定时器1的中断溢出标志、/
IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_1_BASE,0X00);
//timer_1_stop;//关闭定时器1
f_1hz=~f_1hz;
}
/*
void Uart_3_ISR(void * context,alt_u32 id)
{
alt_u8 temp;
temp=IORD_ALTERA_AVALON_UART_RXDATA(UART_3_BASE);
IOWR(LED_GREEN_BASE,0,1<<1);
switch(temp)
{
case '$':
{
comma_count=0;//逗号计数器清零
mode=mode_cmd;//接收命令模式,//0:结束模式,1:命令模式,2:数据模式
rx_count=0;//接收位数清零
}break;
case ',':
{
comma_count++;//逗号计数器加1
rx_count=0;//接收位数清零
}break;
case '*':
{
mode=mode_else;
rx_count=0;
}
break;
default:
{
if(mode==mode_cmd) //命令种类判断
{IOWR(LED_GREEN_BASE,0,1<<2);
cmd[rx_count]=temp; //接收字符放入类型缓存
printf("%s",cmd);
if(rx_count>=4) //如果类型数据接收完毕,判断类型
{
if(cmd[0]=='G'&&cmd[1]=='P'&&cmd[2]=='G'&&cmd[3]=='G'&&cmd[4]=='A')
{
mode=mode_data;//接收数据格式
cmd_type=TYPE_GPGGA;//GPGGA
comma_count=0;
rx_count=0;
}
else if(cmd[0]=='G'&&cmd[1]=='P'&&cmd[2]=='G'&&cmd[3]=='S'&&cmd[4]=='V')
{
mode=mode_data;//接收数据格式
cmd_type=TYPE_GPGSV;//GPGSV
comma_count=0;
rx_count=0;
}
else if(cmd[0]=='G'&&cmd[1]=='P'&&cmd[2]=='R'&&cmd[3]=='M'&&cmd[4]=='C')
{ IOWR(LED_GREEN_BASE,0,1<<3);printf("%s",cmd);
mode=mode_data;//接收数据格式
cmd_type=TYPE_GPRMC;//GPRMC
comma_count=0;
rx_count=0;
printf("ni hao !");
IOWR(LED_RED_BASE,0,1<<1);
}
rx_count=0;
}
}
if(mode==mode_data) //接收数据处理
{
// rx_count++;
switch (cmd_type)
{
case TYPE_GPGGA: //类型1数据接收。GPGGA
switch(comma_count)
{
case 2: //纬度处理
if(rx_count<9)
{
WD[rx_count]=temp;
}
break;
case 3: //纬度半球处理,N/E
if(rx_count<1){WD_A=temp;}
break;
case 4: //经度半球处理,E/W
if(rx_count<10)
{
JD[rx_count]=temp;
}
break;
case 5: //经度方向处理
if(rx_count<1){JD_A=temp;}
break;
case 6: //定位判断
if(rx_count<1){lock=temp-0x30;} //lock已经数值化
break;
case 7: //定位使用的卫星数
if(rx_count<2){use_sat[rx_count]=temp;}
break;
case 9: //高度处理
if(rx_count<6){high[rx_count]=temp;}
break;
}break;
case TYPE_GPGSV: //类型2数据接收。GPGSV
switch(comma_count)
{
case 3: //天空中的卫星总数
if(rx_count<2){total_sat[rx_count]=temp;}
break;
}
break;
case TYPE_GPRMC: //类型3数据接收。GPRMC
switch(comma_count)
{
printf("Hello!");
case 1: //时间处理,在GPRMC下获取时间hhmmss
if(rx_count<6){time[rx_count]=temp;}
break;
case 7: //速度处理
if(rx_count<5){speed[rx_count]=temp;}
break;
case 8: //方位角处理
if(rx_count<6){angle[rx_count]=temp;}
case 9: //方位角处理
if(rx_count<6){date[rx_count]=temp;}
break;
}
break;
}
}
if(mode==mode_else)
{
//mode=mode_data;//接收数据格式
cmd_type=TYPE_NONE;//GPRMC
comma_count=0;
rx_count=0;
}
}break;
}
rx_count++;
}
*/
/*
#ifdef uart_2
alt_u8 flag=0;
alt_u8 flag1=0;
alt_u8 rx_buff[10240];
void Uart_2_ISR(void * context,alt_u32 id)
{
alt_u8 temp;
temp=IORD_ALTERA_AVALON_UART_RXDATA(UART_2_BASE);
//Uart_send(temp);
if(temp=='$')
{
flag=1;
rx_count=0;
}
if(temp!='$'&&temp!=',')
rx_count++;
if(flag==1)
{
rx_buff[rx_count]=temp;
if(rx_buff[1]=='G'&&rx_buff[2]=='P'&&rx_buff[3]=='R'&&rx_buff[4]=='M'&&rx_buff[5]=='C')
{
flag1=1;
rx_count=0;
}
if(flag1==1)
{
if(rx_count<=6)
{
time[0]=rx_buff[1];
time[1]=rx_buff[2];
time[2]=rx_buff[3];
time[3]=rx_buff[4];
time[4]=rx_buff[5];
time[5]=rx_buff[6];
}
else
{
rx_count=0;
flag=0;
flag1=0;
}
}
}
green_dis((1&&(f_1hz)));//绿色发光二极管闪烁
//printf("%s",rx_buff);
//IOWR_ALTERA_AVALON_UART_RXDATA(UART_3_BASE, 0x0);//清接收寄存器
}
#endif
*/
/*
#ifdef uart_3
#ifndef uart_2
alt_u8 flag=0;
alt_u8 flag1=0;
alt_u8 rx_buff[10240];
#endif
void Uart_3_ISR(void * context,alt_u32 id)
{
alt_u8 temp;
temp=IORD_ALTERA_AVALON_UART_RXDATA(UART_3_BASE);
//Uart_3_send(temp);
if(temp=='$')
{
flag=1;
//flag1=0;
rx_count=0;
comma_count=0;
}
if(temp!='$'&&temp!=',')
rx_count++;
if((temp==',')&&flag)
{
comma_count++;
rx_count=0;
}
{
if(flag==1)
{
rx_buff[rx_count]=temp;
if(rx_buff[1]=='G'&&rx_buff[2]=='P'&&rx_buff[3]=='R'&&rx_buff[4]=='M'&&rx_buff[5]=='C')
{
flag1=1;
rx_count=0;
IOWR(LED_RED_BASE,0,0xf0);
}
if(flag1==1)
{
switch(comma_count)
{
case 1:
{
if(rx_count<=6)
{
time[0]=rx_buff[1];
time[1]=rx_buff[2];
time[2]=rx_buff[3];
time[3]=rx_buff[4];
time[4]=rx_buff[5];
time[5]=rx_buff[6];
//printf("%d",comma_count);
}
else
{
rx_count=0;
flag=0;
}
}
break;
}
}
}
}
//printf("%s",rx_buff);
//IOWR_ALTERA_AVALON_UART_RXDATA(UART_3_BASE, 0x0);//清接收寄存器
}
#endif
*/
void main()
{
seg_init();
lcd_init();//液晶初始化
Uart_init();
Uart_3_init(4800);
timer_1_init();
timer_1_start;
alt_u8 bhour;
float weidu;
float jindu;
int ret_code=0;
//alt_u8 bdate[7] ="123456";
alt_u8 max;
alt_flash_fd* fd;
fd=alt_flash_open_dev("/dev/cfi_flash");
ret_code=alt_write_flash(fd,FLASH_OFFSET,11,BUF_SIZE);
while(1)
{
//seg_dis(alt_read_flash());
}
while(1)
{
//if(flag==0)
{
bhour=(time[0]-'0')*10+time[1]-'0'+TIME_BASE;
if(bhour>24)
bhour=bhour-24;
weidu=(WD[0]-'0')*10+(WD[1]-'0')+((WD[2]-'0')*10+(WD[3]-'0')+(WD[5]-'0')*0.1+(WD[6]-'0')*0.01+(WD[7]-'0')*0.001+(WD[8]-'0')*0.0001)/60;
jindu=(JD[0]-'0')*100+(JD[1]-'0')*10+(JD[2]-'0')+((JD[3]-'0')*10+(JD[4]-'0')+(JD[6]-'0')*0.1+(JD[7]-'0')*0.01+(JD[8]-'0')*0.001+(JD[9]-'0')*0.0001)/60;
//bdate[0=(date[0])
seg_dis((jindu*100000));
// seg_dis();
//printf("经度%f 纬度%f\n",jindu,weidu);
//printf("%s",JD_A);
//printf("日期 20%s\n",date);
//printf("%s\n",JD);
//printf("%s\n",stat_count);
dis_buff[0]=bhour/10+'0';
dis_buff[1]=bhour%10+'0';
dis_buff[2]=':';
dis_buff[3]=time[2];
dis_buff[4]=time[3];
dis_buff[5]=':';
dis_buff[6]=time[4];
dis_buff[7]=time[5];
dis_buff[8]='2';
dis_buff[9]='0';
dis_buff[10]=date[0];
dis_buff[11]=date[1];
dis_buff[12]=date[2];
dis_buff[13]=date[3];
dis_buff[14]=date[4];
dis_buff[15]=date[5];
dis_buff2[0]=(alt_u16)(weidu/10)+'0';
dis_buff2[1]=(alt_u16)(weidu)%10+'0';
dis_buff2[2]='.';
dis_buff2[3]=(alt_u16)(weidu*10)%10+'0';
dis_buff2[4]=(alt_u16)(weidu*100)%10+'0';
dis_buff2[5]=(alt_u16)(weidu*1000)%10+'0';
dis_buff2[6]=(alt_u32)(weidu*10000)%10+'0';
dis_buff2[7]=(alt_u32)(weidu*100000)%10+'0';
dis_buff2[8]=WD_A;
dis_buff2[9]=JD_A;
dis_buff2[10]=state_dingwei;
dis_buff2[11]=stat_count[0];
dis_buff2[12]=stat_count[1];
dis_buff2[14]=total_stat[0];
dis_buff2[15]=total_stat[1];
lcd_line1();
// Uart_2_send_n("LIU yong zheng,sha bi!");
lcd_show_text(dis_buff);//printf("%s",rx_buff);
lcd_line2();
lcd_show_text(dis_buff2);
//usleep(1000);
}
//green_dis((1&&(f_1hz)));
//printf("%s\n",WD);
//seg_dis(WD);
switch(key)
{
case key1:
{
green_dis((1<<0)&&f_1hz);
}break;
case key2:
{
green_dis(1<<1);
}break;
case key3:
{
green_dis(1<<2);
}break;
case key4:
{
green_dis(1<<3);
}break;
}
}
}
void Uart_3_ISR(void * context,alt_u32 id)
{
alt_u8 temp;
temp=IORD_ALTERA_AVALON_UART_RXDATA(UART_3_BASE);
//Uart_3_send(temp);
if(temp=='$')
{
//flag=1;
//flag1=0;
rx_count=0;
comma_count=0;
}
switch(temp)
{
case '$':
{
mode=mode_cmd;
rx_count=0;
comma_count=0;
}
break;
case ',':
{
rx_count=0;
comma_count++;
}
break;
default :
{
if(mode==mode_cmd)
{
cmd[rx_count]=temp;
if(rx_count>=4)
{
if(cmd[0]=='G'&&cmd[1]=='P'&&cmd[2]=='R'&&cmd[3]=='M'&&cmd[4]=='C')
cmd_type=TYPE_GPRMC;//GPRMC
else if(cmd[0]=='G'&&cmd[1]=='P'&&cmd[2]=='G'&&cmd[3]=='G'&&cmd[4]=='A')
cmd_type=TYPE_GPGGA;//GPGGA
else if(cmd[0]=='G'&&cmd[1]=='P'&&cmd[2]=='G'&&cmd[3]=='S'&&cmd[4]=='V')
cmd_type=TYPE_GPGSV;//GPGSV
IOWR(LED_RED_BASE,0,0XFF&&f_1hz);
mode=mode_data;
rx_count=0;
}
}
if(mode==mode_data)
{
switch(cmd_type)
{
case TYPE_GPRMC:
{
dd[rx_count]=temp;
switch(comma_count)
{
case 1:
{
if(rx_count>=5)
{
time[0]=dd[0];time[1]=dd[1];time[2]=dd[2];
time[3]=dd[3];time[4]=dd[4];time[5]=dd[5];
}
}
break;
case 2:
{
if(dd[0]>60&&(rx_count==0))//判断是否为字母
state_dingwei=dd[0];
//IOWR(LED_GREEN_BASE,0,8&&f_1hz);
}
break;
case 3:
{
if(rx_count>=8)
{
WD[0]=dd[0];WD[1]=dd[1];WD[2]=dd[2];
WD[3]=dd[3];WD[4]=dd[4];WD[5]=dd[5];
WD[6]=dd[6];WD[7]=dd[7];WD[8]=dd[8];
}
}
break;
case 4:
{
if(dd[0]>60&&(rx_count==0))//判断是否为字母
WD_A=dd[0];
}
break;
case 5:
{
if(rx_count>=9)
{
JD[0]=dd[0];JD[1]=dd[1];JD[2]=dd[2];
JD[3]=dd[3];JD[4]=dd[4];JD[5]=dd[5];
JD[6]=dd[6];JD[7]=dd[7];JD[8]=dd[8];
JD[9]=dd[9];
}
}
break;
case 6:
{
if(dd[0]>60)//判断是否为字母
JD_A=dd[0];
}
break;
case 9:
{
if(rx_count>=5)
{
date[0]=dd[4];date[1]=dd[5];
date[2]=dd[2];date[3]=dd[3];
date[4]=dd[0];date[5]=dd[1];
}
}
%3