fixed crlf for project

This commit is contained in:
Henrik Ekblad
2014-03-07 21:17:56 +01:00
parent 586a4d6239
commit c1441dca4a
62 changed files with 6964 additions and 6964 deletions
@@ -1,79 +1,79 @@
#include <spi.h>
#include <ds1305.h>
#define DS1305_PIN 4
#define LED_PIN 3
// following two methods required by DS1305 library to select/deselect device
void select_ds1305(void)
{
digitalWrite(DS1305_PIN, HIGH);
}
void deselect_ds1305(void)
{
digitalWrite(DS1305_PIN, LOW);
}
// flash led that's connected to pin 3
void flash_led(void)
{
pinMode(LED_PIN, OUTPUT);
for (int i=0; i<10; i++) {
digitalWrite(LED_PIN, i%2==0);
delay(50);
}
}
// called when pin INT0 goes from 1 to 0
ISR(INT0_vect)
{
// get alarm value to clear alarm interrupt flag on DS1305
DS1305_DATETIME alarm;
get_alarm0(&alarm);
flash_led();
}
void setup()
{
// flash LED at start to indicate were about to start
flash_led();
flash_led();
// pin used to enable DS1305
pinMode(DS1305_PIN, OUTPUT);
// Make sure ADC is unselected and setup spi
deselect_ds1305();
setup_spi(SPI_MODE_1, SPI_MSB, SPI_NO_INTERRUPT, SPI_MSTR_CLK16);
set_control(0);
// set current date/time to Thursday 06/05/09 20:32:30
DS1305_DATETIME current = {0x30, 0x32, 0x20, 0x05, 0x06, 0x05, 0x09};
set_time(&current);
// change the value of alarm to the required time/granularity:
// raise alarm every day (at 20:32:00):
// DS1305_DATETIME alarm = {0x00, 0x32, 0x20, 0x00 | DS1305_ALARM_SET};
// raise alarm every minute (when seconds = 00):
// DS1305_DATETIME alarm = {0x00, 0x32 | DS1305_ALARM_SET,
// 0x20 | DS1305_ALARM_SET, 0x05 | DS1305_ALARM_SET};
// raise alarm every second:
DS1305_DATETIME alarm = {0x55 | DS1305_ALARM_SET, 0x32 | DS1305_ALARM_SET,
0x20 | DS1305_ALARM_SET, 0x05 | DS1305_ALARM_SET};
set_alarm0(&alarm);
// turn on timer and make alarm0 lower INT0 pin when alarm is triggered
set_control(DS1305_EOSC | DS1305_INTCN | DS1305_AIE0);
// raise interrupt when INT0 pin falls (pin PD0 at AT90usbXXX, pin PD2 on ATmegaXXX (arduino pin 2))
// the code in ISR(INT0_vect) above will be called
EICRA = (1<<ISC01) | (0<<ISC00);
// enable interrupts
EIMSK = (1<<INT0);
sei();
}
void loop()
{
// do nothing - all action happens in interrupt
}
#include <spi.h>
#include <ds1305.h>
#define DS1305_PIN 4
#define LED_PIN 3
// following two methods required by DS1305 library to select/deselect device
void select_ds1305(void)
{
digitalWrite(DS1305_PIN, HIGH);
}
void deselect_ds1305(void)
{
digitalWrite(DS1305_PIN, LOW);
}
// flash led that's connected to pin 3
void flash_led(void)
{
pinMode(LED_PIN, OUTPUT);
for (int i=0; i<10; i++) {
digitalWrite(LED_PIN, i%2==0);
delay(50);
}
}
// called when pin INT0 goes from 1 to 0
ISR(INT0_vect)
{
// get alarm value to clear alarm interrupt flag on DS1305
DS1305_DATETIME alarm;
get_alarm0(&alarm);
flash_led();
}
void setup()
{
// flash LED at start to indicate were about to start
flash_led();
flash_led();
// pin used to enable DS1305
pinMode(DS1305_PIN, OUTPUT);
// Make sure ADC is unselected and setup spi
deselect_ds1305();
setup_spi(SPI_MODE_1, SPI_MSB, SPI_NO_INTERRUPT, SPI_MSTR_CLK16);
set_control(0);
// set current date/time to Thursday 06/05/09 20:32:30
DS1305_DATETIME current = {0x30, 0x32, 0x20, 0x05, 0x06, 0x05, 0x09};
set_time(&current);
// change the value of alarm to the required time/granularity:
// raise alarm every day (at 20:32:00):
// DS1305_DATETIME alarm = {0x00, 0x32, 0x20, 0x00 | DS1305_ALARM_SET};
// raise alarm every minute (when seconds = 00):
// DS1305_DATETIME alarm = {0x00, 0x32 | DS1305_ALARM_SET,
// 0x20 | DS1305_ALARM_SET, 0x05 | DS1305_ALARM_SET};
// raise alarm every second:
DS1305_DATETIME alarm = {0x55 | DS1305_ALARM_SET, 0x32 | DS1305_ALARM_SET,
0x20 | DS1305_ALARM_SET, 0x05 | DS1305_ALARM_SET};
set_alarm0(&alarm);
// turn on timer and make alarm0 lower INT0 pin when alarm is triggered
set_control(DS1305_EOSC | DS1305_INTCN | DS1305_AIE0);
// raise interrupt when INT0 pin falls (pin PD0 at AT90usbXXX, pin PD2 on ATmegaXXX (arduino pin 2))
// the code in ISR(INT0_vect) above will be called
EICRA = (1<<ISC01) | (0<<ISC00);
// enable interrupts
EIMSK = (1<<INT0);
sei();
}
void loop()
{
// do nothing - all action happens in interrupt
}
+111 -111
View File
@@ -1,111 +1,111 @@
This directory contains a simple AVR spi helper library that should
run on most AVR microcontrollers which support SPI.
The code is further described at:
http://www.rocketnumbernine.com/2009/04/26/using-spi-on-an-avr-1/ (basics & ADC)
http://www.rocketnumbernine.com/2009/05/12/using-spi-on-an-avr-2/ (RTC)
Any comments/questions to <andrew@rocketnumbernine.com>
Make sure viewing this text in a fixed width font for the tables and diagrams
----------------------------------
Arduino
----------------------------------
The Arduino Directory contains all code required to run on the Arduino.
Simply copy the Arduino/SPI and Arduino/DS1305 directories to the
"hardware/libraries" directory of your Arduino IDE installation and
restart the Arduino IDE. Once restarted there should be
"Sketch->Import Library->SPI" and "Sketch->Import Library->DS1305" menu
entries which can be used to include the spi header files into your project.
"File->Sketchbook->Examples->Library SPI" contains 3 example projects
----------------------------------
AVR GCC
----------------------------------
To use, just copy spi.h and spi.c (and ds1305.c and ds1305.h if using
the DS1305 Real Time Clock chip) to your own project and compile.
Makefile.mf - 'standard' generated make file from AVR GCC
Makefile - Makefile "make examples" will make example programs below:
spi-test-adc.c MC3201 Analogue to Digital convertor example
spi-test-rtc.c DS1305 - Real-Time-Clock/Alarm example
spi-test-masterslave.c Master/Slave communication example
----------------------------------
PINS
----------------------------------
Following are the AVR pins used in the circuits below
ATmegaXXX Arduino AT90usbXXX
MISO PB4 12 PB3
MOSI PB3 11 PB2
SCK PB5 13 PB1
SS PB2 10 PB0
INT0 PD2 2 PD0
----------------------------------
MC3201 12-bit ADC Circuit
----------------------------------
See http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf for full details.
+-----------------+
| MC3201 |
+5V [| Vref Vdd |] +5V
| |
Analogue In [| IN+ CLK |] AVR SCK
| |
Ground [| IN- Dout |] AVR MOSI
| |
Ground [| Vss ^CS |] AVR CE
+-----------------+
For testing purposes "Analogue In" can be connected to the middle wire
of a potentiometer with one outer wire being connected to +5 and the
other to Ground. A 1uF Capacitor should be placed between the analogue
input and ground, and +5V and ground as close to the chip as possible,
but in a pinch the circuit will likely work without.
MOSI/SLCK/CE to the relevant pin on the AVR (MISO is not used) - see above.
----------------------------------
DS1305 Real Time Clock Circuit
----------------------------------
See http://datasheets.maxim-ic.com/en/ds/DS1305.pdf for full details.
Without a battery the following connections can be used:
+-----------------+
| DS1305 |
Ground [| Vcc2 Vcc1 |] +5V
| |
Ground [| Vbat ^PF |] Not Connected
| |
Crystal [| X1 Vccif |] +5V
| |
Crystal [| X2 SDO |] AVR MISO
| |
Not Connected [| N.C. SDI |] AVR MOSI
| |
AVR INT0 [| INT0 SLCK |] AVR SLCK
| |
Not Connected [| INT1 CE |] AVR CE
| |
Ground [| GND SERMODE |] +5V
+-----------------+
MISO/MOSI/SLCK/CE/INT0 to the relevant pin on the AVR - see above.
This directory contains a simple AVR spi helper library that should
run on most AVR microcontrollers which support SPI.
The code is further described at:
http://www.rocketnumbernine.com/2009/04/26/using-spi-on-an-avr-1/ (basics & ADC)
http://www.rocketnumbernine.com/2009/05/12/using-spi-on-an-avr-2/ (RTC)
Any comments/questions to <andrew@rocketnumbernine.com>
Make sure viewing this text in a fixed width font for the tables and diagrams
----------------------------------
Arduino
----------------------------------
The Arduino Directory contains all code required to run on the Arduino.
Simply copy the Arduino/SPI and Arduino/DS1305 directories to the
"hardware/libraries" directory of your Arduino IDE installation and
restart the Arduino IDE. Once restarted there should be
"Sketch->Import Library->SPI" and "Sketch->Import Library->DS1305" menu
entries which can be used to include the spi header files into your project.
"File->Sketchbook->Examples->Library SPI" contains 3 example projects
----------------------------------
AVR GCC
----------------------------------
To use, just copy spi.h and spi.c (and ds1305.c and ds1305.h if using
the DS1305 Real Time Clock chip) to your own project and compile.
Makefile.mf - 'standard' generated make file from AVR GCC
Makefile - Makefile "make examples" will make example programs below:
spi-test-adc.c MC3201 Analogue to Digital convertor example
spi-test-rtc.c DS1305 - Real-Time-Clock/Alarm example
spi-test-masterslave.c Master/Slave communication example
----------------------------------
PINS
----------------------------------
Following are the AVR pins used in the circuits below
ATmegaXXX Arduino AT90usbXXX
MISO PB4 12 PB3
MOSI PB3 11 PB2
SCK PB5 13 PB1
SS PB2 10 PB0
INT0 PD2 2 PD0
----------------------------------
MC3201 12-bit ADC Circuit
----------------------------------
See http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf for full details.
+-----------------+
| MC3201 |
+5V [| Vref Vdd |] +5V
| |
Analogue In [| IN+ CLK |] AVR SCK
| |
Ground [| IN- Dout |] AVR MOSI
| |
Ground [| Vss ^CS |] AVR CE
+-----------------+
For testing purposes "Analogue In" can be connected to the middle wire
of a potentiometer with one outer wire being connected to +5 and the
other to Ground. A 1uF Capacitor should be placed between the analogue
input and ground, and +5V and ground as close to the chip as possible,
but in a pinch the circuit will likely work without.
MOSI/SLCK/CE to the relevant pin on the AVR (MISO is not used) - see above.
----------------------------------
DS1305 Real Time Clock Circuit
----------------------------------
See http://datasheets.maxim-ic.com/en/ds/DS1305.pdf for full details.
Without a battery the following connections can be used:
+-----------------+
| DS1305 |
Ground [| Vcc2 Vcc1 |] +5V
| |
Ground [| Vbat ^PF |] Not Connected
| |
Crystal [| X1 Vccif |] +5V
| |
Crystal [| X2 SDO |] AVR MISO
| |
Not Connected [| N.C. SDI |] AVR MOSI
| |
AVR INT0 [| INT0 SLCK |] AVR SLCK
| |
Not Connected [| INT1 CE |] AVR CE
| |
Ground [| GND SERMODE |] +5V
+-----------------+
MISO/MOSI/SLCK/CE/INT0 to the relevant pin on the AVR - see above.