Телесистемы
 Разработка, производство и продажа радиоэлектронной аппаратуры
На главную   | Карта сайта | Пишите нам | В избранное
Требуется программист в Зеленограде
- обработка данных с датчиков; ColdFire; 40 тыс.
e-mail:jobsmp@pochta.ru

Телесистемы | Электроника | Конференция «Микроконтроллеры и их применение»

Э.. простой диалоговый режим. Работало эдак 1,5 года назад. Не мог тока найти терминалки, поодерживающей кирилицу. Плохо искали. В те далёкие времена был такой пакет AVRLib. Что-то мне в нём не нравилось, но работало. Там есть пример командного интерпретаора. Был.

Отправлено uni 22 ноября 2007 г. 06:42
В ответ на: вот вы все про футбол про футбол%) а как мне обработать команды от pc по u...{+} отправлено <font color=gray>maximus01</font> 22 ноября 2007 г. 04:18


//*****************************************************************************
// File Name : cmdlinetest.c
//
// Title : example usage of cmdline (command line) functions
// Revision : 1.0
// Notes :
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// Revision History:
// When Who Description of change
// ----------- ----------- -----------------------
// 21-Jul-2003 pstang Created the program
//*****************************************************************************


//----- Include Files ---------------------------------------------------------
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
#include <avr/signal.h> // include "signal" names (interrupt names)
#include <avr/interrupt.h> // include interrupt support

#include "global.h" // include our global settings
#include "avrlib/uart.h" // include uart function library
#include "avrlib/rprintf.h" // include printf function library
#include "avrlib/a2d.h" // include A/D converter function library
#include "avrlib/timer.h" // include timer function library (timing, PWM, etc)
#include "avrlib/vt100.h" // include vt100 terminal support
#include "avrlib/cmdline.h" // include cmdline function library

// global variables
u08 Run;

//инициализация коммуникационного порта 0
// программируемая скорость связи: 9600
// реально:
void uart0_init(void)
{

UCSR0B = 0x00; //запрет на период инициализации

UBRR0L = 0x27; //установить скорость связи
// UBRR = (fosc/(16*BAUD)) - 1, где fosc - тактовая частота
UBRR0H = 0;

UCSR0A = 0x00; // управляющий регистр А
// RXC TXC UDRE FE DOR PE U2X MPCM
//биты: 7 6 5 4 3 2 1 0
// 0 0 0 0 0 0 0 0
// | | | | | | | |
// | | | | | | | +------ многопроцессорный режим
// | | | | | | +----------- удвоение скорости передачи/приема
// | | | | | +---------------- признак ошибки контроля четности (чтение)
// | | | | +-------------------- переполнение буфера данных (чтение)
// | | | +------------------------- ошибка при приеме байта (чтение)
// | | +------------------------------ буфер данных пуст (чтение)
// | +----------------------------------- передача окончена
// +---------------------------------------- данные приняты
UCSR0B = 0xD8; // управляющий регистр B
// RXCIE TXCIE UDRIE RXEN TXEN UCS22 RXB8 TXB8
//биты: 7 6 5 4 3 2 1 0
// 1 1 0 1 1 0 0 0
// | | | | | | | |
// | | | | | | | +--
// | | | | | | +--------
// | | | | | +-------------- длина символа 8 бит
// | | | | +--------------------- разрешение передачи
// | | | +--------------------------- разрешение приема
// | | +--------------------------------- прерывание "рег. данных пуст"
// | +---------------------------------------- прерывание передачи
// +----------------------------------------------- прерывание приема
UCSR0C = 0x2E; // управляющий регистр C
// URSEL UMSEL UPM1 UPM0 USBS UCS21 USC20 UCPOL
//биты: 7 6 5 4 3 2 1 0
// 1 0 1 0 1 1 1 0
// | | | | | | | |
// | | | | | | | +-- полярность тактирования
// | | | | | +-----+--------- длина символа 8 бит
// | | | | +---------------------- 2 стоповых бита
// | | +------+--------------------------- тип четности: доп. до четн.
// | +---------------------------------------- вкл. асинхронный режим
// +----------------------------------------------- переключение между UCSRC и UBRRH

}

// Внешний сторожевой таймер
#define WDI_EXT PORTD ^= 0x01; // сброс внешнего сторожевого таймера

// functions
void goCmdline(void);
void exitFunction(void);
void helpFunction(void);
void dumpArgsStr(void);
void dumpArgsInt(void);
void dumpArgsHex(void);

//----- Begin Code ------------------------------------------------------------
int main(void)
{
// initialize our libraries
// initialize the UART (serial port)
DDRD = 0x8F; //
PORTD = 0x7F; //

DDRE = 0x00; //
PORTE = 0xFF; //

PORTD = 0xF8;
uartInit();
uartSetBaudRate(9600);
uart0_init();
sei();
// make all rprintf statements use uart for output
rprintfInit(uartSendByte);
// turn on and initialize A/D converter
// a2dInit();
// initialize the timer system
timerInit();
// initialize vt100 terminal

vt100Init();

// configure port B for led output and pushbutton input
// outb(DDRB, 0x0F);
// all LEDs on
// outb(PORTB, 0x00);
// wait for hardware to power up
// timerPause(100);
// all LEDs off
// outb(PORTB, 0x0F);


timerPause(100);

// start command line
goCmdline();

return 0;
}

