cjj20
Newbie level 4
- Joined
- Jan 9, 2018
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 119
Hi can anyone help me in getting this code right?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 #include <stdio.h> #include <avr/io.h> #include <util/delay.h> #define LCD_DATA PORTC; #define F_CPU 12000000UL #define ctrl PORTB; #define USART_BAUDRATE 4800 #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) #define rs PB0; //register select #define rw PB1; // LCD read/Write #define en PB2; // enable print void lcd_init(); void lcdcmd(unsigned char); void lcddata(unsigned char); void delay(int); void drawstring(unsigned char *stri); unsigned int receiveserial(); void uart_init(); void checkgpgga(); unsigned char send[90]; unsigned char send2[90]; unsigned char data; unsigned char lat[15]; unsigned char long[15]; unsigned char lati; unsigned char longi; int main() { DDRC=0xff; //output DDRB=0x07; lcd_init(); delay(50); uart_init(); while(1){ receiveserial(); checkgpgga(); } return 0; } void uart_init() { UBRRL = BAUD_PRESCALE; UBRRH = (BAUD_PRESCALE >> 8); UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN); UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); } void lcdcmd(unsigned char n) { LCD_DATA=n; ctrl =(0<<rs)|(0<<rw)|(1<<en); delay(1); ctrl =(0<<rs)|(0<<rw)|(0<<en); return; } void lcddata(unsigned char n) { LCD_DATA=n; ctrl = (1<<rs)|(0<<rw)|(1<<en); delay(1); ctrl = (1<<rs)|(0<<rw)|(0<<en); return; } void lcd_init() { lcdcmd(0x38); //2 line matrix delay(50); lcdcmd(0x01); //clear lcd delay(50); lcdcmd(0x0E); // cursor start delay(50); lcdcmd(0x80); //cursor begins at line 1 delay(50); return; } unsigned int receiveserial() { while(!(UCSRA) & (1<<RXC)); return UDR; } void drawstring(unsigned char *stri) { unsigned char stri; int j; while(stri[j]!='\0') { lcddata(stri[j]); j++; } return; } void checkgpgga() { int i; int j; data=receiveserial(); if(data=='$') { data=receiveserial(); if(data=='G') { data=receiveserial() if(data=='P') { data=receiveserial(); if(data=='G') { data=receiveserial(); if(data=='G') { data=receiveserial(); if(data=='A') { data-receiveserial(); if(data==',') { data=receiveserial(); while(data!=',') { data=receiveserial(); } while(data!=',') { data=receiveserial(); } lat[0]=receiveserial(); data=lat[0]; for(i=0;data!=',';i++) { lat[i]=receiveserial(); data=lat[i]; } lati=receiveserial(); data=receiveserial(); while(data!=',') { data=receiveserial(); } long[0]=receiveserial(); data=long[0]; for(i=1;data!=',';i++) { long[i]=receiveserial(); data=long[i]; } longi=receiveserial(); lcdcmd(0x01); delay(1); lcdcmd(0x80); delay(1000); i=0; while(lat[i]!='\0') { lcddata(lat[j]); j++; } lcddata(lati); lcdcmd(0xC0); delay(1000); i=0; while(long[i]!='\0') { lcddata(long[i]); i++; } lcddata(longi); delay(1000); } } } } } } } } } void delay(unsigned int times) { unsigned int i; unsigned int j; for(i=0;i<times;i++) for(j=0;j<1275;j++); }