No changes between revisions
/Designs/Oscilloscope/SW/firmware/gnuradio/Makefile |
---|
0,0 → 1,33 |
PRG = scope |
OBJ = main.o ./libs/usart.o ./libs/spi.o |
MCU_TARGET = atmega8 |
AVRDUDE_PART = m8 |
OPTIMIZE = -O1 |
# OPTIMIZE = -Os |
CC = avr-gcc |
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) |
OBJCOPY = avr-objcopy |
OBJDUMP = avr-objdump |
all: hex |
./libs/spi.o: ./libs/spi.h |
./libs/usart.o: ./libs/usart.h |
#./libs/timer.o: ./libs/timer.h |
hex: $(PRG).hex |
%.hex: %.elf |
$(OBJCOPY) -j .text -j .data -O ihex $< $@ |
$(PRG).elf: $(OBJ) |
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) |
load: $(PRG).hex |
avrdude -p $(AVRDUDE_PART) -c stk500v2 -P /dev/ttyUSB0 -B 2 -U flash:w:$< |
clean: |
rm -rf *.o $(PRG).elf $(PRG).hex ./libs/*.o |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |
/Designs/Oscilloscope/SW/firmware/gnuradio/libs/spi.c |
---|
0,0 → 1,20 |
#include "spi.h" |
#include <avr/io.h> |
void SPI_MasterInit(void) |
{ |
/* Enable SPI, Master, set clock rate fck/4, SCK high when idle, sample on rising */ |
// SPSR|= 0b00000001; //for fck/2 |
SPCR = 0b01011100; |
} |
char SPI_MasterTransmit(char cData) { |
/* Start transmission */ |
SPDR = cData; |
/* Wait for transmission complete */ |
while(!(SPSR & (1<<SPIF))) |
; |
return SPDR; |
} |
/Designs/Oscilloscope/SW/firmware/gnuradio/libs/spi.h |
---|
0,0 → 1,7 |
#ifndef SPI_H |
#define SPI_H |
void SPI_MasterInit(void); |
char SPI_MasterTransmit(char cData); |
#endif |
/Designs/Oscilloscope/SW/firmware/gnuradio/libs/usart.c |
---|
0,0 → 1,128 |
#include "usart.h" |
#include <avr/io.h> |
void USART_Init( unsigned int ubrr) |
{ |
/* Set baud rate */ |
UBRRH = (unsigned char)(ubrr>>8); |
UBRRL = (unsigned char)ubrr; |
/* flush transmitt register Double speed */ |
UCSRA = (1<<UDRE)|(1 << U2X); |
/* enable receiver interrupt and transmitter, pins forced */ |
UCSRB = (1<<RXCIE)|(1<<RXEN)|(1<<TXEN); |
/* Asynchronous, no parity, Set frame format: 8data, 1stop bit */ |
UCSRC = (1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1); |
} |
void USART_Transmit( unsigned char data ) |
{ |
while ( !( UCSRA & (1<<UDRE)) ); /* Wait for empty transmit buffer */ |
UDR = data; /* Put data into buffer, sends the data */ |
} |
void USART_Transmit_string( char *data ) |
{ |
while ( *data != 0 ) { |
USART_Transmit(*data); |
data++; |
} |
} |
void USART_Transmit_longnum(signed long data ) { |
unsigned char digits[10],i; |
if (data==0) |
USART_Transmit('0'); |
else { // PROZKOUMAT! |
if (data<0) { |
USART_Transmit('-'); |
data*=-1; |
} |
for (i=0;i<10;i++) { |
digits[i]=data%10; |
data=data/10; |
} |
i=9; |
while (digits[i]==0) i--; |
while (i>0) { |
USART_Transmit(digits[i]+48); |
i--; |
} |
USART_Transmit(digits[0]+48); |
} |
} |
void USART_Transmit_uint16 (unsigned int data ) { |
unsigned char digits[5],i; |
if (data==0) //podivne, ale nulu to odeslat neumi |
USART_Transmit('0'); |
else { |
for (i=0;i<5;i++) { |
digits[i]=data%10; |
data=data/10; |
} |
i=4; |
while (digits[i]==0) i--; |
while (i>0) { |
USART_Transmit(digits[i]+48); |
i--; |
} |
USART_Transmit(digits[0]+48); |
} |
} |
void USART_Transmit_num(unsigned char data ) { |
unsigned char a,b,c; |
c=data%10; |
data=data/10; |
b=data%10; |
data=data/10; |
a=data%10; |
USART_Transmit(a+48); |
USART_Transmit(b+48); |
USART_Transmit(c+48); |
} |
/*void USART_Transmit_float( float data ) { |
int a,b,c; |
c=((int)data)%10; |
b=((int)(data/10))%10; |
a=((int)(data/100))%10; |
USART_Transmit(a+48); |
USART_Transmit(b+48); |
USART_Transmit(c+48); |
}*/ |
void USART_Transmit_byte( char data ) { |
unsigned char i; |
i=0b10000000; |
while (i) { |
USART_Transmit( ( (i&data)&&1 ) + 48 ); |
i>>=1; |
} |
} |
/Designs/Oscilloscope/SW/firmware/gnuradio/libs/usart.h |
---|
0,0 → 1,17 |
#ifndef USART_H |
#define USART_H |
//Inits: |
void USART_Init( unsigned int ubrr); // 8b, no parity, 1 stop |
// asynchronous, RX interrupt |
// Busy loops: |
void USART_Transmit( unsigned char data ); // send char (1B) |
void USART_Transmit_string( char *data ); // send string |
void USART_Transmit_num( unsigned char data ); // send ascii |
void USART_Transmit_longnum( signed long data ); // send ascii |
void USART_Transmit_uint16( unsigned int data ); // send ascii |
//void USART_Transmit_float( float data ); |
void USART_Transmit_byte( char data ); //send in ascii hex reprezentation |
#endif |
/Designs/Oscilloscope/SW/firmware/gnuradio/main.c |
---|
0,0 → 1,38 |
// Oscilloscope firmware, Roman Pavelka, 2011 |
// written for atmega8 |
#define F_CPU 16000000 |
#define BAUD 1000000 |
//#define MYUBRR F_CPU/8/BAUD-1 |
#define MYUBRR 1 |
#include "./libs/usart.h" |
#include "./libs/spi.h" |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <util/delay.h> |
#include <inttypes.h> |
int main (void) { |
USART_Init(MYUBRR); |
DDRB = 0b00100100; //SCK, SS out |
PORTB = 0b00000000; // CONV low |
SPI_MasterInit(); |
while(1) |
{ |
PORTB |= 0b00000100; |
_delay_us(4); |
PORTB &= 0b11111011; //one conversion |
USART_Transmit(SPI_MasterTransmit(0x0)); //Binary transfer |
USART_Transmit(SPI_MasterTransmit(0x0)); |
_delay_us(4); |
} |
return 0; |
} |