void goCmdline(void)
{
u08 c;

// print welcome message
vt100ClearScreen();
vt100SetCursorPos(1,0);
rprintfProgStrM("\r\n+---------------------------------+\r\n");
rprintfProgStrM("| Project ******** *****. |\r\n");
rprintfProgStrM("| Author: Viacheslav N. Mezentsev |\r\n");
rprintfProgStrM("| Date: 17 March 2006 |\r\n");
rprintfProgStrM("+---------------------------------+\r\n");

// Автор: Мезенцев В. Н.
// Начато: Вт 21.02.2006 г.

// initialize cmdline system
cmdlineInit();

// direct cmdline output to uart (serial port)
cmdlineSetOutputFunc(uartSendByte);

// add commands to the command database
cmdlineAddCommand("exit", exitFunction);
cmdlineAddCommand("help", helpFunction);
cmdlineAddCommand("dumpargs1", dumpArgsStr);
cmdlineAddCommand("dumpargs2", dumpArgsInt);
cmdlineAddCommand("dumpargs3", dumpArgsHex);

// send a CR to cmdline input to stimulate a prompt
cmdlineInputFunc('\r');

// set state to run
Run = TRUE;

// main loop
while(Run)
{
// pass characters received on the uart (serial port)
// into the cmdline processor
while(uartReceiveByte(&c)) {
cmdlineInputFunc(c);
WDI_EXT
}

// run the cmdline execution functions
cmdlineMainLoop();
WDI_EXT
}

rprintfCRLF();
rprintf("Exited program!\r\n");
}

void exitFunction(void)
{
// to exit, we set Run to FALSE
Run = FALSE;
}

void helpFunction(void)
{
rprintfCRLF();

rprintf("Available commands are:\r\n");
rprintf("help - displays available commands\r\n");
rprintf("dumpargs1 - dumps command arguments as strings\r\n");
rprintf("dumpargs2 - dumps command arguments as decimal integers\r\n");
rprintf("dumpargs3 - dumps command arguments as hex integers\r\n");

rprintfCRLF();
}

void dumpArgsStr(void)
{
rprintfCRLF();
rprintf("Dump arguments as strings\r\n");

rprintfProgStrM("Arg0: "); rprintfStr(cmdlineGetArgStr(0)); rprintfCRLF();
rprintfProgStrM("Arg1: "); rprintfStr(cmdlineGetArgStr(1)); rprintfCRLF();
rprintfProgStrM("Arg2: "); rprintfStr(cmdlineGetArgStr(2)); rprintfCRLF();
rprintfProgStrM("Arg3: "); rprintfStr(cmdlineGetArgStr(3)); rprintfCRLF();
rprintfCRLF();
}

void dumpArgsInt(void)
{
rprintfCRLF();
rprintf("Dump arguments as integers\r\n");

// printf %d will work but only if your numbers are less than 16-bit values
//rprintf("Arg1 as int: %d\r\n", cmdlineGetArgInt(1));
//rprintf("Arg2 as int: %d\r\n", cmdlineGetArgInt(2));
//rprintf("Arg3 as int: %d\r\n", cmdlineGetArgInt(3));

// printfNum is good for longs too
rprintf("Arg1 as int: "); rprintfNum(10, 10, TRUE, ' ', cmdlineGetArgInt(1)); rprintfCRLF();
rprintf("Arg2 as int: "); rprintfNum(10, 10, TRUE, ' ', cmdlineGetArgInt(2)); rprintfCRLF();
rprintf("Arg3 as int: "); rprintfNum(10, 10, TRUE, ' ', cmdlineGetArgInt(3)); rprintfCRLF();
rprintfCRLF();
}

void dumpArgsHex(void)
{
rprintfCRLF();
rprintf("Dump arguments as hex integers\r\n");

rprintf("Arg1 as hex: "); rprintfNum(16, 8, FALSE, ' ', cmdlineGetArgHex(1)); rprintfCRLF();
rprintf("Arg2 as hex: "); rprintfNum(16, 8, FALSE, ' ', cmdlineGetArgHex(2)); rprintfCRLF();
rprintf("Arg3 as hex: "); rprintfNum(16, 8, FALSE, ' ', cmdlineGetArgHex(3)); rprintfCRLF();
rprintfCRLF();
}




Составить ответ | Вернуться на конференцию

Ответы


Отправка ответа
Имя*: 
Пароль: 
E-mail: 
Тема*:

Сообщение:

Ссылка на URL: 
URL изображения: 

если вы незарегистрированный на форуме пользователь, то
для успешного добавления сообщения заполните поле, как указано ниже:
введите число 567:

Перейти к списку ответов | Конференция | Раздел "Электроника" | Главная страница | Карта сайта

Rambler's Top100 Рейтинг@Mail.ru
 
Web telesys.ru