2009年5月19日 星期二

Dot matrix watch

Use a Atmeg8 with bootloader to make a dot matric watch. Basic circuit is the same but two push switches are added for hour and minute adjustment.

1. Connect the LED matrix, Arduino NG and the resistors.

* Pin Assignments are as follows:
*
* 8x8 LED ----------------> Atmega8 (with bootloader)
* 1 --------------------------> 3....D1 (connect to 220 ohm resistor between LED and Arduino)
* 2 --------------------------> 4....D2
* 3 --------------------------> 5....D3
* 4 --------------------------> 6....D4
* 5 --------------------------> 11..D5
* 6 --------R220-----------> 12..D6
* 7 --------------------------> 13..D7
* 8 --------------------------> 14..D8
* 9 --------------------------> 15..D9
* 10 -------R220----------> 16..D10
* 11 ------------------------> 17..D11
* 12 ------------------------> 18..D12
* 13 ------------------------> 19..D13
* 14 ------------------------> 23..D14(A0)
* 15 -------R220----------> 24..D15(A1)
* 16 -------R220----------> 25..D16(A2)

8x8 LED - pin assignment
9...|-----------------------|.8
10.|............................|.7
11.|............................|.6
12.|............................|.5
13.|............................|.4
14.|............................|.3
15.|............................|.2
16.|-----------------------|.1

Two switches connected as follows:
+5V------>R10K----->Atmega 8 pin 27----->switch A----->GND (hour switch)
+5V------>R10K----->Atmega 8 pin 28----->switch B----->GND (minute switch)

2. Insert Atmeg8(with bootloader) into the Arduino and download the following script into the Atmega8
/* Dot Watch Code
**
* Main Components:
* Atmega8
* 8x8 LED Matrix
*
* Pin Assignments
*
* 8x8 LED -> Atmega8
* 1 -> D1:
* 2 -> D2 :
* 3 -> D3:
* 4 -> D4:
* 5 -> D5:
* 6* -> D6: add 200 Ohm resistor
* 7 -> D7:
* 8 -> D8:
* 9 -> D9:
* 10* -> D10: add 200 Ohm resistor
* 11 -> D11:
* 12 -> D12:
* 13 -> D13:
* 14 -> D14 A(0):
* 15* -> D15 A(1): add 200 Ohm resistor
* 16* -> D16 A(2): add 200 Ohm resistor
*
* row # LED pin #
________________________________
* 0 5 I I
* 1 11 I I
* 2 12 I LED I
* 3 2 I MATRIX I
* 4 14 I Ark SZ411288k I
* 5 3 I I
* 6 7 I I
* 7 8 I________________________________I
* LED pin # 13 10 15 9 4 16 6 1
* Col # 0 1 2 3 4 5 6 7
*
*
* Pin # Pin #
* _________________________________
* M I 8+ +9 I
* A I 7+ +10 I
* R I 6+ LED +11 I
* K I 5+ MATRIX +12 I
* I I 4+ Ark SZ411288k +13 I
* N I 3+ +14 I
* G I 2+ +15 I
* I 1+ I
* I________________________________I
*
*
*/

#define millisOverflow 34359738

unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
int valm=0,valh=0;

int ticks = 0;
// The Dot Watch always starts operation @ 1258 hrs
int seconds = 29;
int minutes = 19;
int hours = 12;

// Set LED pins[x] for Arduino pins
int pin[17] = {-1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};

// Set LED columns
int col[8] = {pin[13], pin[10], pin[15], pin[9], pin[4], pin[16], pin[6], pin[1]};

// Set LED rows
int row[8] = {pin[5], pin[11], pin[12], pin[2], pin[14], pin[3], pin[7], pin[8]};

void displayFlash() {
// Pulse four columns as seconds ticker
// Set columns 0, 3, 4, & 7 ON
digitalWrite(col[0], HIGH);
digitalWrite(col[3], HIGH);
digitalWrite(col[4], HIGH);
digitalWrite(col[7], HIGH);
digitalWrite(col[2], LOW);
//}
// Turn each row ON, then OFF
for (int i=0; i<8; i++) {
pinMode(row[i], OUTPUT);
delay (100);
pinMode(row[i], INPUT);
}
// Set columns 0, 3, 4, & 7 OFF
digitalWrite(col[0], LOW);
digitalWrite(col[3], LOW);
digitalWrite(col[4], LOW);
digitalWrite(col[7], LOW);
//}
}

void displayTime(int displayHours, int displayMinutes) {
// Columns 1 & 2 are used for hours
// Column 1 = 5 hour increments
// Column 2 = 1 hour increments
// Columns 5 & 6 are used for minutes
// Column 5 = 10 minute increments
// Column 6 = 2 minute increments
int displayHoursCol1 = 0;
int displayHoursCol2 = 0;
int displayMinutesCol1 = 0;
int displayMinutesCol2 = 0;

// Setup hours first
// Use division & modulo division for determining hour rows
displayHoursCol1 = displayHours / 5;
displayHoursCol2 = displayHours % 5;
// Setup minutes
// Use division & modulo division for determining minute rows
displayMinutesCol1 = displayMinutes / 10;
displayMinutesCol2 = displayMinutes % 10;
switch(displayMinutesCol2) {
case 1:
displayMinutesCol2 = 1;
break;
case 2:
displayMinutesCol2 = 1;
break;
case 3:
displayMinutesCol2 = 2;
break;
case 4:
displayMinutesCol2 = 2;
break;
case 5:
displayMinutesCol2 = 3;
break;
case 6:
displayMinutesCol2 = 3;
break;
case 7:
displayMinutesCol2 = 4;
break;
case 8:
displayMinutesCol2 = 4;
break;
case 9:
displayMinutesCol2 = 5;
break;
}

// Loop through the display of the LED hours+minutes
int counter=0;
do
{
// Determine which rows to light for hours
// Start with Column 2
digitalWrite(col[2], HIGH);
for (int dot=0; dot pinMode(row[6-dot], OUTPUT);
delay(1);
pinMode(row[6-dot], INPUT);
}
digitalWrite(col[2], LOW);
delay(3);
// Now Column 1
digitalWrite(col[1], HIGH);
for (int dot=0; dot pinMode(row[6-dot], OUTPUT);
delay(1);
pinMode(row[6-dot], INPUT);
}
digitalWrite(col[1], LOW);
delay(3);
// Now display the minutes
// Start with Column 6
digitalWrite(col[6], HIGH);
for (int dot=0; dot pinMode(row[6-dot], OUTPUT);
delay(1);
pinMode(row[6-dot], INPUT);
}
digitalWrite(col[6], LOW);
delay(3);
// Now display Column 5 minutes
digitalWrite(col[5], HIGH);
for (int dot=0; dot pinMode(row[6-dot], OUTPUT);
delay(1);
pinMode(row[6-dot], INPUT);
}
digitalWrite(col[5], LOW);
delay(3);

counter = counter + 1;

} while (counter<100);
}

