add first sreg code
This commit is contained in:
@@ -42,7 +42,7 @@ MCU = atmega644
|
||||
|
||||
# Main Oscillator Frequency
|
||||
# This is only used to define F_OSC in all assembler and c-sources.
|
||||
F_OSC = 8000000
|
||||
F_OSC = 20000000
|
||||
|
||||
# Output format. (can be srec, ihex, binary)
|
||||
FORMAT = ihex
|
||||
@@ -177,11 +177,90 @@ LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
|
||||
#
|
||||
# Type: avrdude -c ?
|
||||
# to get a full listing.
|
||||
##############################################################################
|
||||
# Fuse values for particular devices
|
||||
##############################################################################
|
||||
# If your device is not listed here, go to
|
||||
# http://palmavr.sourceforge.net/cgi-bin/fc.cgi
|
||||
# and choose options for external crystal clock and no clock divider
|
||||
#
|
||||
AVRDUDE_PROGRAMMER = stk500v2
|
||||
################################## ATMega8 ##################################
|
||||
# ATMega8 FUSE_L (Fuse low byte):
|
||||
# 0x9f = 1 0 0 1 1 1 1 1
|
||||
# ^ ^ \ / \--+--/
|
||||
# | | | +------- CKSEL 3..0 (external >8M crystal)
|
||||
# | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
|
||||
# | +------------------ BODEN (BrownOut Detector enabled)
|
||||
# +-------------------- BODLEVEL (2.7V)
|
||||
# ATMega8 FUSE_H (Fuse high byte):
|
||||
# 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
|
||||
# ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
|
||||
# | | | | | +-------- BOOTSZ1
|
||||
# | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
|
||||
# | | | +-------------- CKOPT (full output swing)
|
||||
# | | +---------------- SPIEN (allow serial programming)
|
||||
# | +------------------ WDTON (WDT not always on)
|
||||
# +-------------------- RSTDISBL (reset pin is enabled)
|
||||
#
|
||||
############################## ATMega48/88/168 ##############################
|
||||
# ATMega*8 FUSE_L (Fuse low byte):
|
||||
# 0xdf = 1 1 0 1 1 1 1 1
|
||||
# ^ ^ \ / \--+--/
|
||||
# | | | +------- CKSEL 3..0 (external >8M crystal)
|
||||
# | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
|
||||
# | +------------------ CKOUT (if 0: Clock output enabled)
|
||||
# +-------------------- CKDIV8 (if 0: divide by 8)
|
||||
# ATMega*8 FUSE_H (Fuse high byte):
|
||||
# 0xde = 1 1 0 1 1 1 1 0
|
||||
# ^ ^ ^ ^ ^ \-+-/
|
||||
# | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V)
|
||||
# | | | | + --------- EESAVE (preserve EEPROM over chip erase)
|
||||
# | | | +-------------- WDTON (if 0: watchdog always on)
|
||||
# | | +---------------- SPIEN (allow serial programming)
|
||||
# | +------------------ DWEN (debug wire enable)
|
||||
# +-------------------- RSTDISBL (reset pin is enabled)
|
||||
#
|
||||
############################## ATTiny25/45/85 ###############################
|
||||
# ATMega*5 FUSE_L (Fuse low byte):
|
||||
# 0xef = 1 1 1 0 1 1 1 1
|
||||
# ^ ^ \+/ \--+--/
|
||||
# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
|
||||
# | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
|
||||
# | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
|
||||
# +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
|
||||
# ATMega*5 FUSE_H (Fuse high byte):
|
||||
# 0xdd = 1 1 0 1 1 1 0 1
|
||||
# ^ ^ ^ ^ ^ \-+-/
|
||||
# | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V)
|
||||
# | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved)
|
||||
# | | | +-------------- WDTON (watchdog timer always on -> disable)
|
||||
# | | +---------------- SPIEN (enable serial programming -> enabled)
|
||||
# | +------------------ DWEN (debug wire enable)
|
||||
# +-------------------- RSTDISBL (disable external reset -> enabled)
|
||||
#
|
||||
################################ ATTiny2313 #################################
|
||||
# ATTiny2313 FUSE_L (Fuse low byte):
|
||||
# 0xef = 1 1 1 0 1 1 1 1
|
||||
# ^ ^ \+/ \--+--/
|
||||
# | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
|
||||
# | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
|
||||
# | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
|
||||
# +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
|
||||
# ATTiny2313 FUSE_H (Fuse high byte):
|
||||
# 0xdb = 1 1 0 1 1 0 1 1
|
||||
# ^ ^ ^ ^ \-+-/ ^
|
||||
# | | | | | +---- RSTDISBL (disable external reset -> enabled)
|
||||
# | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V)
|
||||
# | | | +-------------- WDTON (watchdog timer always on -> disable)
|
||||
# | | +---------------- SPIEN (enable serial programming -> enabled)
|
||||
# | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved)
|
||||
# +-------------------- DWEN (debug wire enable)
|
||||
|
||||
#
|
||||
AVRDUDE_PROGRAMMER = usbasp
|
||||
|
||||
# com1 = serial port. Use lpt1 to connect to parallel port.
|
||||
AVRDUDE_PORT = /dev/ttyUSB0 # programmer connected to serial device
|
||||
AVRDUDE_PORT = # programmer connected to serial device
|
||||
|
||||
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
|
||||
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
|
||||
@@ -201,7 +280,7 @@ AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
|
||||
# to submit bug reports.
|
||||
#AVRDUDE_VERBOSE = -v -v
|
||||
|
||||
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
|
||||
AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER)
|
||||
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
|
||||
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
|
||||
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
|
||||
|
||||
@@ -102,7 +102,8 @@ void SRAM_Write(uint32_t addr, uint8_t data)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
DDRB|= (1 << PB1);
|
||||
PORTB|= (1 << PB1);
|
||||
while(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -1,298 +0,0 @@
|
||||
/*#######################################################################################
|
||||
Connect AVR to MMC/SD
|
||||
|
||||
Copyright (C) 2004 Ulrich Radig
|
||||
|
||||
Bei Fragen und Verbesserungen wendet euch per EMail an
|
||||
|
||||
mail@ulrichradig.de
|
||||
|
||||
oder im Forum meiner Web Page : www.ulrichradig.de
|
||||
|
||||
Dieses Programm ist freie Software. Sie k<>nnen es unter den Bedingungen der
|
||||
GNU General Public License, wie von der Free Software Foundation ver<65>ffentlicht,
|
||||
weitergeben und/oder modifizieren, entweder gem<65><6D> Version 2 der Lizenz oder
|
||||
(nach Ihrer Option) jeder sp<73>teren Version.
|
||||
|
||||
Die Ver<65>ffentlichung dieses Programms erfolgt in der Hoffnung,
|
||||
da<EFBFBD> es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
|
||||
sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
|
||||
F<EFBFBD>R EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
|
||||
|
||||
Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
|
||||
Programm erhalten haben.
|
||||
Falls nicht, schreiben Sie an die Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
#######################################################################################*/
|
||||
|
||||
#include "mmc.h"
|
||||
#include <util/delay.h>
|
||||
|
||||
//############################################################################
|
||||
//Routine zur Initialisierung der MMC/SD-Karte (SPI-MODE)
|
||||
unsigned char mmc_init ()
|
||||
//############################################################################
|
||||
{
|
||||
unsigned int Timeout = 0,i;
|
||||
|
||||
//Konfiguration des Ports an der die MMC/SD-Karte angeschlossen wurde
|
||||
DDRC |= ( (1<<MMC_DO) | (1<<MMC_CS) | (1<<MMC_CLK) );
|
||||
DDRC &= ~(1<<MMC_DI);
|
||||
PORTC |= ( (1<<MMC_DO) | (1<<MMC_DI) | (1<<MMC_CS) );
|
||||
|
||||
//Wartet eine kurze Zeit
|
||||
_delay_ms(10);
|
||||
|
||||
|
||||
//Initialisiere MMC/SD-Karte in den SPI-Mode
|
||||
for(i=0; i<250; i++)
|
||||
{
|
||||
PORTC ^= (1<<MMC_CLK);
|
||||
_delay_us(4);
|
||||
}
|
||||
|
||||
PORTC &= ~(1<<MMC_CLK);
|
||||
_delay_us(10);
|
||||
|
||||
PORTC &= ~(1<<MMC_CS);
|
||||
_delay_us(3);
|
||||
|
||||
|
||||
//Sendet Commando CMD0 an MMC/SD-Karte
|
||||
unsigned char CMD[] = {0x40,0x00,0x00,0x00,0x00,0x95};
|
||||
|
||||
while(mmc_write_command (CMD) !=1)
|
||||
{
|
||||
if (Timeout++ > 20)
|
||||
{
|
||||
MMC_Disable();
|
||||
return(1); //Abbruch bei Commando1 (Return Code1)
|
||||
}
|
||||
}
|
||||
|
||||
//Sendet Commando CMD1 an MMC/SD-Karte
|
||||
Timeout = 0;
|
||||
|
||||
CMD[0] = 0x41;//Commando 1
|
||||
CMD[5] = 0xFF;
|
||||
|
||||
while( mmc_write_command (CMD) !=0)
|
||||
{
|
||||
if (Timeout++ > 800)
|
||||
{
|
||||
MMC_Disable();
|
||||
return(9); //Abbruch bei Commando2 (Return Code2)
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
//Sendet ein Commando an die MMC/SD-Karte
|
||||
unsigned char mmc_write_command (unsigned char *cmd)
|
||||
//############################################################################
|
||||
{
|
||||
unsigned char tmp = 0xff;
|
||||
unsigned int Timeout = 0;
|
||||
|
||||
|
||||
//sendet 6 Byte Commando
|
||||
for (unsigned char a = 0;a<0x06;a++) //sendet 6 Byte Commando zur MMC/SD-Karte
|
||||
{
|
||||
mmc_write_byte(*cmd++);
|
||||
}
|
||||
|
||||
//Wartet auf ein g<>ltige Antwort von der MMC/SD-Karte
|
||||
while (tmp == 0xff)
|
||||
{
|
||||
tmp = mmc_read_byte();
|
||||
|
||||
if (Timeout++ > 50)
|
||||
{
|
||||
break; //Abbruch da die MMC/SD-Karte nicht Antwortet
|
||||
}
|
||||
}
|
||||
return(tmp);
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
//Routine zum Empfangen eines Bytes von der MMC-Karte
|
||||
unsigned char mmc_read_byte (void)
|
||||
//############################################################################
|
||||
{
|
||||
uint8_t Byte=0,j;
|
||||
|
||||
for(j=0; j<8; j++){
|
||||
Byte = (Byte<<1);
|
||||
|
||||
PORTC |= (1<<MMC_CLK);
|
||||
_delay_us(4);
|
||||
|
||||
if(PINC & (1<<MMC_DI)){
|
||||
Byte |= 1;
|
||||
}
|
||||
else{
|
||||
Byte &= ~1;
|
||||
}
|
||||
|
||||
PORTC &= ~(1<<MMC_CLK);
|
||||
_delay_us(4);
|
||||
}
|
||||
|
||||
return (Byte);
|
||||
}
|
||||
|
||||
|
||||
//############################################################################
|
||||
//Routine zum Senden eines Bytes zur MMC-Karte
|
||||
void mmc_write_byte (unsigned char Byte)
|
||||
//############################################################################
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i=0; i<8; i++){
|
||||
if(Byte & 0x80){
|
||||
PORTC |= (1<<MMC_DO);
|
||||
}
|
||||
else{
|
||||
PORTC &= ~(1<<MMC_DO);
|
||||
}
|
||||
|
||||
Byte = (Byte<<1);
|
||||
PORTC |= (1<<MMC_CLK);
|
||||
_delay_us(4);
|
||||
PORTC &= ~(1<<MMC_CLK);
|
||||
_delay_us(4);
|
||||
}
|
||||
PORTC |= (1<<MMC_DO);
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
//Routine zum schreiben eines Blocks(512Byte) auf die MMC/SD-Karte
|
||||
unsigned char mmc_write_sector (unsigned long addr,unsigned char *Buffer)
|
||||
//############################################################################
|
||||
{
|
||||
unsigned char tmp;
|
||||
//Commando 24 zum schreiben eines Blocks auf die MMC/SD - Karte
|
||||
unsigned char cmd[] = {0x58,0x00,0x00,0x00,0x00,0xFF};
|
||||
|
||||
/*Die Adressierung der MMC/SD-Karte wird in Bytes angegeben,
|
||||
addr wird von Blocks zu Bytes umgerechnet danach werden
|
||||
diese in das Commando eingef<65>gt*/
|
||||
|
||||
addr = addr << 9; //addr = addr * 512
|
||||
|
||||
cmd[1] = ((addr & 0xFF000000) >>24 );
|
||||
cmd[2] = ((addr & 0x00FF0000) >>16 );
|
||||
cmd[3] = ((addr & 0x0000FF00) >>8 );
|
||||
|
||||
//Sendet Commando cmd24 an MMC/SD-Karte (Write 1 Block/512 Bytes)
|
||||
tmp = mmc_write_command (cmd);
|
||||
if (tmp != 0)
|
||||
{
|
||||
return(tmp);
|
||||
}
|
||||
|
||||
//Wartet einen Moment und sendet einen Clock an die MMC/SD-Karte
|
||||
for (unsigned char a=0;a<100;a++)
|
||||
{
|
||||
mmc_read_byte();
|
||||
}
|
||||
|
||||
//Sendet Start Byte an MMC/SD-Karte
|
||||
mmc_write_byte(0xFE);
|
||||
|
||||
//Schreiben des Bolcks (512Bytes) auf MMC/SD-Karte
|
||||
for (unsigned int a=0;a<512;a++)
|
||||
{
|
||||
mmc_write_byte(*Buffer++);
|
||||
}
|
||||
|
||||
//CRC-Byte schreiben
|
||||
mmc_write_byte(0xFF); //Schreibt Dummy CRC
|
||||
mmc_write_byte(0xFF); //CRC Code wird nicht benutzt
|
||||
|
||||
//Fehler beim schreiben? (Data Response XXX00101 = OK)
|
||||
if((mmc_read_byte()&0x1F) != 0x05) return(1);
|
||||
|
||||
//Wartet auf MMC/SD-Karte Bussy
|
||||
while (mmc_read_byte() != 0xff){};
|
||||
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
//Routine zum lesen des CID Registers von der MMC/SD-Karte (16Bytes)
|
||||
void mmc_read_block(unsigned char *cmd,unsigned char *Buffer,unsigned int Bytes)
|
||||
//############################################################################
|
||||
{
|
||||
//Sendet Commando cmd an MMC/SD-Karte
|
||||
if (mmc_write_command (cmd) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Wartet auf Start Byte von der MMC/SD-Karte (FEh/Start Byte)
|
||||
|
||||
while (mmc_read_byte() != 0xfe){};
|
||||
|
||||
//Lesen des Bolcks (normal 512Bytes) von MMC/SD-Karte
|
||||
for (unsigned int a=0;a<Bytes;a++)
|
||||
{
|
||||
*Buffer++ = mmc_read_byte();
|
||||
}
|
||||
//CRC-Byte auslesen
|
||||
mmc_read_byte();//CRC - Byte wird nicht ausgewertet
|
||||
mmc_read_byte();//CRC - Byte wird nicht ausgewertet
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
//Routine zum lesen eines Blocks(512Byte) von der MMC/SD-Karte
|
||||
unsigned char mmc_read_sector (unsigned long addr,unsigned char *Buffer)
|
||||
//############################################################################
|
||||
{
|
||||
//Commando 16 zum lesen eines Blocks von der MMC/SD - Karte
|
||||
unsigned char cmd[] = {0x51,0x00,0x00,0x00,0x00,0xFF};
|
||||
/*Die Adressierung der MMC/SD-Karte wird in Bytes angegeben,
|
||||
addr wird von Blocks zu Bytes umgerechnet danach werden
|
||||
diese in das Commando eingef<65>gt*/
|
||||
|
||||
addr = addr << 9; //addr = addr * 512
|
||||
|
||||
cmd[1] = ((addr & 0xFF000000) >>24 );
|
||||
cmd[2] = ((addr & 0x00FF0000) >>16 );
|
||||
cmd[3] = ((addr & 0x0000FF00) >>8 );
|
||||
|
||||
mmc_read_block(cmd,Buffer,512);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
//Routine zum lesen des CID Registers von der MMC/SD-Karte (16Bytes)
|
||||
unsigned char mmc_read_cid (unsigned char *Buffer)
|
||||
//############################################################################
|
||||
{
|
||||
//Commando zum lesen des CID Registers
|
||||
unsigned char cmd[] = {0x4A,0x00,0x00,0x00,0x00,0xFF};
|
||||
|
||||
mmc_read_block(cmd,Buffer,16);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
//############################################################################
|
||||
//Routine zum lesen des CSD Registers von der MMC/SD-Karte (16Bytes)
|
||||
unsigned char mmc_read_csd (unsigned char *Buffer)
|
||||
//############################################################################
|
||||
{
|
||||
//Commando zum lesen des CSD Registers
|
||||
unsigned char cmd[] = {0x49,0x00,0x00,0x00,0x00,0xFF};
|
||||
|
||||
mmc_read_block(cmd,Buffer,16);
|
||||
return(0);
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*#######################################################################################
|
||||
Connect ARM to MMC/SD
|
||||
|
||||
Copyright (C) 2004 Ulrich Radig
|
||||
#######################################################################################*/
|
||||
|
||||
#ifndef _MMC_H_
|
||||
#define _MMC_H_
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
//#define SPI_Mode 1 //1 = Hardware SPI | 0 = Software SPI
|
||||
#define SPI_Mode 0
|
||||
|
||||
#define MMC_Write PORTC //Port an der die MMC/SD-Karte angeschlossen ist also des SPI
|
||||
#define MMC_Read PINC
|
||||
#define MMC_Direction_REG DDRC
|
||||
|
||||
#if defined (__AVR_ATmega8__)
|
||||
#define MMC_CS PC0
|
||||
#define MMC_DO PC1
|
||||
#define MMC_DI PC2
|
||||
#define MMC_CLK PC3
|
||||
#define SPI_SS 4 //Nicht Benutz mu<6D> aber definiert werden
|
||||
#endif
|
||||
|
||||
|
||||
//Prototypes
|
||||
extern unsigned char mmc_read_byte(void);
|
||||
|
||||
extern void mmc_write_byte(unsigned char);
|
||||
|
||||
extern void mmc_read_block(unsigned char *,unsigned char *,unsigned in);
|
||||
|
||||
extern unsigned char mmc_init(void);
|
||||
|
||||
extern unsigned char mmc_read_sector (unsigned long,unsigned char *);
|
||||
|
||||
extern unsigned char mmc_write_sector (unsigned long,unsigned char *);
|
||||
|
||||
extern unsigned char mmc_write_command (unsigned char *);
|
||||
|
||||
extern unsigned char mmc_read_csd (unsigned char *);
|
||||
|
||||
extern unsigned char mmc_read_cid (unsigned char *);
|
||||
|
||||
//set MMC_Chip_Select to high (MMC/SD-Karte Inaktiv)
|
||||
#define MMC_Disable() MMC_Write|= (1<<MMC_CS);
|
||||
|
||||
//set MMC_Chip_Select to low (MMC/SD-Karte Aktiv)
|
||||
#define MMC_Enable() MMC_Write&=~(1<<MMC_CS);
|
||||
|
||||
#define nop() __asm__ __volatile__ ("nop" ::)
|
||||
|
||||
#endif //_MMC_H_
|
||||
|
||||
|
||||
Reference in New Issue
Block a user