Soft_UART_Init в microC AVR ???
Чип ATINY2313.
В хелпе для программы microC AVR есть пример работы программного UART порта. Примет рабочий, а вот из мануала к этой же программе есть другой вид инициализации. Так вот он, отказывается работать и указывает именно на строку настройки UART порта.
error = Soft_UART_Init(9600, 0); // Initialize Soft UART at9600 bps
Кто знает причину? Программы тестировались 2.10 и 3.20Beta версии - нет разницы.
Рабочая версия :
//=======================================
char i, error, byte_read; // Auxiliary variables
void main(){
DDRB = 0xFF; // Set PORTB as output (error signalization)
PORTB = 0; // No error
error = Soft_UART_Init(&PORTD,0,1,9600,0); // Initialize Soft UART at 9600 bps
if (error › 0) {
PORTB = error; // Signalize Init error
while(1) ; // Stop program
}
Delay_ms(100);
for (i = 'z'; i ›= 'A'; i--) { // Send bytes from 'z' downto 'A'
Soft_UART_Write(i);
Delay_ms(100);
}
while(1) { // Endless loop
byte_read = Soft_UART_Read(&error); // Read byte, then test error flag
if (error) // If error was detected
PORTB = error; // signal it on PORTB
else
Soft_UART_Write(byte_read); // If error was not detected, return byte read
}
}
//=========================================
Не рабочая версия:
Library Example
mikroC PRO for AVR
This example demonstrates simple data exchange via software UART. MCU is
connected to the PC, you can test the example from the mikroC PRO for AVR
USART Terminal Tool.
//==================================================
// Soft UART connections
sbit Soft_UART_Rx_Pin at PIND.B0;
sbit Soft_UART_Tx_Pin at PORTD.B1;
sbit Soft_UART_Rx_Pin_Direction at DDRD.B0;
sbit Soft_UART_Tx_Pin_Direction at DDRD.B1;
// End Soft UART connections
char i, error, byte_read; // Auxiliary variables
void main(){
DDRB = 0xFF; // Set PORTB as output(error signalization)
PORTB = 0; // No error
error = Soft_UART_Init(9600, 0); // Initialize Soft UART at9600 bps В этом месте ошибка
if (error › 0) {
PORTB = error; // Signalize Init error
while(1); // Stop program
}
Delay_ms(100);
for (i = 'z'; i ›= 'A'; i--) { // Send bytes from 'z'downto 'A'
Soft_UART_Write(i);
Delay_ms(100);
}
while(1) { // Endless loop
byte_read = Soft_UART_Read(&error); // Read byte, then testerror flag
if (error) // If error was detected
PORTB = error; // signal it on PORTB
else
Soft_UART_Write(byte_read); // If error was not detect-ed, return byte read
}
}
//===============================================
Последний раз редактировалось ut3mk; 13.08.2010 в 23:44.
|