void setup() {
// Set Arduino column pins for LED
for (int i=0; i<17; i++) {
pinMode(pin[i], OUTPUT);
}
// Set column pins LOW
for (int i=0; i<8; i++) {
digitalWrite(col[i], LOW);
}
// Set row pins OFF
for (int i=0; i<8; i++) {
pinMode(row[i], INPUT);
}
}

void loop() {
// Begin program
// Start Clock
// Increment clock seconds and calculate minutes & hours
currentMillis = millis();
// Check for millis overflow @ approx 9.5 hrs
if (currentMillis < previousMillis) {
ticks += millisOverflow - previousMillis + currentMillis;
}
else
{
ticks += currentMillis - previousMillis;
}

seconds += ticks / 993; //seconds += ticks / 1000
ticks = ticks % 993;

// flash LED for each second
digitalWrite(col[2], HIGH);
pinMode(row[1], OUTPUT);
delay(5);
pinMode(row[1], INPUT);

if (seconds >= 60) {
minutes++;
seconds = 0;
}
if (minutes >= 60) {
hours = hours + 1;
minutes = 0;
}
if (hours > 12) {
hours = 1;
}
// Flash the watch, then display the time
if (minutes == 0){
displayFlash();
}
if (minutes == 15){
displayFlash();
}
if (minutes == 30){
displayFlash();
}
if (minutes == 45){
displayFlash();
}

displayTime(hours, minutes);

previousMillis = currentMillis;

valm = analogRead(5); // add one minute when pressed
if(valm<400) {
minutes=minutes+2;
seconds=0;
delay(1);
}

valh = analogRead(4); // add one hour when pressed
if(valh<400) {
hours++;
seconds=0;
delay(50);
}


}



3. Pull out the Atmega8 and insert into the circuit board.

4. Connect the battery and wait for a few seconds.

5. Adjust the time using switches A and B.

2009年3月23日 星期一

Adurino Dot Watch

The Dot Watch is driven by an ArduinoNG with Atmega8. Dot Watch uses a 8x8 LED matrix to displace the current time. Four columns of LED matrix are used for displaying time in a 24-hour format.

  • Columns 1 & 2 are used for hours.
    • Column 1 represents 5 hour increments
    • Column 2 uses 1 hour increments
  • Columns 5 & 6 are used for the minutes.
    • Column 5 shows minutes in 10-minute increments
    • Column 6 flashes the minutes in 2-minute increments
Check : http://www.popsci.com/diy/article/2009-02/dot-%E2%80%A2-watch?page=1



1. Connect the LED matrix, Arduino NG and the resistors.

* Pin Assignments are as follows:
*
* 8x8 LED ----------------> Atmega8
* 1 -----------R220--------> D16 A(2): (connect to 220 ohm resistor between LED and Arduino)
* 2 --------------------------> D15 (A1) :
* 3 --------------------------> D14 (A0):
* 4 -----------R220--------> D13:
* 5 --------------------------> D12:
* 6 -----------R220--------> D11 :
* 7 --------------------------> D10 :
* 8 --------------------------> D9 :
* 9 -----------R220--------> D7 :
* 10 ---------R220--------> D6 :
* 11 ------------------------> D5 :
* 12 ------------------------> D4 :
* 13 ---------R220--------> D3 :
* 14 ------------------------> D2 :
* 15 ---------R220--------> D1 :
* 16 ---------R220--------> D0 :

2. Connect the USB cable to the Arduino NG and the computer.

3. Download the following sketch into the Arduino NG and wait for a few seconds. Dot Watch begins to work.
/* Dot Watch Code **
* Main Components:

* Atmega8
* 8x8 LED Matrix
*
* Pin Assignments *
* 8x8 LED -> Atmega8

* 1 -> D16 A(2):
* 2 -> D15 (A1) :
* 3 -> D14 (A0):
* 4 -> D13:
* 5 -> D12:
* 6 -> D11 :
* 7 -> D10 :
* 8 -> D9 :

* 9 -> D7 :
* 10 -> D6 :
* 11 -> D5 :

* 12 -> D4 :
* 13 -> D3 :
* 14 -> D2 :
* 15 -> D1 :

* 16 -> D0 : *
* row # LED pin # ________________________________
*...... 0...... 5........I
............................................................... I
* ......1.......1........I................................................................I
* ......2.....12........I......LED...................................................I
* ......3...... 2........I......MATRIX............................................I
* ......4.... 14........I......Ark SZ411288k..................................I
* ......5...... 3........I............................................................... I

* ......6...... 7
........I............................................................... I
* ......7...... 8........I________________________________I
* .......LED pin #.......13...10...15....9....4.....16.....6.....1

* .......Col #............... 0.....1.....2....3....4.......5.....6.....7

*/

