| Line 9... |
Line 9... |
| 9 |
* Last change....: 2009-02-28 |
9 |
* Last change....: 2009-02-28 |
| 10 |
* |
10 |
* |
| 11 |
* PC2 SCK speed option. |
11 |
* PC2 SCK speed option. |
| 12 |
* GND -> slow (8khz SCK), |
12 |
* GND -> slow (8khz SCK), |
| 13 |
* open -> software set speed (default is 375kHz SCK) |
13 |
* open -> software set speed (default is 375kHz SCK) |
| - |
|
14 |
* |
| - |
|
15 |
* 2014_02_09 miho@mlab.cz - cleaned code and defined IO port better, automatic compile prodcess for more target CPUs |
| - |
|
16 |
* |
| 14 |
*/ |
17 |
*/ |
| 15 |
|
18 |
|
| 16 |
#include <avr/io.h> |
19 |
#include <avr/io.h> |
| 17 |
#include <avr/interrupt.h> |
20 |
#include <avr/interrupt.h> |
| 18 |
#include <avr/pgmspace.h> |
21 |
#include <avr/pgmspace.h> |
| Line 42... |
Line 45... |
| 42 |
uchar len = 0; |
45 |
uchar len = 0; |
| 43 |
|
46 |
|
| 44 |
if (data[1] == USBASP_FUNC_CONNECT) { |
47 |
if (data[1] == USBASP_FUNC_CONNECT) { |
| 45 |
|
48 |
|
| 46 |
/* set SCK speed */ |
49 |
/* set SCK speed */ |
| 47 |
if ((PINC & (1 << PC2)) == 0) { |
50 |
if ((PIN(CLKSW_PORT) & (1 << CLKSW_BIT)) == 0) { |
| 48 |
ispSetSCKOption(USBASP_ISP_SCK_8); |
51 |
ispSetSCKOption(USBASP_ISP_SCK_8); |
| 49 |
} else { |
52 |
} else { |
| 50 |
ispSetSCKOption(prog_sck); |
53 |
ispSetSCKOption(prog_sck); |
| 51 |
} |
54 |
} |
| 52 |
|
55 |
|
| Line 301... |
Line 304... |
| 301 |
} |
304 |
} |
| 302 |
|
305 |
|
| 303 |
int main(void) { |
306 |
int main(void) { |
| 304 |
uchar i, j; |
307 |
uchar i, j; |
| 305 |
|
308 |
|
| 306 |
/* no pullups on USB and ISP pins */ |
309 |
/* unused pins with pullups */ |
| - |
|
310 |
PORTB = PORTB_UNUSED_MASK; |
| - |
|
311 |
PORTC = PORTC_UNUSED_MASK; |
| 307 |
PORTD = 0; |
312 |
PORTD = PORTD_UNUSED_MASK; |
| - |
|
313 |
|
| - |
|
314 |
/* LED ports as output */ |
| 308 |
PORTB = 0; |
315 |
ledInit(); |
| - |
|
316 |
ledGreenOn(); |
| - |
|
317 |
ledRedOff(); |
| - |
|
318 |
|
| 309 |
/* all outputs except PD2 = INT0 */ |
319 |
/* CLKSW input with PullUp (external jumper to GND) */ |
| 310 |
DDRD = ~(1 << 2); |
320 |
clkswInit(); |
| 311 |
|
321 |
|
| 312 |
/* output SE0 for USB reset */ |
322 |
/* output SE0 for USB reset */ |
| 313 |
DDRB = ~0; |
323 |
DDR(USB_CFG_IOPORTNAME) |= (1 << USB_CFG_DPLUS_BIT | 1<<USB_CFG_DMINUS_BIT); |
| 314 |
j = 0; |
324 |
|
| 315 |
/* USB Reset by device only required on Watchdog Reset */ |
325 |
/* USB Reset by device only required on Watchdog Reset */ |
| - |
|
326 |
j = 0; |
| 316 |
while (--j) { |
327 |
while (--j) { |
| 317 |
i = 0; |
328 |
i = 0; |
| 318 |
/* delay >10ms for USB reset */ |
329 |
/* delay >10ms for USB reset */ |
| 319 |
while (--i) |
330 |
while (--i) |
| 320 |
; |
331 |
; |
| 321 |
} |
332 |
} |
| 322 |
/* all USB and ISP pins inputs */ |
- |
|
| 323 |
DDRB = 0; |
- |
|
| 324 |
|
333 |
|
| 325 |
/* all inputs except PC0, PC1 */ |
334 |
/* all USB and ISP pins inputs */ |
| 326 |
DDRC = 0x03; |
- |
|
| 327 |
PORTC = 0xfe; |
335 |
DDR(USB_CFG_IOPORTNAME) &= ~(1 << USB_CFG_DPLUS_BIT | 1<<USB_CFG_DMINUS_BIT); |
| 328 |
|
336 |
|
| 329 |
/* init timer */ |
337 |
/* init timer */ |
| 330 |
clockInit(); |
338 |
clockInit(); |
| 331 |
|
339 |
|
| 332 |
/* main event loop */ |
340 |
/* main event loop */ |
| Line 335... |
Line 343... |
| 335 |
for (;;) { |
343 |
for (;;) { |
| 336 |
usbPoll(); |
344 |
usbPoll(); |
| 337 |
} |
345 |
} |
| 338 |
return 0; |
346 |
return 0; |
| 339 |
} |
347 |
} |
| 340 |
|
- |
|