49,6 → 49,7 |
|
//************************************************************************ |
// pomocne |
|
#define WIDTH_CHAR_SIGNALL 8 |
prog_uint8_t CHAR_SIGNALL[WIDTH_CHAR_SIGNALL]={127,12,30,51,51,30,12,127}; |
|
65,9 → 66,11 |
prog_uint8_t CHAR_LIGHT[WIDTH_CHAR_LIGHT]={127,65,95,95,127}; |
|
|
|
#define BOOT() (((void(*)(void))(char *)0x7C00)()) |
#define RESET() (((void(*)(void))(char *)0x0000)()) |
//*********************************************************************** |
// global variables |
|
extern uint8_t video_buf[504]; |
extern uint8_t *offset_text; |
|
79,12 → 82,16 |
|
enum {ID_TIME,ID_LOCATION,ID_COURSE,ID_ALL_POSITION,ID_ALL_SERVICE,ID_SERVICE,ID_TEMP,ID_SATELITES,ID_NORTH,ID_NAV}; |
|
static FILE mystdout = FDEV_SETUP_STREAM(lcd_put, NULL,_FDEV_SETUP_WRITE); // in lcd.h |
static FILE mystdout2 = FDEV_SETUP_STREAM(lcd_put2, NULL,_FDEV_SETUP_WRITE); // in lcd.h |
|
//static int lcd_put(char c, FILE *stream); |
static FILE mystdout = FDEV_SETUP_STREAM(lcd_put, NULL,_FDEV_SETUP_WRITE); |
//static int lcd_put2(char c, FILE *stream); |
static FILE mystdout2 = FDEV_SETUP_STREAM(lcd_put2, NULL,_FDEV_SETUP_WRITE); |
//************************************************************************ |
// prototypes |
|
//(*bootloader)(void) = 0x7C00; |
void delay_ms(uint16_t time); |
void null_variables(void); |
|
//************************************************************************ |
// general cpu init |
|
98,8 → 105,8 |
TL3_INIT; |
TL3_PULLUP; |
|
RX_INIT; |
RX_PULLUP; |
USB_INIT; |
//USB_PULLUP; |
|
GPS_INIT; |
GPS_OFF; |
120,16 → 127,22 |
LED_OFF; |
|
//*** EXTERNAL PIN INTERRUPTS |
EICRA = _BV(ISC21); //pin INT2 - TL2 |
EIMSK = _BV(INT2); //pin INT2 - TL2 |
//PCICR = _BV(PCIE1); //pin change TL1,TL2,TL3 |
//PCMSK1 = _BV(PCINT10) | _BV(PCINT11) |_BV(PCINT12); //pin change TL1,TL2,TL3 |
//EICRA = _BV(ISC21); //pin INT2 - TL2 |
//EIMSK = _BV(INT2); //pin INT2 - TL2 |
|
|
//*** TIMER1 *** tik for TL fosc/8 /1024(TCNT1) cca 8ms |
//*** PIN CHANGE INTERRUPTS PCINT29 |
PCICR = _BV(PCIE1); |
PCMSK1 = _BV(PCINT10) | _BV(PCINT11) |_BV(PCINT12); //pin change TL1,TL2,TL3 |
|
PCICR |= _BV(PCIE3); |
PCMSK3 = _BV(PCINT29); // pin USB |
|
//*** TIMER1 *** tik for TL fosc/64 /1024(TCNT1) cca 8ms |
TCNT1 = 0; |
OCR1A = 1024; |
TCCR1A = _BV(WGM11) | _BV(WGM10); |
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11) ; // TIMER1 fast PWM |
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // TIMER1 fast PWM |
TIMSK1 = _BV(TOIE1); |
|
//*** TIMER2 *** RTC |
145,18 → 158,22 |
//WDTCSR = _BV(WDIE) | _BV(WDP3) | _BV(WDP0); |
|
//*** USART0 *** RX PD0, TX PD1, GPS |
UBRR0 = 12; |
UBRR0 = 95; |
//UCSR0A = |
UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0); |
|
//*** USART1 *** RX PD2, TX PD3 PC |
UBRR1 = 12; |
#ifndef DEBUG |
UBRR1 = 95; |
#else |
UBRR1 = 3; |
#endif |
//UCSR0A = |
UCSR1B = _BV(RXCIE1) | _BV(RXEN0) | _BV(TXEN1); |
|
//*** ADC *** |
ADMUX = _BV(REFS1) | _BV(MUX0); |
ADCSRA = _BV(ADPS1) | _BV(ADPS0); |
ADCSRA = _BV(ADPS1) | _BV(ADPS2); |
|
} |
|
230,14 → 247,42 |
UDR1 = UDR0; |
} |
|
uint8_t first_char_usart1 = 0; |
|
ISR(USART1_RX_vect) |
{ |
#ifndef DEBUG |
UDR0 = UDR1; |
#else |
if (TL1_INPUT && TL3_INPUT) BOOT(); |
//bootloader(); |
#endif |
} |
|
ISR(PCINT1_vect) |
{ |
if ((!TL3_INPUT) && (!TL1_INPUT)) RESET(); |
} |
|
ISR(PCINT3_vect) |
{ |
if (!TL2_INPUT && USB_INPUT) |
{ |
cli(); |
buffer_clr(); |
gotoxy(2,3); |
fprintf(&mystdout2,"programing"); |
gotoxy(6,5); |
fprintf(&mystdout2,"mod"); |
lcd_refresh(); |
delay_ms(1000); |
BOOT(); |
} |
|
} |
|
EMPTY_INTERRUPT(INT0_vect) |
EMPTY_INTERRUPT(INT2_vect) |
EMPTY_INTERRUPT(PCINT1_vect) |
EMPTY_INTERRUPT(WDT_vect) |
|
//************************************************************************ |
256,38 → 301,6 |
UDR0 = c; |
} |
|
void set_static_navigation(uint8_t static_nav) |
{ |
char chsum[3]; |
char SWITCH_TO_SIRF[]="$PSRF100,0,4800,8,1,0" ; |
uint8_t SET_STATIC_NAV[10]={0xa0,0xA2,0x00,0x02,0x8f,0x00,0x00,0x8f,0xB0,0xB3}; |
uint8_t SWITCH_TO_NMEA[10]={0xa0,0xA2,0x00,0x02,0x87,0x02,0x00,0x89,0xB0,0xB3}; |
uint8_t chksum; |
uint8_t i; |
|
chksum=0; |
for (i=0;i<21;i++) |
{ |
gps_put(SWITCH_TO_SIRF[i]); |
chksum +=SWITCH_TO_SIRF[i]; |
} |
gps_put('*'); |
sprintf(chsum,"%02X",chksum); |
gps_put(chsum[0]); |
gps_put(chsum[1]); |
gps_put('\r'); |
gps_put('\n'); |
|
if (static_nav) |
{ |
} |
else |
{ |
for (i=0;i<10;i++) gps_put(SET_STATIC_NAV[i]); |
} |
//for (i=0;i<10;i++) gps_put(SWITCH_TO_NMEA[i]); |
} |
|
//************************************************************************ |
// key + timer1_ovf |
|
304,8 → 317,9 |
{ |
uint8_t key_temp; |
|
timer1_ovf--; |
while (timer1_ovf) |
{ |
timer1_ovf--; |
if (timer_status) timer_status--; |
if (timer_refresh) timer_refresh--; |
if (timer_off) timer_off--; |
313,9 → 327,10 |
if (timer_key) timer_key--; |
else |
{ |
if (!TL1_INPUT) key_temp = _BV(KEY1); else key_temp = 0; |
if (!TL2_INPUT) key_temp |= _BV(KEY2); else key_temp &= ~(_BV(KEY2)); |
if (!TL3_INPUT) key_temp |= _BV(KEY3); else key_temp &= ~(_BV(KEY3)); |
key_temp = 0; |
if (!TL1_INPUT) key_temp = _BV(KEY1); |
if (!TL2_INPUT) key_temp |= _BV(KEY2); |
if (!TL3_INPUT) key_temp |= _BV(KEY3); |
if (key_temp != key_press) |
{ |
timer_key = KEY_TIME_DEAD; |
514,6 → 529,12 |
offset_text = video_buf + LCD_WIDTH - WIDTH_CHAR_LIGHT - 2*CHAR_WIDTH - WIDTH_CHAR_SIGNALL_3D - WIDTH_CHAR_SIGNALL - 2; |
if (gps.fix_position) |
{ |
|
ptr= CHAR_SIGNALL_3D;b=WIDTH_CHAR_SIGNALL_3D;//offset_text++; |
if (gps.mode2 == '3') |
for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++); |
|
offset_text = video_buf + LCD_WIDTH - WIDTH_CHAR_LIGHT - 2*CHAR_WIDTH - WIDTH_CHAR_SIGNALL_3D - 2; |
switch (gps.fix_position) |
{ |
case 1: ptr= CHAR_SIGNALL;b=WIDTH_CHAR_SIGNALL;break; |
523,10 → 544,7 |
} |
for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++); |
|
ptr= CHAR_SIGNALL_3D;b=WIDTH_CHAR_SIGNALL_3D;offset_text++; |
if (gps.mode2 == '3') |
for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++); |
offset_text++; |
|
} |
offset_text = video_buf + LCD_WIDTH - WIDTH_CHAR_LIGHT-2*CHAR_WIDTH; |
printf("%d",gps.satelites_used); |
550,8 → 568,8 |
timer_refresh = CLOCK1S; |
buffer_clr(); |
status(); |
gotoxy(1,2); |
printf("time & date"); |
//gotoxy(1,2); |
// printf("time & date"); |
gotoxy(1,3); |
fprintf(&mystdout2," %2d:%02d:%02d",gps.hour+2,gps.minute,gps.second); |
gotoxy(1,5); |
562,13 → 580,23 |
|
void displ_location(void) |
{ |
uint8_t a,b; |
uint8_t *ptr; |
|
if (!timer_refresh) |
{ |
timer_refresh = CLOCK1S; |
buffer_clr(); |
status(); |
gotoxy(1,2); |
printf("location"); |
|
gotoxy(8,2); |
offset_text -=2; |
ptr= CHAR_SIGNALL_3D;b=WIDTH_CHAR_SIGNALL_3D;//offset_text++; |
for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++); |
|
//gotoxy(9,2); |
printf("%4.0fm",gps.altitude); |
|
gotoxy(1,3); |
//gps.latitude = 14.5; |
fprintf(&mystdout2,"%c %3d%.4f'",gps.ns_indicator,(uint8_t)gps.latitude,(gps.latitude - 1.0*(uint8_t)gps.latitude)*60); |
698,7 → 726,7 |
gotoxy(1,4); |
printf("alt%4.0fm V%2.1f",gps.altitude,gps.VDOP); |
gotoxy(1,5); |
printf("geo%4.0fm H%2.1f",gps.geoid,gps.HDOP); |
printf("geo%4.1fm H%2.1f",gps.geoid,gps.HDOP); |
gotoxy(1,6); |
printf("%3.0fkm/h %3.0f",gps.speed,gps.course); |
lcd_refresh(); |
707,10 → 735,12 |
|
void displ_nav(void) |
{ |
uint8_t a; |
|
double lon,lat,temp; |
double course; |
uint8_t x,y,xl,yl,xp,yp; |
uint8_t a,b; |
uint8_t *ptr; |
|
if (!timer_refresh) |
{ |
725,6 → 755,18 |
temp = sqrt((lon*lon) + (lat*lat)); |
|
gotoxy(9,3); |
offset_text -=2; |
ptr= CHAR_SIGNALL_3D;b=WIDTH_CHAR_SIGNALL_3D; |
for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++); |
//offset_text++; |
|
//gotoxy(10,3); |
printf("%4.0fm",gps.altitude); |
|
gotoxy(7,2); |
printf("go home"); |
|
gotoxy(9,4); |
if (temp < 10000) |
{ |
if (temp<1000) fprintf(&mystdout2,"%.1f ",temp); |
731,10 → 773,10 |
else |
{ |
fprintf(&mystdout2,"%.3f ",temp/1000); |
gotoxy(12,5); |
gotoxy(12,6); |
printf("k"); |
} |
gotoxy(13,5); |
gotoxy(13,6); |
printf("m"); |
} |
else |
752,7 → 794,7 |
} |
} |
else fprintf(&mystdout2,"%5.0f ",temp); |
gotoxy(12,5); |
gotoxy(12,6); |
printf("km"); |
} |
|
810,7 → 852,8 |
|
void displ_north(void) |
{ |
//uint8_t a; |
uint8_t a,b; |
uint8_t *ptr; |
uint8_t x,y; |
uint8_t xp,yp; |
uint8_t xl,yl; |
822,9 → 865,21 |
timer_refresh = CLOCK1S; |
buffer_clr(); |
status(); |
|
gotoxy(9,3); |
offset_text -=2; |
ptr= CHAR_SIGNALL_3D;b=WIDTH_CHAR_SIGNALL_3D;//offset_text++; |
for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++); |
|
//gotoxy(10,3); |
printf("%4.0fm",gps.altitude); |
|
gotoxy(9,2); |
printf("north"); |
|
gotoxy(9,4); |
fprintf(&mystdout2,"%3.1f",gps.speed); |
gotoxy(10,5); |
gotoxy(10,6); |
printf("km/h"); |
|
#define WIDTH_REC_NORTH 43 |
958,29 → 1013,24 |
|
void all_off(void) |
{ |
if (!timer_refresh) |
{ |
buffer_clr(); |
gotoxy(6,3); |
fprintf(&mystdout2,"OFF"); |
lcd_refresh(); |
timer_refresh = CLOCK1S; |
return; |
} |
if (timer_refresh < CLOCK50MS) |
{ |
timer_refresh = 0; |
LED_OFF; |
GPS_OFF; |
REF_OFF; |
delay_ms(1000); |
LED_OFF; |
N5110_send_command(POWER_DOWN); |
|
while (TL2_INPUT) |
sleep_cpu(); |
{ |
sleep_cpu(); |
|
} |
null_variables(); |
LCD_N5110_INIT(); |
id_mod = ID_START; |
} |
displ_start(); |
} |
|
//************************************************************************ |
1039,18 → 1089,42 |
return mod; |
} |
|
void null_variables(void) |
{ |
key_press = 0; |
key_flag = 0; |
|
timer_key = 0; |
timer_temp = 0; |
timer_off = OFF_TIME; |
timer_refresh = 0; |
timer_status = 0; |
timer1_ovf =0; |
|
//max.temperature=0x8000; |
//min.temperature=0x7FFF; |
|
//sRTC=0; |
//mRTC=15; |
//hRTC=17; |
|
//dRTC=25; |
//mdRTC=7; |
//yRTC=8; |
|
id_mod = ID_START; |
} |
|
//************************************************************************ |
// main |
|
int main(void) |
{ |
uint8_t temp; |
{ |
|
pgps = &gps; |
max.temperature=0x8000; |
min.temperature=0x7FFF; |
id_mod = ID_NORTH; |
|
null_variables(); |
|
general_cpu_init(); |
//GPS_ON; |
LCD_N5110_INIT(); |
1057,14 → 1131,6 |
|
//set_static_navigation(0); |
|
sRTC=0; |
mRTC=15; |
hRTC=17; |
|
dRTC=25; |
mdRTC=7; |
yRTC=8; |
|
stdout = &mystdout; |
sei(); |
|
1072,25 → 1138,22 |
{ |
switch(id_mod) |
{ |
case ID_TIME: displ_time(); break; |
case ID_LOCATION: id_mod++;break;displ_location();break; |
case ID_TIME: displ_time(); break; |
case ID_LOCATION: displ_location();break; |
//case ID_SPEED: displ_speed(); break; |
case ID_SATELITES: displ_satelites();break; |
case ID_COURSE: id_mod++;break;displ_course(); break; |
case ID_ALL_POSITION:displ_all_position(); break; |
case ID_ALL_SERVICE:displ_all_service();break; |
case ID_SERVICE: id_mod++; break;displ_service(scan_buf);break; |
case ID_TEMP: displ_temp(); break; |
case ID_OFF: all_off(); break; |
case ID_START: displ_start(); break; |
case ID_SATELITES: displ_satelites();break; |
case ID_COURSE: id_mod++;break;displ_course(); break; |
case ID_ALL_POSITION: displ_all_position(); break; |
case ID_ALL_SERVICE: id_mod++;break;displ_all_service();break; |
case ID_SERVICE: id_mod++;break;displ_service(scan_buf);break; |
case ID_TEMP: displ_temp(); break; |
case ID_OFF: all_off(); break; |
case ID_START: displ_start(); break; |
case ID_NAV: displ_nav();break; |
case ID_NORTH: displ_north();break; |
case ID_NORTH: displ_north();break; |
default : id_mod = 0; |
} |
|
id_mod = key(id_mod); |
|
while(timer1_ovf)timer1_tik(); |
|
switch (load_nmea(rx_shift,rx_buf,scan_buf)) |
{ |
1100,6 → 1163,11 |
case RETURN_RMC: nmea_rmc(scan_buf,pgps);break; |
case RETURN_VTG: nmea_vtg(scan_buf,pgps);break; |
} |
|
timer1_tik(); |
|
id_mod = key(id_mod); |
|
} |
return 0; |
} |