comparison testavr.c @ 15:0940abdf2b9d

- Add LED commands. - Fix backspace/delete.
author darius
date Sat, 17 Sep 2005 18:10:33 +0930
parents 2c03ec600dbc
children 026dc24d85e0
comparison
equal deleted inserted replaced
14:a9d493261c6c 15:0940abdf2b9d
51 int 51 int
52 main(void) { 52 main(void) {
53 uint8_t ROM[8]; 53 uint8_t ROM[8];
54 char cmdbuf[40]; 54 char cmdbuf[40];
55 int8_t i, arg; 55 int8_t i, arg;
56 56 uint8_t crc, buf[9];;
57 int8_t temp;
58 uint16_t tfrac;
59
57 cli(); 60 cli();
58 61
59 outp(0xfc, DDRC); 62 outp(0xfc, DDRC);
60 outp(0x00, PORTC); 63 outp(0x00, PORTC);
64 DDRA = 0xff;
61 65
62 /* Init UART */ 66 /* Init UART */
63 outp(UART_BAUD_SELECT(UART_BAUD_RATE,XTAL_CPU), UBRR); 67 outp(UART_BAUD_SELECT(UART_BAUD_RATE,XTAL_CPU), UBRR);
64 68
65 /* Enable receiver and transmitter. Turn on transmit interrupts */ 69 /* Enable receiver and transmitter. Turn on transmit interrupts */
74 while (1) { 78 while (1) {
75 cmdbuf[i] = tolower(uart_getc()); 79 cmdbuf[i] = tolower(uart_getc());
76 if (cmdbuf[i] == '\n' || cmdbuf[i] == '\r') 80 if (cmdbuf[i] == '\n' || cmdbuf[i] == '\r')
77 break; 81 break;
78 82
79 /* Backspace */ 83 /* Backspace/Delete */
80 if (cmdbuf[i] == 010) { 84 if (cmdbuf[i] == 0x08) {
81 if (i > 0) { 85 if (i > 0) {
82 uart_putsP(PSTR("\010\040\010")); 86 uart_putsP(PSTR("\010\040\010"));
83 i--; 87 i--;
84 } 88 }
85 continue; 89 continue;
108 "re Read a bit\n\r" 112 "re Read a bit\n\r"
109 "rb Read a byte\n\r" 113 "rb Read a byte\n\r"
110 "wr bit Write a bit\n\r" 114 "wr bit Write a bit\n\r"
111 "wb byte Write a byte (hex)\n\r" 115 "wb byte Write a byte (hex)\n\r"
112 "wc cmd [ROMID] Write command\n\r" 116 "wc cmd [ROMID] Write command\n\r"
113 "te ROMID Read the temperature from a DS1820\n\r")); 117 "te ROMID Read the temperature from a DS1820\n\r"
118 "le byte Set the LED port\n\r"));
114 119
115 continue; 120 continue;
116 } 121 }
117 122
118 if (i < 2) 123 if (i < 2)
170 for (i = 0; i < 8; i++) 175 for (i = 0; i < 8; i++)
171 ROM[i] = (int)strtol(cmdbuf + 6 + (3 * i), (char **)NULL, 16); 176 ROM[i] = (int)strtol(cmdbuf + 6 + (3 * i), (char **)NULL, 16);
172 177
173 OWSendCmd(ROM, arg); 178 OWSendCmd(ROM, arg);
174 } else if (cmdbuf[0] == 't' && cmdbuf[1] == 'e') { 179 } else if (cmdbuf[0] == 't' && cmdbuf[1] == 'e') {
175 uint8_t crc, buf[9];;
176 int8_t temp;
177 uint16_t tfrac;
178
179 if (strlen(cmdbuf) < 26) { 180 if (strlen(cmdbuf) < 26) {
180 uart_putsP(PSTR("Unable to parse ROM ID\n\r")); 181 uart_putsP(PSTR("Unable to parse ROM ID\n\r"));
181 continue; 182 continue;
182 } 183 }
183 184
292 uart_puts_hex(ROM[7]); 293 uart_puts_hex(ROM[7]);
293 uart_putsP(PSTR("\n\r")); 294 uart_putsP(PSTR("\n\r"));
294 295
295 i = OWNext(ROM, 1, 0); 296 i = OWNext(ROM, 1, 0);
296 } while (1); 297 } while (1);
298 } else if (cmdbuf[0] == 'l' && cmdbuf[1] == 'e') {
299 crc = (uint8_t)strtol(cmdbuf + 3, (char **)NULL, 16);
300 PORTA = crc;
301 #if 1
302 uart_putsP(PSTR("LEDs set to 0x"));
303 uart_puts_hex(crc);
304 uart_putsP(PSTR("\n\r"));
305 #endif
297 } else { 306 } else {
298 badcmd: 307 badcmd:
299 uart_putsP(PSTR("Unknown command, ? for a list\n\r")); 308 uart_putsP(PSTR("Unknown command, ? for a list\n\r"));
300 } 309 }
301 310