#define millisOverflow 34359738

unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
int valm=0,valh=0;

int ticks = 0;
int seconds = 29;
int minutes = 58;
// The Dot Watch always starts operation @ 1258 hrs
int hours = 12;

// Set LED pins[x] for Arduino pins
int pin[17] = {-1, 16, 15, 14, 13, 12, 11, 10, 9, 7, 6, 5, 4, 3, 2, 1, 0};

// Set LED columns
int col[8] = {pin[13], pin[10], pin[15], pin[9], pin[4], pin[16], pin[6], pin[1]};

// Set LED rows
int row[8] = {pin[5], pin[11], pin[12], pin[2], pin[14], pin[3], pin[7], pin[8]};

void displayFlash() {
// Pulse four columns as seconds ticker
// Set columns 0, 3, 4, & 7 ON
digitalWrite(col[0], HIGH);
digitalWrite(col[3], HIGH);
digitalWrite(col[4], HIGH);
digitalWrite(col[7], HIGH);
//}
// Turn each row ON, then OFF
for (int i=0; i<8; 1 =" 5" 2 =" 1" 5 =" 10" 6 =" 2" displayhourscol1 =" 0;" displayhourscol2 =" 0;" displayminutescol1 =" 0;" displayminutescol2 =" 0;" displayhourscol1 =" displayHours" displayhourscol2 =" displayHours" displayminutescol1 =" displayMinutes" displayminutescol2 =" displayMinutes" displayminutescol2 =" 1;" displayminutescol2 =" 1;" displayminutescol2 =" 2;" displayminutescol2 =" 2;" displayminutescol2 =" 3;" displayminutescol2 =" 3;" displayminutescol2 =" 4;" displayminutescol2 =" 4;" displayminutescol2 =" 5;" counter="0;" dot="0;" now="" column="" 1="" for="" int="" dot="0;"><100); i="0;" i="0;" i="0;" currentmillis =" millis();" ticks =" ticks">= 60) {
minutes++;
seconds = 0;
}
if (minutes >= 60) {
hours = hours + 1;
minutes = 0;
}
if (hours > 23) {
hours = 0;
}
// Flash the watch, then display the time
if (minutes == 0){
displayFlash();
}
if (minutes == 15){
displayFlash();
}
if (minutes == 30){
displayFlash();
}
if (minutes == 45){
displayFlash();
}

displayTime(hours, minutes);

previousMillis = currentMillis;
/*
valm = analogRead(5);
// add one minute when pressed
if(valm<800) minutes="minutes+2;" seconds="0;" valh =" analogRead(4);" seconds="0;" now="" column="" 1="" for="" int="" dot="0;">); } */ }


2009年3月16日 星期一

Binary clock with Arduino

I just made a binary clock with Arduino.
see http://www.danielandrade.net/2008/07/15/binary-clock-with-arduino/





I will use 'Atmega8 with bootloader' to make a simplier one later.

2009年3月15日 星期日

Use LCD4bit with 'Atmega8 with bootloader' and LCD

1. First write 'bootloader' into Atmega8 with 'Arduino bootloader copier'.

2. Insert 'Atmega8 with bootloader' onto Arduino NG board and download LCD sketch into the Atmega8 chip.


3. Remove the Atmega8 chip from the Arduino NG board and insert the Atmega8 chip onto breadboard with LCD, 16 MHz crystal, capacitors, reset resistor, etc, as shown.


---Arduino------LCD---- LCD pin----Atmega8 pin
----------2-------enable-----6--------------4
----------7-------DB4-------11-------------13
----------8-------DB5-------12-------------14
----------9-------DB6-------13-------------15
----------10-----DB7-------14-------------16
----------12-----DI (RS)----4--------------18
---------GND---RW--------5---------------8,22
-----------------------------------------------9----->16 MHz Xtal --->22pF--->GND
-----------------------------------------------10--->16
MHz Xtal --->22pF--->GND
-----------------------------------------------1-----> 6K resistor---> 5V






4. Connect the 5V supply to the breadboard and wait for a few second for Atmega8 to reset.

IT WORKS ! ! !

2009年3月4日 星期三

Arduino AVR programmer - AVRISP

Use Arduino as a AVR programmer to burn the AVR

Circuit
Connect the Arduino Duemilanove and the AVR chip and LEDs as follows:

Arduino..............AVR................LED
Pin 13..................SCK
Pin 12..................MISO
Pin 11..................MOSI
Pin 10..................Reset
+5V......................VCC
GND.....................GND
Pin 9.............................................Communication
LED.....+ 330 ohm-->GND
Pin 8.............................................Error LED....................... + 330 ohm --> GND
Pin 7.............................................Heartbeat LED...............+ 330 ohm --> GND

Upload the follwoing sketch into the Arduino Duemilanove. I am using Arduino version 0011 IDE.
// this sketch turns the Arduino into a AVRISP
// using the following pins:
// 10: slave reset
// 11: MOSI
// 12: MISO
// 13: SCK

// Put an LED (with resistor) on the following pins:
// 9: Heartbeat - shows the programmer is running
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the slave
//
// February 2009 by Randall Bohn
// - Added support for writing to EEPROM (what took so long?)
// Windows users should consider WinAVR's avrdude instead of the
// avrdude included with Arduino software.
//
// January 2008 by Randall Bohn
// - Thanks to Amplificar for helping me with the STK500 protocol
// - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader
// - The SPI functions herein were developed for the AVR910_ARD programmer
// - More information at http://code.google.com/p/mega-isp

