顯示具有 Atmega8 標籤的文章。 顯示所有文章
顯示具有 Atmega8 標籤的文章。 顯示所有文章

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月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 ! ! !