На дисплее последовательно отображаются непонятные рандомные символы,вводя чтонить в гипертерминале отображается что-то определенное, но не совпадающее с тем что на кнопках... ввожу 1 - отображается 7 и тут же исчезает...
но это все работает только когда к контроллеру поделючен провод передачи
как только включаю провод на прием - контроллер замирает, на дисплее ничего не отображается... в гипертерминал ничего не отправляется... что это может быть?
Код
#include <mega48.h>
// Alphanumeric LCD Module functions
#include <alcd.h>
// Standard Input/Output functions
#include <stdio.h>
#include <delay.h>
#define LCD_CHARS_LINE 16
// Bit definitions from the USART control registers
#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7
#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)
// Specify that a new putchar function will be used instead of the one from stdio.h
#define _ALTERNATE_PUTCHAR_
// Specify the output types
#define USART0 0
#define LCD 2
// This variable will specify to which peripheral the output of putchar will be directed
unsigned char poutput;
void putchar(char c)
{
switch (poutput)
{
case USART0: // the output will be directed to USART0
while ((UCSR0A & DATA_REGISTER_EMPTY)==0);
UDR0=c;
break;
case LCD: // the output will be directed to the LCD
lcd_putchar©;
};
}
void main(void)
{
char k;
// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART0 Mode: Asynchronous
// USART Baud Rate: 9600
UCSR0A=0x00;
UCSR0B=0x18;
UCSR0C=0x06;
UBRR0H=0x00;
UBRR0L=0x33;
lcd_init(16);
while (1)
{
poutput=USART0;
//printf("This is a test of USART%u.\r",0);
k=getchar();
putchar(k);
//UDR0=3;
delay_ms(100);
poutput=LCD;
lcd_clear();
printf("-- %c --\n%u characters/line.",k,LCD_CHARS_LINE);
}
}
Сообщение отредактировал AnKing - Oct 13 2010, 21:55