#define SCK 13
#define MISO 12
#define MOSI 11
#define RESET 10

#define LED_HB 9
#define LED_ERR 8
#define LED_PMODE 7

#define HWVER 2
#define SWMAJ 1
#define SWMIN 18

// STK Definitions
#define STK_OK 0x10
#define STK_FAILED 0x11
#define STK_UNKNOWN 0x12
#define STK_INSYNC 0x14
#define STK_NOSYNC 0x15
#define CRC_EOP 0x20 //ok it is a space...

void pulse(int pin, int times);

void setup() {
// 19200?
Serial.begin(19200);
pinMode(7, OUTPUT);
pulse(7, 2);
pinMode(8, OUTPUT);
pulse(8, 2);
pinMode(9, OUTPUT);
pulse(9, 2);
}

int error=0;
int pmode=0;
// address for reading and writing, set by 'U' command
int here;
uint8_t buff[256]; // global block storage

#define beget16(addr) (*addr * 256 + *(addr+1) )
typedef struct param {
uint8_t devicecode;
uint8_t revision;
uint8_t progtype;
uint8_t parmode;
uint8_t polling;
uint8_t selftimed;
uint8_t lockbytes;
uint8_t fusebytes;
int flashpoll;
int eeprompoll;
int pagesize;
int eepromsize;
int flashsize;
}
parameter;

parameter param;

// this provides a heartbeat on pin 9, so you can tell the software is running.
uint8_t hbval=128;
int8_t hbdelta=8;
void heartbeat() {
if (hbval > 192) hbdelta = -hbdelta;
if (hbval < hbdelta =" -hbdelta;" x =" 0;" spcr =" 0x53;" x="SPSR;" x="SPDR;" spdr="b;" reply =" SPDR;" n="spi_send(b);" error =" -1;" n="spi_send(c);" crc_eop ="=" crc_eop ="=" devicecode =" buff[0];" revision =" buff[1];" progtype =" buff[2];" parmode =" buff[3];" polling =" buff[4];" selftimed =" buff[5];" lockbytes =" buff[6];" fusebytes =" buff[7];" flashpoll =" buff[8];" eeprompoll =" beget16(&buff[10]);" pagesize =" beget16(&buff[12]);" eepromsize =" beget16(&buff[14]);" flashsize =" buff[16]" pmode =" 1;" pmode =" 0;" w =" 0;" ch =" spi_transaction(buff[0],">>8 & 0xFF,
addr & 0xFF,
data);
}
void commit(int addr) {
spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0);
}

//#define _current_page(x) (here & 0xFFFFE0)
int current_page(int addr) {
if (param.pagesize == 32) return here & 0xFFFFFFF0;
if (param.pagesize == 64) return here & 0xFFFFFFE0;
if (param.pagesize == 128) return here & 0xFFFFFFC0;
if (param.pagesize == 256) return here & 0xFFFFFF80;
return here;
}
uint8_t write_flash(int length) {
if (param.pagesize < page =" current_page(here);" x =" 0;" page =" current_page(here);" x =" 0;" result =" (char)" length =" 256"> 256) {
Serial.print((char) STK_FAILED);
return;
}
char memtype = getch();
for (int x = 0; x < crc_eop ="=" memtype ="=" result =" (char)write_flash(length);" memtype ="=" result =" (char)write_eeprom(length);">> 8) & 0xFF,
addr & 0xFF,
0);
}

