Mercurial > ~darius > hgwebdir.cgi > avr
comparison testavr.c @ 11:ccc39c9f320b
Enable pretty LED command.
author | darius |
---|---|
date | Fri, 16 Jul 2004 23:39:58 +0930 |
parents | eb1faf51968e |
children | 2c03ec600dbc |
comparison
equal
deleted
inserted
replaced
10:eb1faf51968e | 11:ccc39c9f320b |
---|---|
45 void uart_puts(const char *addr); | 45 void uart_puts(const char *addr); |
46 int uart_putc(char c); | 46 int uart_putc(char c); |
47 int uart_getc(void); | 47 int uart_getc(void); |
48 int beginswith_P(const char *s1, const char *s2); | 48 int beginswith_P(const char *s1, const char *s2); |
49 | 49 |
50 #if 0 | |
51 uint8_t PROGMEM ledvals[] = {0x01, 0x03, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0, 0xc0, 0x80}; | 50 uint8_t PROGMEM ledvals[] = {0x01, 0x03, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0, 0xc0, 0x80}; |
52 static uint8_t dir = 0; | 51 static uint8_t dir = 0; |
53 static volatile uint8_t leds = 0; | 52 static volatile uint8_t leds = 0; |
54 static uint8_t ledpos = 0; | 53 static uint8_t ledpos = 0; |
55 | 54 |
79 doleds: | 78 doleds: |
80 TCNT0 = 0; | 79 TCNT0 = 0; |
81 | 80 |
82 PORTA = pgm_read_byte(&ledvals[ledpos]); | 81 PORTA = pgm_read_byte(&ledvals[ledpos]); |
83 } | 82 } |
84 #endif | |
85 | 83 |
86 void | 84 void |
87 usleep(uint16_t usec) { | 85 usleep(uint16_t usec) { |
88 /* 4Mhz = 250ns per clock cycle */ | 86 /* 4Mhz = 250ns per clock cycle */ |
89 usec /= 2; | 87 usec /= 2; |
101 uint8_t ROM[8]; | 99 uint8_t ROM[8]; |
102 char cmdbuf[40]; | 100 char cmdbuf[40]; |
103 int i; | 101 int i; |
104 | 102 |
105 cli(); | 103 cli(); |
106 #if 0 | |
107 outp(0xff, DDRA); | 104 outp(0xff, DDRA); |
108 | 105 |
109 /* Timer Clock divisor - CK/1024 */ | 106 /* Timer Clock divisor - CK/1024 */ |
110 outp(BV(CS00) | BV(CS02), TCCR0); | 107 outp(BV(CS00) | BV(CS02), TCCR0); |
111 #endif | 108 |
112 outp(0xfe, DDRC); | 109 outp(0xfc, DDRC); |
113 outp(0x00, PORTC); | 110 outp(0x00, PORTC); |
114 | 111 |
115 /* Init UART */ | 112 /* Init UART */ |
116 outp(UART_BAUD_SELECT(UART_BAUD_RATE,XTAL_CPU), UBRR); | 113 outp(UART_BAUD_SELECT(UART_BAUD_RATE,XTAL_CPU), UBRR); |
117 | 114 |
118 /* Enable receiver and transmitter. Turn on transmit interrupts */ | 115 /* Enable receiver and transmitter. Turn on transmit interrupts */ |
119 outp(BV(RXEN) | BV(TXEN), UCR); | 116 outp(BV(RXEN) | BV(TXEN), UCR); |
120 | 117 |
118 #if 0 | |
119 int was; | |
120 uint32_t count; | |
121 | |
122 was = inp(PINC) & 0x02; | |
123 | |
124 count = 0; | |
125 while (1) { | |
126 if (was) { | |
127 if (!(inp(PINC) & 0x02)) { | |
128 sprintf_P(cmdbuf, PSTR("high -> low, i = %d\n\r"), count); | |
129 uart_puts(cmdbuf); | |
130 count = 0; | |
131 was = 0x00; | |
132 } | |
133 } else { | |
134 if ((inp(PINC) & 0x02)) { | |
135 sprintf_P(cmdbuf, PSTR("low -> high, i = %d\n\r"), count); | |
136 uart_puts(cmdbuf); | |
137 count = 0; | |
138 was = 0x02; | |
139 } | |
140 } | |
141 | |
142 count++; | |
143 } | |
144 #endif | |
145 | |
121 uart_putsP(PSTR("\n\r\n\r===============\n\r" | 146 uart_putsP(PSTR("\n\r\n\r===============\n\r" |
122 "Inited!\n\r\n\r")); | 147 "Inited!\n\r\n\r")); |
123 | 148 |
124 while (1) { | 149 while (1) { |
125 uart_putsP(PSTR("> ")); | 150 uart_putsP(PSTR("> ")); |
161 "re Read a bit\n\r" | 186 "re Read a bit\n\r" |
162 "rb Read a byte\n\r" | 187 "rb Read a byte\n\r" |
163 "wr bit Write a bit\n\r" | 188 "wr bit Write a bit\n\r" |
164 "wb byte Write a byte (hex)\n\r" | 189 "wb byte Write a byte (hex)\n\r" |
165 "wc cmd [ROMID] Write command\n\r" | 190 "wc cmd [ROMID] Write command\n\r" |
166 "te ROMID Read the temperature from a DS1820\n\r")); | 191 "te ROMID Read the temperature from a DS1820\n\r" |
192 "le Turn pretty LED cycling on\n\r")); | |
193 | |
167 continue; | 194 continue; |
168 } | 195 } |
169 | 196 |
170 if (i < 2) | 197 if (i < 2) |
171 goto badcmd; | 198 goto badcmd; |
330 ROM[7]); | 357 ROM[7]); |
331 uart_puts(cmdbuf); | 358 uart_puts(cmdbuf); |
332 | 359 |
333 i = OWNext(ROM, 1, 0); | 360 i = OWNext(ROM, 1, 0); |
334 } while (1); | 361 } while (1); |
335 | 362 } else if (cmdbuf[0] == 'l' && cmdbuf[1] == 'e') { |
336 #if 0 | |
337 | |
338 } else if (cmdbuf[0] == 'l' && cmdbuf[1] == 'e' && cmdbuf[2] == 'd') { | |
339 if (leds == 0) { | 363 if (leds == 0) { |
340 leds = 1; | 364 leds = 1; |
341 ledpos = 0; | 365 ledpos = 0; |
342 outp(0, TCNT0); | 366 outp(0, TCNT0); |
343 sbi(TIMSK, TOIE0); | 367 sbi(TIMSK, TOIE0); |
349 PORTA = 0x00; | 373 PORTA = 0x00; |
350 cbi(TIMSK, TOIE0); | 374 cbi(TIMSK, TOIE0); |
351 cli(); | 375 cli(); |
352 uart_putsP(PSTR("Stopping\n\r")); | 376 uart_putsP(PSTR("Stopping\n\r")); |
353 } | 377 } |
354 #endif | |
355 } else { | 378 } else { |
356 badcmd: | 379 badcmd: |
357 uart_putsP(PSTR("Unknown command, ? for a list\n\r")); | 380 uart_putsP(PSTR("Unknown command, ? for a list\n\r")); |
358 } | 381 } |
359 | 382 |