Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0820407

Browse files
committed
Renamed sketch filetype to .ino. Added Arduino Mega pinout into comment.
1 parent 617f324 commit 0820407

File tree

1 file changed

+50
-44
lines changed

1 file changed

+50
-44
lines changed

ArduinoISP/ArduinoISP.pde renamed to ArduinoISP/ArduinoISP.ino

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
// ArduinoISP version 04m2
1+
// ArduinoISP version 04m3
22
// Copyright (c) 2008-2011 Randall Bohn
33
// If you require a license, see
44
// http://www.opensource.org/licenses/bsd-license.php
55
//
6-
// this sketch turns the Arduino into a AVRISP
7-
// using the following pins:
8-
// 10: slave reset
9-
// 11: MOSI
10-
// 12: MISO
11-
// 13: SCK
12-
// (This is standard Arduino. Mega and others use different pins.)
13-
6+
// This sketch turns the Arduino into a AVRISP
7+
// using the following arduino pins:
8+
//
9+
// pin name: not-mega: mega(1280 and 2560)
10+
// slave reset: 10: 53
11+
// MOSI: 11: 51
12+
// MISO: 12: 50
13+
// SCK: 13: 52
14+
//
1415
// Put an LED (with resistor) on the following pins:
15-
// 9: Heartbeat - shows the programmer is running
16-
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
16+
// 9: Heartbeat - shows the programmer is running
17+
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
1718
// 7: Programming - In communication with the slave
1819
//
1920
// 23 July 2011 Randall Bohn
@@ -43,10 +44,10 @@
4344
// - More information at http://code.google.com/p/mega-isp
4445

4546
#include "pins_arduino.h"
46-
#define RESET SS
47+
#define RESET SS
4748

48-
#define LED_HB 9
49-
#define LED_ERR 8
49+
#define LED_HB 9
50+
#define LED_ERR 8
5051
#define LED_PMODE 7
5152
#define PROG_FLICKER true
5253

@@ -55,12 +56,12 @@
5556
#define SWMIN 18
5657

5758
// STK Definitions
58-
#define STK_OK 0x10
59-
#define STK_FAILED 0x11
59+
#define STK_OK 0x10
60+
#define STK_FAILED 0x11
6061
#define STK_UNKNOWN 0x12
61-
#define STK_INSYNC 0x14
62-
#define STK_NOSYNC 0x15
63-
#define CRC_EOP 0x20 //ok it is a space...
62+
#define STK_INSYNC 0x14
63+
#define STK_NOSYNC 0x15
64+
#define CRC_EOP 0x20 //ok it is a space...
6465

6566
void pulse(int pin, int times);
6667

@@ -110,7 +111,7 @@ void heartbeat() {
110111
analogWrite(LED_HB, hbval);
111112
delay(40);
112113
}
113-
114+
114115

115116
void loop(void) {
116117
// is pmode active?
@@ -119,7 +120,7 @@ void loop(void) {
119120
// is there an error?
120121
if (error) digitalWrite(LED_ERR, HIGH);
121122
else digitalWrite(LED_ERR, LOW);
122-
123+
123124
// light the heartbeat LED
124125
heartbeat();
125126
if (Serial.available()) {
@@ -187,7 +188,8 @@ void empty_reply() {
187188
if (CRC_EOP == getch()) {
188189
Serial.print((char)STK_INSYNC);
189190
Serial.print((char)STK_OK);
190-
} else {
191+
}
192+
else {
191193
error++;
192194
Serial.print((char)STK_NOSYNC);
193195
}
@@ -227,18 +229,18 @@ void get_version(uint8_t c) {
227229
void set_parameters() {
228230
// call this after reading paramter packet into buff[]
229231
param.devicecode = buff[0];
230-
param.revision = buff[1];
231-
param.progtype = buff[2];
232-
param.parmode = buff[3];
233-
param.polling = buff[4];
234-
param.selftimed = buff[5];
235-
param.lockbytes = buff[6];
236-
param.fusebytes = buff[7];
237-
param.flashpoll = buff[8];
232+
param.revision = buff[1];
233+
param.progtype = buff[2];
234+
param.parmode = buff[3];
235+
param.polling = buff[4];
236+
param.selftimed = buff[5];
237+
param.lockbytes = buff[6];
238+
param.fusebytes = buff[7];
239+
param.flashpoll = buff[8];
238240
// ignore buff[9] (= buff[8])
239241
// following are 16 bits (big endian)
240242
param.eeprompoll = beget16(&buff[10]);
241-
param.pagesize = beget16(&buff[12]);
243+
param.pagesize = beget16(&buff[12]);
242244
param.eepromsize = beget16(&buff[14]);
243245

244246
// 32 bits flashsize (big endian)
@@ -299,8 +301,8 @@ void commit(int addr) {
299301

300302
//#define _current_page(x) (here & 0xFFFFE0)
301303
int current_page(int addr) {
302-
if (param.pagesize == 32) return here & 0xFFFFFFF0;
303-
if (param.pagesize == 64) return here & 0xFFFFFFE0;
304+
if (param.pagesize == 32) return here & 0xFFFFFFF0;
305+
if (param.pagesize == 64) return here & 0xFFFFFFE0;
304306
if (param.pagesize == 128) return here & 0xFFFFFFC0;
305307
if (param.pagesize == 256) return here & 0xFFFFFF80;
306308
return here;
@@ -312,7 +314,8 @@ void write_flash(int length) {
312314
if (CRC_EOP == getch()) {
313315
Serial.print((char) STK_INSYNC);
314316
Serial.print((char) write_flash_pages(length));
315-
} else {
317+
}
318+
else {
316319
error++;
317320
Serial.print((char) STK_NOSYNC);
318321
}
@@ -383,7 +386,8 @@ void program_page() {
383386
if (CRC_EOP == getch()) {
384387
Serial.print((char) STK_INSYNC);
385388
Serial.print(result);
386-
} else {
389+
}
390+
else {
387391
error++;
388392
Serial.print((char) STK_NOSYNC);
389393
}
@@ -395,9 +399,9 @@ void program_page() {
395399

396400
uint8_t flash_read(uint8_t hilo, int addr) {
397401
return spi_transaction(0x20 + hilo * 8,
398-
(addr >> 8) & 0xFF,
399-
addr & 0xFF,
400-
0);
402+
(addr >> 8) & 0xFF,
403+
addr & 0xFF,
404+
0);
401405
}
402406

403407
char flash_read_page(int length) {
@@ -511,7 +515,7 @@ int avrisp() {
511515
case 0x64: //STK_PROG_PAGE
512516
program_page();
513517
break;
514-
518+
515519
case 0x74: //STK_READ_PAGE 't'
516520
read_page();
517521
break;
@@ -524,19 +528,19 @@ int avrisp() {
524528
end_pmode();
525529
empty_reply();
526530
break;
527-
531+
528532
case 0x75: //STK_READ_SIGN 'u'
529533
read_signature();
530534
break;
531535

532-
// expecting a command, not CRC_EOP
533-
// this is how we can get back in sync
536+
// expecting a command, not CRC_EOP
537+
// this is how we can get back in sync
534538
case CRC_EOP:
535539
error++;
536540
Serial.print((char) STK_NOSYNC);
537541
break;
538-
539-
// anything else we will return STK_UNKNOWN
542+
543+
// anything else we will return STK_UNKNOWN
540544
default:
541545
error++;
542546
if (CRC_EOP == getch())
@@ -546,3 +550,5 @@ int avrisp() {
546550
}
547551
}
548552

553+
554+

0 commit comments

Comments
 (0)