char flash_read_page(int length) {
for (int x = 0; x < low =" flash_read(LOW," high =" flash_read(HIGH," x =" 0;" ee =" spi_transaction(0xA0," result =" (char)STK_FAILED;" length =" 256" memtype =" getch();" memtype ="=" result =" flash_read_page(length);" memtype ="=" result =" eeprom_read_page(length);" ch =" getch();" here =" getch()" low =" getch();" high =" getch();" data =" getch();" error="0;" crc_eop ="=">

You can start using AVRDUDE with this Arduino Duemilanove. First you need to know which port the Arduino is using. Mine is on port com5. You can run the following command line and read the device signature (0×1e910a).

> avrdude -P com5 -p t2313 -c avrisp -b 19200 -u -t

Enter ’sig’ to view the device signature again:

avrdude> sig
Reading | ################################## | 100% 0.02s
Device signature = 0×1e910a

Congratuation ! You have constructed an AVR programmer !!!

You can then develop your program using CodeVisionAVR and debug/simulate the program using AVRStudio.

The program can then be transform into HEX file by CodeVisionAVR.

The HEX file can then be written into the flash of the AVR (e.g. ATTINY2313) using AVRDUDE.

Type the following command line to write the program 'XXXX.hex' into the flash of t2313
> avrdude
-P com5 -p t2313 -c avrisp -b 19200 -U flash:w:XXXX.hex
see tutorial in using avrdude : - http://www.ladyada.net/learn/avr/avrdude.html


Check also: - http://www.uchobby.com/index.php/2007/11/04/arduino-avr-in-system-programmer-isp/

2009年2月28日 星期六

Arduino Bootloader Copier

If you need more than one Arduino, you can build this cheaper Arduino by copying the bootloader into the Atmega8 using the following circuit.




Photo shows the Arduino Bootloader copier. I am using a Duemilanove.

In Arduino version 0011 IDE, select BOARD = Arduino Diecimila. Upload the script to the Duemilanove.



The script is as follows:
/* ARDUINO BOOT-CLONER
* -------------------
*
* Comments
*
* The ATmega8 fuse bytes and bootloader are copied
* from the chip on the Arduino, to a new blank ATmega8.
*
* / See app note DOC0943.pdf "AVR910: In-System Programming"
* / See app note DOC2486.pdf "ATmega8 Documentation" - The chapter on Memory Programming, p.237/240
* / iHex flash file format information "http://www.scienceprog.com/shelling-the-intel-8-bit-hex-file-format/"
* / PROGMEM and pgmspace.h usage information:
* "http://www.scienceprog.com/simple-routine-how-to-store-data-in-microcontroller-flash-and-read-from-it-using-winavr/"
*
* Notes:
* Contrary to what I originally thought, the bootloader resides at the end of flash memory.
*
* The program was too big, so some of the extra functions are commented out to save memory.
*
* This program hasn't been optimized for speed, but it's still pretty quick. Some of the delays are unnecessary.
*
* Your bootloader flash probably can't be read; the default lock bits prevent that. (0xCF ~ bit 6)
* This boot-cloner writes different lock bits to the new ATmega8; so the boot flash section *could* be read
* when run from the new chip. (0xEF)
* With the bootloader flash unlocked, you could remove the bootloader[] table and save a bunch of memory.
*
* (copyright notice) 2007 by Amplificar
*/

// need this header for PROGMEM and the command pgm_read_byte()
// which reads bytes from flash program memory.
// you can view the header's contents, which are in arduino->tools->avr->avr->include->avr->pgmspace.h
#include

// CONSTANT DECLARATION

// target microcontroller constants
#define FLASH_MAX 8192
// the flash size
#define PAGE_WORDS 32
// the number of words per page
#define BOOT_PAGE 112
// the starting page number, where the bootloader lurks (8192/2/32=128, 1024/2/32=16, 128-16=112)

// the bootloader data; distributed with arduino ide 0005
// this is the extracted data from the ihex file
// PROGMEM forces this data to be kept in the flash - and not get loaded into ram (that'd be bad)
// this table has to be read back using "byte=pgm_read_byte(&bootloader[index]);"
#define BOOT_MAX 1019
const unsigned char bootloader[] PROGMEM= {
0x12,0xC0,0x2B,0xC0,0x2A,0xC0,0x29,0xC0,0x28,0xC0,0x27,0xC0,0x26,0xC0,0x25,0xC0,
0x24,0xC0,0x23,0xC0,0x22,0xC0,0x21,0xC0,0x20,0xC0,0x1F,0xC0,0x1E,0xC0,0x1D,0xC0,
0x1C,0xC0,0x1B,0xC0,0x1A,0xC0,0x11,0x24,0x1F,0xBE,0xCF,0xE5,0xD4,0xE0,0xDE,0xBF,
0xCD,0xBF,0x10,0xE0,0xA0,0xE6,0xB0,0xE0,0xE6,0xEF,0xFF,0xE1,0x02,0xC0,0x05,0x90,
0x0D,0x92,0xA2,0x36,0xB1,0x07,0xD9,0xF7,0x11,0xE0,0xA2,0xE6,0xB0,0xE0,0x01,0xC0,
0x1D,0x92,0xAA,0x36,0xB1,0x07,0xE1,0xF7,0x4B,0xC0,0xD2,0xCF,0xEF,0x92,0xFF,0x92,
0x0F,0x93,0x1F,0x93,0xEE,0x24,0xFF,0x24,0x87,0x01,0x5F,0x99,0x15,0xC0,0x08,0x94,
0xE1,0x1C,0xF1,0x1C,0x01,0x1D,0x11,0x1D,0x81,0xE0,0xE8,0x16,0x82,0xE1,0xF8,0x06,
0x8A,0xE7,0x08,0x07,0x80,0xE0,0x18,0x07,0x28,0xF0,0xE0,0x91,0x62,0x00,0xF0,0x91,
0x63,0x00,0x09,0x95,0x5F,0x9B,0xEB,0xCF,0x8C,0xB1,0x99,0x27,0x87,0xFD,0x90,0x95,
0x1F,0x91,0x0F,0x91,0xFF,0x90,0xEF,0x90,0x08,0x95,0x5D,0x9B,0xFE,0xCF,0x8C,0xB9,
0x08,0x95,0xD4,0xDF,0x80,0x32,0x21,0xF4,0x84,0xE1,0xF7,0xDF,0x80,0xE1,0xF5,0xDF,
0x08,0x95,0x08,0x95,0xCF,0x93,0xC8,0x2F,0xC9,0xDF,0x80,0x32,0x31,0xF4,0x84,0xE1,
0xEC,0xDF,0x8C,0x2F,0xEA,0xDF,0x80,0xE1,0xE8,0xDF,0xCF,0x91,0x08,0x95,0xCF,0x93,
0x88,0x23,0x21,0xF0,0xC8,0x2F,0xBA,0xDF,0xC1,0x50,0xE9,0xF7,0xCF,0x91,0x08,0x95,
0xCF,0xE5,0xD4,0xE0,0xDE,0xBF,0xCD,0xBF,0x00,0x00,0x10,0xBC,0x83,0xE3,0x89,0xB9,
0x88,0xE1,0x8A,0xB9,0x86,0xE8,0x80,0xBD,0xBD,0x9A,0x10,0x92,0x68,0x01,0x30,0xE2,
0x2F,0xE0,0x88,0xB3,0x83,0x27,0x88,0xBB,0x80,0xE0,0x90,0xE0,0x01,0x97,0xF1,0xF7,
0x21,0x50,0x27,0xFF,0xF6,0xCF,0x20,0xE1,0x20,0x93,0x68,0x01,0x97,0xDF,0x80,0x33,
0x09,0xF4,0x44,0xC0,0x81,0x33,0xA1,0xF4,0x91,0xDF,0xC8,0x2F,0x80,0x32,0xB1,0xF7,
0x84,0xE1,0xB3,0xDF,0x81,0xE4,0xB1,0xDF,0x86,0xE5,0xAF,0xDF,0x82,0xE5,0xAD,0xDF,
0x8C,0x2F,0xAB,0xDF,0x89,0xE4,0xA9,0xDF,0x83,0xE5,0xA7,0xDF,0x80,0xE5,0x2E,0xC1,
0x80,0x34,0x29,0xF4,0x7B,0xDF,0x86,0x38,0x48,0xF1,0x78,0xDF,0x27,0xC0,0x81,0x34,
0x71,0xF4,0x74,0xDF,0x80,0x38,0x11,0xF4,0x82,0xE0,0x28,0xC1,0x81,0x38,0x11,0xF4,
0x81,0xE0,0x24,0xC1,0x82,0x38,0x09,0xF0,0x20,0xC1,0x82,0xE1,0x1F,0xC1,0x82,0x34,
0x11,0xF4,0x84,0xE1,0x03,0xC0,0x85,0x34,0x19,0xF4,0x85,0xE0,0xA0,0xDF,0x0E,0xC0,
0x80,0x35,0x61,0xF0,0x81,0x35,0x51,0xF0,0x82,0x35,0x41,0xF0,0x85,0x35,0x41,0xF4,
0x55,0xDF,0x80,0x93,0x64,0x00,0x52,0xDF,0x80,0x93,0x65,0x00,0x7A,0xDF,0xB6,0xCF,
0x86,0x35,0x19,0xF4,0x84,0xE0,0x8B,0xDF,0x00,0xC1,0x84,0x36,0x09,0xF0,0x9D,0xC0,
0x45,0xDF,0x80,0x93,0x67,0x01,0x42,0xDF,0x80,0x93,0x66,0x01,0x80,0x91,0x69,0x01,
0x8E,0x7F,0x80,0x93,0x69,0x01,0x3A,0xDF,0x85,0x34,0x29,0xF4,0x80,0x91,0x69,0x01,
0x81,0x60,0x80,0x93,0x69,0x01,0xC0,0xE0,0xD0,0xE0,0x80,0x91,0x66,0x01,0x90,0x91,
0x67,0x01,0xC8,0x17,0xD9,0x07,0x70,0xF4,0x06,0xE6,0x10,0xE0,0x27,0xDF,0xF8,0x01,
0x81,0x93,0x8F,0x01,0x21,0x96,0x80,0x91,0x66,0x01,0x90,0x91,0x67,0x01,0xC8,0x17,
0xD9,0x07,0xA0,0xF3,0x1B,0xDF,0x80,0x32,0x09,0xF0,0x80,0xCF,0x80,0x91,0x69,0x01,
0x80,0xFF,0x26,0xC0,0xC0,0xE0,0xD0,0xE0,0x80,0x91,0x66,0x01,0x90,0x91,0x67,0x01,
0xC8,0x17,0xD9,0x07,0x08,0xF0,0x5F,0xC0,0x06,0xE6,0x10,0xE0,0xF8,0x01,0x61,0x91,
0x8F,0x01,0x80,0x91,0x64,0x00,0x90,0x91,0x65,0x00,0xC2,0xD0,0x80,0x91,0x64,0x00,
0x90,0x91,0x65,0x00,0x01,0x96,0x90,0x93,0x65,0x00,0x80,0x93,0x64,0x00,0x21,0x96,
0x80,0x91,0x66,0x01,0x90,0x91,0x67,0x01,0xC8,0x17,0xD9,0x07,0x38,0xF3,0x43,0xC0,
0xF8,0x94,0xE1,0x99,0xFE,0xCF,0x11,0x27,0xE0,0x91,0x64,0x00,0xF0,0x91,0x65,0x00,
0xEE,0x0F,0xFF,0x1F,0xC6,0xE6,0xD0,0xE0,0x80,0x91,0x66,0x01,0x90,0x91,0x67,0x01,
0x80,0xFF,0x01,0xC0,0x01,0x96,0x10,0x30,0x51,0xF4,0x22,0xD0,0x03,0xE0,0x00,0x93,
0x57,0x00,0xE8,0x95,0x1D,0xD0,0x01,0xE1,0x00,0x93,0x57,0x00,0xE8,0x95,0x09,0x90,
0x19,0x90,0x16,0xD0,0x01,0xE0,0x00,0x93,0x57,0x00,0xE8,0x95,0x13,0x95,0x10,0x32,
0x58,0xF0,0x11,0x27,0x0D,0xD0,0x05,0xE0,0x00,0x93,0x57,0x00,0xE8,0x95,0x08,0xD0,
0x01,0xE1,0x00,0x93,0x57,0x00,0xE8,0x95,0x32,0x96,0x02,0x97,0x39,0xF0,0xDB,0xCF,
0x00,0x91,0x57,0x00,0x01,0x70,0x01,0x30,0xD9,0xF3,0x08,0x95,0x10,0x30,0x11,0xF0,
0x02,0x96,0xE7,0xCF,0x11,0x24,0x84,0xE1,0x59,0xC0,0x84,0x37,0x09,0xF0,0x49,0xC0,
0xA5,0xDE,0x80,0x93,0x67,0x01,0xA2,0xDE,0x80,0x93,0x66,0x01,0x9F,0xDE,0x90,0x91,
0x69,0x01,0x85,0x34,0x21,0xF4,0x91,0x60,0x90,0x93,0x69,0x01,0x0D,0xC0,0x9E,0x7F,
0x90,0x93,0x69,0x01,0x80,0x91,0x64,0x00,0x90,0x91,0x65,0x00,0x88,0x0F,0x99,0x1F,
0x90,0x93,0x65,0x00,0x80,0x93,0x64,0x00,0x89,0xDE,0x80,0x32,0x09,0xF0,0xEE,0xCE,
0x84,0xE1,0xAB,0xDE,0xC0,0xE0,0xD0,0xE0,0x80,0x91,0x66,0x01,0x90,0x91,0x67,0x01,
0xC8,0x17,0xD9,0x07,0x60,0xF5,0x80,0x91,0x69,0x01,0x80,0xFF,0x06,0xC0,0x80,0x91,
0x64,0x00,0x90,0x91,0x65,0x00,0x2C,0xD0,0x08,0xC0,0x86,0x95,0x80,0xFD,0x06,0xC0,
0xE0,0x91,0x64,0x00,0xF0,0x91,0x65,0x00,0x84,0x91,0x8F,0xDE,0x80,0x91,0x64,0x00,
0x90,0x91,0x65,0x00,0x01,0x96,0x90,0x93,0x65,0x00,0x80,0x93,0x64,0x00,0x21,0x96,
0xDB,0xCF,0x85,0x37,0x79,0xF4,0x5A,0xDE,0x80,0x32,0x09,0xF0,0xBF,0xCE,0x84,0xE1,
0x7C,0xDE,0x8E,0xE1,0x7A,0xDE,0x83,0xE9,0x78,0xDE,0x87,0xE0,0x76,0xDE,0x80,0xE1,
0x74,0xDE,0xB4,0xCE,0x86,0x37,0x09,0xF0,0xB1,0xCE,0x80,0xE0,0x7B,0xDE,0xAE,0xCE,
0xE1,0x99,0xFE,0xCF,0x9F,0xBB,0x8E,0xBB,0xE0,0x9A,0x99,0x27,0x8D,0xB3,0x08,0x95,
0xE1,0x99,0xFE,0xCF,0x9F,0xBB,0x8E,0xBB,0x6D,0xBB,0x0F,0xB6,0xF8,0x94,0xE2,0x9A,
0xE1,0x9A,0x0F,0xBE,0x08,0x95,
0x80,0x00,
0x00,0x00,0x1C,0x00
};

// PINS
#define SCK 13
// serial clock to target avr
#define MISO 12
// input from target avr
#define MOSI 11
// output to target avr
#define RESET 10
// reset pin of the target avr

#define START_BTN 9
// active low - starts burning the bootloader to the new chip
#define IDLE_LED 8
#define RUN_LED 7
#define ERR_LED 6

// on the target avr, wire these other pins:
// GND: pins 22 (GND), 8 (GND)
// +VCC: pin 7 (VCC)
// XTAL1 & XTAL2

#define CKEDGE LOW
// SCK transmits the bit from MOSI on the rising edge of the clock pulse
// CKEDGE should be LOW, which means SCK pulses "...LOW->HIGH->LOW..."

// ISP Command Words (use the functions defined further below)
#define PE 0xAC53
#define ER 0xAC80
#define RD_PL 0x2000
#define RD_PH 0x2800
#define LD_PL 0x4000
#define LD_PH 0x4800
#define WR_P 0x4C00
#define RD_E 0xA000
#define WR_E 0xC000
#define RD_L 0x5800
#define WR_L 0xACE0
#define RD_S 0x3000
#define WR_F 0xACA0
#define WR_FH 0xACA8
#define RD_F 0x5000
#define RD_FH 0x5808
#define RD_C 0x3800

// Arduino lock bits (default 0xCF ~ prevented reading the boot sector with LPM)
#define LockBits 0xEF
// 11101111 = SPM is not allowed to write to the boot loader section (prevents bootloader corruption)
// Your mega8 running this program probably has bit 6 is programmed. That lock bit makes the bootloader unreadable... (doh!)
// When you use this program to burn new bootloaders, those chips WILL be able to use LPM in the boot flash section.
// You could reduce this program's size by 1K, if LPM can read the boot flash. (there'd be no need for the bootloader table above)

// Arduino fuse bits
#define FuseLow 0xDF
// default 11011111 = 0xDF, bits 1-4 (rightmost) are CKSEL clock select, bits 5-6 are SUT1 & SUT0 start up time delay
// bits 7-8 are BOD brown out detect, which is disabled

#define FuseHigh 0xCA
// default 11001010 = 0xCA, bit 1 select reset vector (on), bits 2-3 boot size (1K), bit 4 EESAVE eeprom preserved through chip erase (off)
// bit 5 CKOPT clock options (on), bit 6 SPIEN SPI enabled (on), bit 7 WDT watchdog timer (off), bit 8 RSTDISBL reset disable (off)

// MACRO DECLARATION

#define PULSE_SCK(level) { digitalWrite((SCK),(level)); digitalWrite((SCK),!(level)); }
// slow pulse, max 60KHz

#define GetWordHigh(a) ( ((a) & 0xFF00) >> 8 )
#define GetWordLow(a) ( ((a) & 0x00FF) )
// these macros are used by the function declarations below

// FUNCTION DECLARATION

// sends 4 bytes out with SCK, MOSI (output) and gets the return value of the last byte from MISO (input)
unsigned char Send_ISP(unsigned char v0, unsigned char v1, unsigned char v2, unsigned char v3);

#define CMD_Program_Enable() (Send_ISP(GetWordHigh(PE),GetWordLow(PE),0x22,0x22))
// Programming Enable: enable serial programming after reset goes low

#define CMD_Erase_Flash() (Send_ISP(GetWordHigh(ER),GetWordLow(ER),0x22,0x22))
// Chip Erase: chip erase eeprom and flash

#define CMD_Read_Flash_Low(addr) (Send_ISP(GetWordHigh(RD_PL), (GetWordLow(RD_PL) | (((addr) & 0xF00) >> 8)), ((addr) & 0xFF), 0))
// Read Program Memory - Low Byte: reads and returns low data from 12 bit word address (divide byte address by 2 for word address)

#define CMD_Read_Flash_High(addr) (Send_ISP(GetWordHigh(RD_PH), (GetWordLow(RD_PH) | (((addr) & 0xF00) >> 8)), ((addr) & 0xFF), 0))
// Read Program Memory - High Byte: reads and returns high data from 12 bit word address

#define CMD_Load_Page_Low(addr,data) (Send_ISP(GetWordHigh(LD_PL),GetWordLow(LD_PL), (addr), (data)))
// Load Program Memory Page - Low Byte: loads a low byte to the selected memory page, at word address "page" (page is 4 bits)
// data low byte must be loaded before data high byte; the flash data is entered by pages, then that whole page is written
// pages are 32 words (64 bytes)

#define CMD_Load_Page_High(addr,data) (Send_ISP(GetWordHigh(LD_PH),GetWordLow(LD_PH), (addr), (data)))
// Load Program Memory Page - High Byte: loads a high byte to program memory page at word address "page" (page is 4 bits)
// data low byte must be loaded before data high byte; the flash data is entered by pages, then that whole page is written
// pages are 32 words (64 bytes)

//#define CMD_Write_Page(addr) (Send_ISP(GetWordHigh(WR_P),(GetWordLow(WR_P) | (((addr) & 0xF0) >> 4)), (((addr) & 0x0F) <<>> 4, ((addr)*2) << 2="3584)" result =" 0;" result="CMD_Program_Enable()" result="CMD_Program_Enable()" result="CMD_Program_Enable()" page =" BOOT_PAGE" index =" 0" result =" 0;" i =" 0x80">0 ; i /= 2 ) {
digitalWrite(MOSI,(v0 & i));
PULSE_SCK(CKEDGE);
//result = ((result << i =" 0x80">0 ; i /= 2 ) { // second byte - MISO echos first byte
digitalWrite(MOSI,(v1 & i));
PULSE_SCK(CKEDGE);
result = ((result << i =" 0x80">0 ; i /= 2 ) { // third byte - MISO echos second byte
digitalWrite(MOSI,(v2 & i));
PULSE_SCK(CKEDGE);
result = ((result << i =" 0x80">0 ; i /= 2 ) { // fourth byte - MISO returns some value (depends on command)
digitalWrite(MOSI,(v3 & i));
PULSE_SCK(CKEDGE);
result = ((result << x =" 0" value =" 0;" index =" 0" index =" 0" page =" 0" index =" 0">> 8);
}
CMD_Write_Page(page);
delay(20);
}
}*/


Insert your Atmega8 into the Arduino Bootloader copier. Switch on the circuit and the green LED will be ON. Press the switch. The yellow LED will be ON for a few seconds and the bootloader was loaded into the Atmega8.

The following diagram shows the 'cheaper version of the Arduino'. You can remove the ISP connector if you don't need this.






You can upload your program to your Atmega8 in the
Arduino Diecimila. Remove the Atmega8 from the Diecimila board and insert it into the 'cheaper version of Arduino'.

That mean you can use Arduino IDE to program your Atmega8 and put the Atmega8 into the 'cheaper version of Arduino'. ENJOY !

Check : - http://www.arduino.cc/playground/BootCloner/BootCloner



2009年1月25日 星期日

2009年1月23日 星期五

Arduino with 4x20 LCD using LCD4bit libaray

How to use LCD4bit with Arduino and LCD


















1. for Duemilanove board, use NG with ATmega168 instead of Diecimila in Arduino IDE 0012


2.
Arduino------LCD------LCD pin

----------2--------enable---- 6

----------7--------DB4-------11

----------8--------DB5-------12

----------9--------DB6-------13

----------10------DB7-------14

----------12------DI (RS)----4

---------GND----RW---------5

3. Need to modify LCD4bit.cpp (\arduino-0012\hardware\libaries\LCD4Bit\LCD4bit.cpp) as follows and delete LCD4bit.o before compile/ verify the sketch.

I changed the origenal 4bit library code myself to let it work with my 4x20LCD, KS0066u Based.
I got it working perfectly.
Below the code for those of you who have the same LCD.

LCD4Bit.cpp:
changes I made
just replace the origenal ones with this ones.


The new constructor:

LCD4Bit::LCD4Bit (int num_lines) {
g_num_lines = num_lines;
if (g_num_lines < g_num_lines =" 1;"> 4)

{
g_num_lines = 4;
}
}

function cursorTo

void LCD4Bit::cursorTo(int line_num, int x){
//first, put cursor home
commandWrite(CMD_HOME);
if (x>19)
{
x=19;
}
switch (line_num)
{

case 1:
x+=0x00 ; break;
case 2:
x+= 0x40 ; break;
case 3:
x+= 0x14 ; break; // In fact, line 3 is an extension of the line 1 (beyond the 20 first characters)
case 4:
x+= 0x54 ; break; // Line 4 is an extension of line 2
}

//
commandWrite(0x80+x);
}

Test program:

#include

LCD4Bit lcd = LCD4Bit(4);

void setup() {
pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
lcd.init();
}

void loop() {
digitalWrite(13, HIGH); //light the debug LED

lcd.clear();
lcd.cursorTo(1,0);
lcd.printIn("Line 1");
lcd.cursorTo(2,0);
lcd.printIn("Line 2");
lcd.cursorTo(3,0);
lcd.printIn("Line 3");
lcd.cursorTo(4,0);
lcd.printIn("Line 4");
delay(1000);
digitalWrite(13, LOW); //clear the debug LED

}

Hope it works for you to!


check www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1170601618/0