Problem with comparison.
/Designs/Oscilloscope/PrjInfo.txt |
---|
0,0 → 1,14 |
[InfoShortDescription.en] |
Simple low frequency oscilloscope project. The project utilizes modules ATMEGA801B, USBRS232R01B and ADCmonoSPI01B. |
[InfoShortDescription.cs] |
Jednoduchý nízkofrekvenční osciloskop. Využívá modulů ATMEGA801B, USBRS232R01B a ADCmonoSPI01B. |
[InfoLongDescription.en] |
The device services for analog signal conditioning, ADC sampling and raw data transfer to PC. Following processing is taken on the PC side. |
[InfoLongDescription.cs] |
Zařízení provede zákládní zpracování signálu analogovou cestou, navzorkuje daný počet hodnot a odešle je osobnímu počítači. Další zpracování provádí software PC. |
[End] |
/Designs/Oscilloscope/SW/PC_side/qscope/Makefile |
---|
0,0 → 1,218 |
############################################################################# |
# Makefile for building: qscope |
# Generated by qmake (2.01a) (Qt 4.7.2) on: Sun Aug 14 00:40:57 2011 |
# Project: qscope.pro |
# Template: app |
# Command: /usr/bin/qmake -o Makefile qscope.pro |
############################################################################# |
####### Compiler, tools and options |
CC = gcc |
CXX = g++ |
DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED |
CFLAGS = -pipe -Wall -W -D_REENTRANT $(DEFINES) |
CXXFLAGS = -pipe -Wall -W -D_REENTRANT $(DEFINES) |
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. |
LINK = g++ |
LFLAGS = -Wl,-O1 -Wl,-rpath,/usr/lib/qt4 |
LIBS = $(SUBLIBS) -L/usr/lib/qt4 -lQtGui -L/usr/lib/qt4 -L/usr/X11R6/lib -lQtCore -lgthread-2.0 -lrt -lglib-2.0 -lpthread |
AR = ar cqs |
RANLIB = |
QMAKE = /usr/bin/qmake |
TAR = tar -cf |
COMPRESS = gzip -9f |
COPY = cp -f |
SED = sed |
COPY_FILE = $(COPY) |
COPY_DIR = $(COPY) -r |
STRIP = strip |
INSTALL_FILE = install -m 644 -p |
INSTALL_DIR = $(COPY_DIR) |
INSTALL_PROGRAM = install -m 755 -p |
DEL_FILE = rm -f |
SYMLINK = ln -f -s |
DEL_DIR = rmdir |
MOVE = mv -f |
CHK_DIR_EXISTS= test -d |
MKDIR = mkdir -p |
####### Output directory |
OBJECTS_DIR = ./ |
####### Files |
SOURCES = main.cpp \ |
scope.cpp moc_scope.cpp |
OBJECTS = main.o \ |
scope.o \ |
moc_scope.o |
DIST = /usr/share/qt4/mkspecs/common/g++.conf \ |
/usr/share/qt4/mkspecs/common/unix.conf \ |
/usr/share/qt4/mkspecs/common/linux.conf \ |
/usr/share/qt4/mkspecs/qconfig.pri \ |
/usr/share/qt4/mkspecs/modules/qt_phonon.pri \ |
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ |
/usr/share/qt4/mkspecs/features/qt_functions.prf \ |
/usr/share/qt4/mkspecs/features/qt_config.prf \ |
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \ |
/usr/share/qt4/mkspecs/features/default_pre.prf \ |
/usr/share/qt4/mkspecs/features/release.prf \ |
/usr/share/qt4/mkspecs/features/default_post.prf \ |
/usr/share/qt4/mkspecs/features/warn_on.prf \ |
/usr/share/qt4/mkspecs/features/qt.prf \ |
/usr/share/qt4/mkspecs/features/unix/thread.prf \ |
/usr/share/qt4/mkspecs/features/moc.prf \ |
/usr/share/qt4/mkspecs/features/resources.prf \ |
/usr/share/qt4/mkspecs/features/uic.prf \ |
/usr/share/qt4/mkspecs/features/yacc.prf \ |
/usr/share/qt4/mkspecs/features/lex.prf \ |
/usr/share/qt4/mkspecs/features/include_source_dir.prf \ |
qscope.pro |
QMAKE_TARGET = qscope |
DESTDIR = |
TARGET = qscope |
first: all |
####### Implicit rules |
.SUFFIXES: .o .c .cpp .cc .cxx .C |
.cpp.o: |
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" |
.cc.o: |
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" |
.cxx.o: |
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" |
.C.o: |
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" |
.c.o: |
$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" |
####### Build rules |
all: Makefile $(TARGET) |
$(TARGET): $(OBJECTS) |
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) |
Makefile: qscope.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \ |
/usr/share/qt4/mkspecs/common/unix.conf \ |
/usr/share/qt4/mkspecs/common/linux.conf \ |
/usr/share/qt4/mkspecs/qconfig.pri \ |
/usr/share/qt4/mkspecs/modules/qt_phonon.pri \ |
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ |
/usr/share/qt4/mkspecs/features/qt_functions.prf \ |
/usr/share/qt4/mkspecs/features/qt_config.prf \ |
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \ |
/usr/share/qt4/mkspecs/features/default_pre.prf \ |
/usr/share/qt4/mkspecs/features/release.prf \ |
/usr/share/qt4/mkspecs/features/default_post.prf \ |
/usr/share/qt4/mkspecs/features/warn_on.prf \ |
/usr/share/qt4/mkspecs/features/qt.prf \ |
/usr/share/qt4/mkspecs/features/unix/thread.prf \ |
/usr/share/qt4/mkspecs/features/moc.prf \ |
/usr/share/qt4/mkspecs/features/resources.prf \ |
/usr/share/qt4/mkspecs/features/uic.prf \ |
/usr/share/qt4/mkspecs/features/yacc.prf \ |
/usr/share/qt4/mkspecs/features/lex.prf \ |
/usr/share/qt4/mkspecs/features/include_source_dir.prf \ |
/usr/lib/qt4/libQtGui.prl \ |
/usr/lib/qt4/libQtCore.prl |
$(QMAKE) -o Makefile qscope.pro |
/usr/share/qt4/mkspecs/common/g++.conf: |
/usr/share/qt4/mkspecs/common/unix.conf: |
/usr/share/qt4/mkspecs/common/linux.conf: |
/usr/share/qt4/mkspecs/qconfig.pri: |
/usr/share/qt4/mkspecs/modules/qt_phonon.pri: |
/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri: |
/usr/share/qt4/mkspecs/features/qt_functions.prf: |
/usr/share/qt4/mkspecs/features/qt_config.prf: |
/usr/share/qt4/mkspecs/features/exclusive_builds.prf: |
/usr/share/qt4/mkspecs/features/default_pre.prf: |
/usr/share/qt4/mkspecs/features/release.prf: |
/usr/share/qt4/mkspecs/features/default_post.prf: |
/usr/share/qt4/mkspecs/features/warn_on.prf: |
/usr/share/qt4/mkspecs/features/qt.prf: |
/usr/share/qt4/mkspecs/features/unix/thread.prf: |
/usr/share/qt4/mkspecs/features/moc.prf: |
/usr/share/qt4/mkspecs/features/resources.prf: |
/usr/share/qt4/mkspecs/features/uic.prf: |
/usr/share/qt4/mkspecs/features/yacc.prf: |
/usr/share/qt4/mkspecs/features/lex.prf: |
/usr/share/qt4/mkspecs/features/include_source_dir.prf: |
/usr/lib/qt4/libQtGui.prl: |
/usr/lib/qt4/libQtCore.prl: |
qmake: FORCE |
@$(QMAKE) -o Makefile qscope.pro |
dist: |
@$(CHK_DIR_EXISTS) .tmp/qscope1.0.0 || $(MKDIR) .tmp/qscope1.0.0 |
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/qscope1.0.0/ && $(COPY_FILE) --parents scope.h .tmp/qscope1.0.0/ && $(COPY_FILE) --parents main.cpp scope.cpp .tmp/qscope1.0.0/ && (cd `dirname .tmp/qscope1.0.0` && $(TAR) qscope1.0.0.tar qscope1.0.0 && $(COMPRESS) qscope1.0.0.tar) && $(MOVE) `dirname .tmp/qscope1.0.0`/qscope1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/qscope1.0.0 |
clean:compiler_clean |
-$(DEL_FILE) $(OBJECTS) |
-$(DEL_FILE) *~ core *.core |
####### Sub-libraries |
distclean: clean |
-$(DEL_FILE) $(TARGET) |
-$(DEL_FILE) Makefile |
check: first |
mocclean: compiler_moc_header_clean compiler_moc_source_clean |
mocables: compiler_moc_header_make_all compiler_moc_source_make_all |
compiler_moc_header_make_all: moc_scope.cpp |
compiler_moc_header_clean: |
-$(DEL_FILE) moc_scope.cpp |
moc_scope.cpp: scope.h |
/usr/bin/moc $(DEFINES) $(INCPATH) scope.h -o moc_scope.cpp |
compiler_rcc_make_all: |
compiler_rcc_clean: |
compiler_image_collection_make_all: qmake_image_collection.cpp |
compiler_image_collection_clean: |
-$(DEL_FILE) qmake_image_collection.cpp |
compiler_moc_source_make_all: |
compiler_moc_source_clean: |
compiler_uic_make_all: |
compiler_uic_clean: |
compiler_yacc_decl_make_all: |
compiler_yacc_decl_clean: |
compiler_yacc_impl_make_all: |
compiler_yacc_impl_clean: |
compiler_lex_make_all: |
compiler_lex_clean: |
compiler_clean: compiler_moc_header_clean |
####### Compile |
main.o: main.cpp scope.h |
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp |
scope.o: scope.cpp scope.h |
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o scope.o scope.cpp |
moc_scope.o: moc_scope.cpp |
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_scope.o moc_scope.cpp |
####### Install |
install: FORCE |
uninstall: FORCE |
FORCE: |
/Designs/Oscilloscope/SW/PC_side/qscope/main.cpp |
---|
0,0 → 1,36 |
#include <QApplication> |
#include <QPushButton> |
#include <QVBoxLayout> |
#include "scope.h" |
class Window : public QWidget |
{ |
public: |
Window(QWidget *parent = 0); |
}; |
Window::Window(QWidget *parent) |
: QWidget(parent) |
{ |
Scope *scope = new Scope; |
// QPushButton *ReadDataBut = new QPushButton(tr("Read data")); |
// connect(ReadDataBut, SIGNAL(clicked()), scope, SLOT(getData())); |
QVBoxLayout *layout = new QVBoxLayout; |
layout->addWidget(scope); |
// layout->addWidget(ReadDataBut); |
setLayout(layout); |
} |
int main(int argc, char *argv[]) |
{ |
QApplication app(argc, argv); |
Window window; |
window.setGeometry(800, 200, 560, 690); |
window.show(); |
return app.exec(); |
} |
/Designs/Oscilloscope/SW/PC_side/qscope/moc_scope.cpp |
---|
0,0 → 1,84 |
/**************************************************************************** |
** Meta object code from reading C++ file 'scope.h' |
** |
** Created: Sun Aug 14 02:02:16 2011 |
** by: The Qt Meta Object Compiler version 62 (Qt 4.7.2) |
** |
** WARNING! All changes made in this file will be lost! |
*****************************************************************************/ |
#include "scope.h" |
#if !defined(Q_MOC_OUTPUT_REVISION) |
#error "The header file 'scope.h' doesn't include <QObject>." |
#elif Q_MOC_OUTPUT_REVISION != 62 |
#error "This file was generated using the moc from 4.7.2. It" |
#error "cannot be used with the include files from this version of Qt." |
#error "(The moc has changed too much.)" |
#endif |
QT_BEGIN_MOC_NAMESPACE |
static const uint qt_meta_data_Scope[] = { |
// content: |
5, // revision |
0, // classname |
0, 0, // classinfo |
3, 14, // methods |
0, 0, // properties |
0, 0, // enums/sets |
0, 0, // constructors |
0, // flags |
0, // signalCount |
// slots: signature, parameters, type, tag, flags |
7, 6, 6, 6, 0x0a, |
21, 17, 6, 6, 0x0a, |
35, 17, 6, 6, 0x0a, |
0 // eod |
}; |
static const char qt_meta_stringdata_Scope[] = { |
"Scope\0\0getData()\0val\0setScale(int)\0" |
"setShift(int)\0" |
}; |
const QMetaObject Scope::staticMetaObject = { |
{ &QWidget::staticMetaObject, qt_meta_stringdata_Scope, |
qt_meta_data_Scope, 0 } |
}; |
#ifdef Q_NO_DATA_RELOCATION |
const QMetaObject &Scope::getStaticMetaObject() { return staticMetaObject; } |
#endif //Q_NO_DATA_RELOCATION |
const QMetaObject *Scope::metaObject() const |
{ |
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; |
} |
void *Scope::qt_metacast(const char *_clname) |
{ |
if (!_clname) return 0; |
if (!strcmp(_clname, qt_meta_stringdata_Scope)) |
return static_cast<void*>(const_cast< Scope*>(this)); |
return QWidget::qt_metacast(_clname); |
} |
int Scope::qt_metacall(QMetaObject::Call _c, int _id, void **_a) |
{ |
_id = QWidget::qt_metacall(_c, _id, _a); |
if (_id < 0) |
return _id; |
if (_c == QMetaObject::InvokeMetaMethod) { |
switch (_id) { |
case 0: getData(); break; |
case 1: setScale((*reinterpret_cast< int(*)>(_a[1]))); break; |
case 2: setShift((*reinterpret_cast< int(*)>(_a[1]))); break; |
default: ; |
} |
_id -= 3; |
} |
return _id; |
} |
QT_END_MOC_NAMESPACE |
/Designs/Oscilloscope/SW/PC_side/qscope/qscope |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:executable |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/Designs/Oscilloscope/SW/PC_side/qscope/qscope.pro |
---|
0,0 → 1,12 |
###################################################################### |
# Automatically generated by qmake (2.01a) Sun Aug 14 00:40:56 2011 |
###################################################################### |
TEMPLATE = app |
TARGET = |
DEPENDPATH += . |
INCLUDEPATH += . |
# Input |
HEADERS += scope.h |
SOURCES += main.cpp scope.cpp |
/Designs/Oscilloscope/SW/PC_side/qscope/scope.cpp |
---|
0,0 → 1,130 |
#include "scope.h" |
#include <QPainter> |
#include <QString> |
#include <iostream> |
#include <stdio.h> |
using namespace std; |
#define LEN 100 |
#define DEF_SCALE 1 |
#define DEF_SHIFT 0 |
#define LEFT 10 |
#define WIDTH 512 |
#define HEIGHT 600 |
#define PIXPT 2 |
Scope::Scope(QWidget *parent) { |
dataAquired=0; |
head=-1; |
data=new int[LEN*sizeof(int)]; ; |
int i; |
for(i=1;i<LEN;i++) |
data[i]=0; |
scale=DEF_SCALE; |
shift=DEF_SHIFT; |
scaleSlider = new QSlider(Qt::Horizontal); |
scaleSlider->setRange(1, 128); |
scaleSlider->setValue(DEF_SCALE); |
connect(scaleSlider, SIGNAL(valueChanged(int)), this, SLOT(setScale(int))); |
shiftSlider = new QSlider(Qt::Horizontal); |
shiftSlider->setRange(-60000, +60000); |
shiftSlider->setValue(DEF_SHIFT); |
connect(shiftSlider, SIGNAL(valueChanged(int)), this, SLOT(setShift(int))); |
updateTimer = new QTimer(this); |
updateTimer->start(150); |
connect(updateTimer, SIGNAL(timeout()), this, SLOT(getData())); |
scaleSlider->setGeometry(QRect(50,250,400,10)); |
scaleSlider->show(); |
shiftSlider->setGeometry(QRect(50,300,800,10)); |
shiftSlider->show(); |
// getData(); |
} |
Scope::~Scope() { |
delete [] data; |
} |
void Scope::paintEvent(QPaintEvent* event) { |
QPainter painter(this); |
if (head>-1) |
painter.drawText(10,20,QString::number(data[head])); |
if (dataAquired) { |
painter.drawLine(LEFT-1,45,LEFT-1,HEIGHT); |
painter.drawLine(LEFT+WIDTH,45,LEFT+WIDTH,HEIGHT); |
painter.drawLine(LEFT-1,45,LEFT+WIDTH,45); |
painter.drawLine(LEFT-1,HEIGHT,LEFT+WIDTH,HEIGHT); |
// painter.drawLine(LEFT-1,HEIGHT/2,LEFT+WIDTH,HEIGHT/2); |
int i; |
/* for(i=head+1;i<LEN-1;i++) |
painter.drawLine(PIXPT*(i-head)+LEFT,HEIGHT-data[i],PIXPT*(i-head+1)+LEFT,HEIGHT-data[i+1]); |
painter.drawLine(PIXPT*(LEN-head-1)+LEFT,HEIGHT-data[LEN-1],PIXPT*(LEN-head+1)+LEFT,HEIGHT-data[0]); |
for(i=0;i<head;i++) |
painter.drawLine(PIXPT*(i+LEN-head)+LEFT,HEIGHT-data[i],PIXPT*(i+LEN-head+1)+10,HEIGHT-data[i+1]);*/ |
for(i=0;i<LEN;i++) { |
data[i] = (data[i] + shift)/scale; |
// data[i] = data[i] + HEIGHT/2; |
} |
for(i=0;i<LEN-1;i++) { |
painter.drawLine(PIXPT*i+LEFT,HEIGHT-data[i],PIXPT*(i+1)+10,HEIGHT-data[i+1]); |
} |
} |
} |
void Scope::getData() { |
char c='m'; |
uint8_t buffer[2*LEN]; |
FILE *serial=fopen("/dev/ttyUSB0","r+"); |
fwrite(&c,sizeof(char),1,serial); // poprosime o data |
fread(buffer,sizeof(uint8_t),2*LEN,serial); // a berem je |
int i; |
for(i=0;i<LEN;i++) { |
data[i]=buffer[2*i]*256+buffer[2*i+1]; |
cout << 1*data[i] <<endl; |
} |
dataAquired=1; |
// head=LEN-1; |
update(); |
// cout << "Screen updated."<<endl; |
} |
void Scope::setScale(int val) { |
scale=val; |
} |
void Scope::setShift(int val) { |
shift=val; |
} |
/Designs/Oscilloscope/SW/PC_side/qscope/scope.h |
---|
0,0 → 1,37 |
#ifndef SCOPE_H |
#define SCOPE_H |
#include <QWidget> |
#include <QTimer> |
#include <QSlider> |
#include <stdint.h> |
class Scope : public QWidget |
{ |
Q_OBJECT |
public: |
Scope(QWidget *parent = 0); |
~Scope(); |
public slots: |
void getData(); |
void setScale(int val); |
void setShift(int val); |
protected: |
void paintEvent(QPaintEvent *event); |
private: |
int * data; |
char dataAquired; |
int head; |
long shift, scale; |
QTimer *updateTimer; |
QSlider *shiftSlider; |
QSlider *scaleSlider; |
}; |
#endif |
/Designs/Oscilloscope/SW/PC_side/stty_setting |
---|
0,0 → 1,2 |
stty -F /dev/ttyUSB0 1000000 raw -hupcl |
/Designs/Oscilloscope/SW/firmware/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/ttyUSB1 -B 2 -U flash:w:$< |
clean: |
rm -rf *.o $(PRG).elf $(PRG).hex ./libs/*.o |
Property changes: |
Added: svn:executable |
/Designs/Oscilloscope/SW/firmware/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/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/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/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/main.c |
---|
0,0 → 1,79 |
// 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> |
#define LEN 100 |
uint8_t data[2*LEN]; |
void measure(void); |
void send(void); |
int main (void) { |
USART_Init(MYUBRR); |
DDRB = 0b00100100; //SCK, SS out |
PORTB = 0b00000000; // CONV low |
SPI_MasterInit(); |
sei(); |
while(1) {} |
return 0; |
} |
void measure(void) { |
uint8_t i; |
for(i=0;i<LEN;i++) { |
PORTB |= 0b00000100; |
_delay_us(4); |
PORTB &= 0b11111011; //one conversion |
data[2*i] = SPI_MasterTransmit(0x0); |
data[2*i+1] = SPI_MasterTransmit(0x0); |
} |
} |
void send(void) { |
uint8_t i; |
for(i=0;i<LEN;i++) { |
/* USART_Transmit_uint16(data[i]); //ASCII transfer |
USART_Transmit('\n');*/ |
USART_Transmit(data[2*i]); //Binary transfer |
USART_Transmit(data[2*i+1]); |
// USART_Transmit('\n'); |
} |
} |
ISR(USART_RXC_vect) { |
char data; |
data=UDR; //must be read to untrigger interupt |
if (data=='m') { |
measure(); |
send(); |
} |
} |
/Designs/Oscilloscope/SW/firmware/scope.elf |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
Property changes: |
Added: svn:executable |
Added: svn:mime-type |
+application/octet-stream |
\ No newline at end of property |
/Designs/Oscilloscope/SW/firmware/scope.hex |
---|
0,0 → 1,74 |
:1000000012C02CC02BC02AC029C028C027C026C0BF |
:1000100025C024C023C069C021C020C01FC01EC08D |
:100020001DC01CC01BC011241FBECFE5D4E0DEBF25 |
:10003000CDBF10E0A0E6B0E0E2E8F4E002C0059039 |
:100040000D92A036B107D9F711E0A0E6B0E001C0EB |
:100050001D92A832B107E1F76FD011C2D1CF0F9333 |
:100060001F93CF93DF93C0E6D0E008E211E08881D0 |
:1000700077D0898175D02296C017D107C1F7DF915B |
:10008000CF911F910F910895DF92EF92FF920F93FE |
:100090001F93CF93DF93C0E6D0E00F2EF8E2EF2E50 |
:1000A000F1E0FF2EF02D08E310E00F2EF5E1DF2E3A |
:1000B000F02DF8018081846080838D2D8A95F1F781 |
:1000C00080818B7F808380E075D1888380E072D1CE |
:1000D00089832296CE15DF0561F7DF91CF911F91BD |
:1000E0000F91FF90EF90DF9008951F920F920FB63F |
:1000F0000F9211242F933F934F935F936F937F93AE |
:100100008F939F93AF93BF93EF93FF938CB18D36F3 |
:1001100011F4BADFA4DFFF91EF91BF91AF919F91EE |
:100120008F917F916F915F914F913F912F910F90A0 |
:100130000FBE0F901F90189581E090E006D084E2EA |
:1001400087BB18BA34D17894FFCFE0E4F0E0908315 |
:1001500089B982E28BB988E98AB986E880830895F3 |
:10016000EBE2F0E0908195FFFDCF8CB90895CF933D |
:10017000DF93EC018881882329F0F2DF21968881C2 |
:100180008823D9F7DF91CF910895AF92BF92CF9294 |
:10019000DF92EF92FF920F931F93DF93CF93CDB730 |
:1001A000DEB72A970FB6F894DEBF0FBECDBF7B0136 |
:1001B0008C01611571058105910519F480E3D0DF8B |
:1001C00050C0992354F48DE2CBDF10950095F09444 |
:1001D000E094E11CF11C011D111D6E010894C11C6D |
:1001E000D11C0F2EFBE0AF2EBB24F02DAC0EBD1E9C |
:1001F000C801B7012AE030E040E050E003D1F60149 |
:1002000061936F01C801B7012AE030E040E050E09F |
:10021000F9D0E22EF32E042F152FCA14DB0441F778 |
:100220008A85882311F019E00DC019E09E012F5F27 |
:100230003F4F1150F901E10FF11D80818823C9F36F |
:10024000112361F07E010894E11CF11CF701E10F1C |
:10025000F11D8081805D84DF1150C1F78981805D4F |
:100260007FDF2A960FB6F894DEBF0FBECDBFCF91C9 |
:10027000DF911F910F91FF90EF90DF90CF90BF9093 |
:10028000AF900895EF92FF920F931F93DF93CF9358 |
:1002900000D000D00F92CDB7DEB79C01009719F4C3 |
:1002A00080E35EDF34C0FE0131968E010A5F1F4F8E |
:1002B000C9016AE070E092D08193C9016AE070E000 |
:1002C0008DD0262F372FE017F10791F78D818823E6 |
:1002D00011F014E00DC014E09E012F5F3F4F11504C |
:1002E000F901E10FF11D80818823C9F3112361F029 |
:1002F0007E010894E11CF11CF701E10FF11D8081E2 |
:10030000805D2EDF1150C1F78981805D29DF0F905C |
:100310000F900F900F900F90CF91DF911F910F9141 |
:10032000FF90EF9008950F931F93182F6AE04AD023 |
:10033000082F48D047D0892F805D12DF802F6AE0D8 |
:1003400041D0892F805D0CDF812F6AE03BD0892F5F |
:10035000805D06DF1F910F910895DF92EF92FF926B |
:100360000F931F93CF93DF93C0E0D0E010E8E82E07 |
:10037000FF24E7FCF09401E30F2EF0E3DF2EF02DD5 |
:10038000812F90E08E219F21009711F48D2D01C0C7 |
:10039000802FE6DE16952196C830D10589F7DF91CA |
:1003A000CF911F910F91FF90EF90DF9008958CE512 |
:1003B0008DB908958FB9EEE2F0E080818823ECF7E3 |
:1003C0008FB10895991B79E004C0991F961708F022 |
:1003D000961B881F7A95C9F780950895AA1BBB1BA9 |
:1003E00051E107C0AA1FBB1FA617B70710F0A61B35 |
:1003F000B70B881F991F5A95A9F780959095BC0156 |
:10040000CD01089597FB092E05260ED057FD04D087 |
:1004100014D00AD0001C38F45095409530952195A1 |
:100420003F4F4F4F5F4F0895F6F790958095709529 |
:1004300061957F4F8F4F9F4F0895A1E21A2EAA1BFF |
:10044000BB1BFD010DC0AA1FBB1FEE1FFF1FA21784 |
:10045000B307E407F50720F0A21BB30BE40BF50B81 |
:10046000661F771F881F991F1A9469F7609570950A |
:10047000809590959B01AC01BD01CF010895F89442 |
:02048000FFCFAC |
:00000001FF |