Статус:
Offline
Реєстрація: 15.11.2007
Повідом.: 59
Реєстрація: 15.11.2007
Повідом.: 59
- 🟢 19:53 Відбій тривоги в м. Харків та Харківська територіальна громада.Слідкуйте за подальшими повідомленнями.#м_Харків_та_Харківська_територіальна_громада
- #21
С ДМА очень даже хороший вариант, но до него я пока еще не дорос... пока только осваивается...
вот что навоял.
//================================================
#ifndef COMMUNICATION_H
#define COMMUNICATION_H
#pragma import(__use_no_semihosting_swi)
extern unsigned char Device_Num; //Íîìåð USART.
#define PRINTF0(...) {Device_Num = 0; printf(__VA_ARGS__);}
#define PRINTF1(...) {Device_Num = 1; printf(__VA_ARGS__);}
#define PRINTF2(...) {Device_Num = 2; printf(__VA_ARGS__);}
#define PUTCHAR0(c) {Device_Num = 0; putchar(c);}
#define PUTCHAR1(c) {Device_Num = 1; putchar(c);}
#define PUTCHAR2(c) {Device_Num = 2; putchar(c);}
#define SCANF0(...) {Device_Num = 0; scanf(__VA_ARGS__);}
#define SCANF1(...) {Device_Num = 1; scanf(__VA_ARGS__);}
#define SCANF2(...) {Device_Num = 2; scanf(__VA_ARGS__);}
//#define GETCHAR0()
//#define GETCHAR1(void) {Device_Num = 1; (getchar());}
//#define GETCHAR2(void) {Device_Num = 2; (getchar());}
#endif
//===================================================
#include "communication.h"
#include <usart\usart.h>
#include <dbgu\dbgu.h>
#include <stdio.h>
unsigned char Device_Num;
struct __FILE { int handle; };
FILE __stdout;
FILE __stdin;
//================proto==================
int SendChar(unsigned char c);
int GetChar(void);
//=======================================
int fputc(int ch, FILE *f)
{
return (SendChar(ch));
}
int fgetc(FILE *f)
{
return (GetChar());
}
int ferror(FILE *f)
{
return EOF;
}
void _ttywrch(int ch)
{
SendChar(ch);
}
void _sys_exit(int return_code)
{
while (1);
}
int GetChar(void)
{
switch (Device_Num)
{
case 0:
{
return USART_GetChar(AT91C_BASE_US0);
}
case 1:
{
return USART_GetChar(AT91C_BASE_US1);
}
case 2:
{
return DBGU_GetChar();
}
}
return -1;
}
int SendChar(unsigned char c)
{
switch (Device_Num)
{
case 0:
{
USART_PutChar(AT91C_BASE_US0,c);
return 0;
}
case 1:
{
USART_PutChar(AT91C_BASE_US1,c);
return 0;
}
case 2:
{
DBGU_PutChar(c);
return 0;
}
}
return -1;
}
В принципе все работает принтф, сканф и путчар... кроме гетчар...)
вот что навоял.
//================================================
#ifndef COMMUNICATION_H
#define COMMUNICATION_H
#pragma import(__use_no_semihosting_swi)
extern unsigned char Device_Num; //Íîìåð USART.
#define PRINTF0(...) {Device_Num = 0; printf(__VA_ARGS__);}
#define PRINTF1(...) {Device_Num = 1; printf(__VA_ARGS__);}
#define PRINTF2(...) {Device_Num = 2; printf(__VA_ARGS__);}
#define PUTCHAR0(c) {Device_Num = 0; putchar(c);}
#define PUTCHAR1(c) {Device_Num = 1; putchar(c);}
#define PUTCHAR2(c) {Device_Num = 2; putchar(c);}
#define SCANF0(...) {Device_Num = 0; scanf(__VA_ARGS__);}
#define SCANF1(...) {Device_Num = 1; scanf(__VA_ARGS__);}
#define SCANF2(...) {Device_Num = 2; scanf(__VA_ARGS__);}
//#define GETCHAR0()
//#define GETCHAR1(void) {Device_Num = 1; (getchar());}
//#define GETCHAR2(void) {Device_Num = 2; (getchar());}
#endif
//===================================================
#include "communication.h"
#include <usart\usart.h>
#include <dbgu\dbgu.h>
#include <stdio.h>
unsigned char Device_Num;
struct __FILE { int handle; };
FILE __stdout;
FILE __stdin;
//================proto==================
int SendChar(unsigned char c);
int GetChar(void);
//=======================================
int fputc(int ch, FILE *f)
{
return (SendChar(ch));
}
int fgetc(FILE *f)
{
return (GetChar());
}
int ferror(FILE *f)
{
return EOF;
}
void _ttywrch(int ch)
{
SendChar(ch);
}
void _sys_exit(int return_code)
{
while (1);
}
int GetChar(void)
{
switch (Device_Num)
{
case 0:
{
return USART_GetChar(AT91C_BASE_US0);
}
case 1:
{
return USART_GetChar(AT91C_BASE_US1);
}
case 2:
{
return DBGU_GetChar();
}
}
return -1;
}
int SendChar(unsigned char c)
{
switch (Device_Num)
{
case 0:
{
USART_PutChar(AT91C_BASE_US0,c);
return 0;
}
case 1:
{
USART_PutChar(AT91C_BASE_US1,c);
return 0;
}
case 2:
{
DBGU_PutChar(c);
return 0;
}
}
return -1;
}
В принципе все работает принтф, сканф и путчар... кроме гетчар...)